Skip to content

Commit

Permalink
Use taplo to auto-format TOML files
Browse files Browse the repository at this point in the history
Use https://github.com/tamasfe/taplo to auto-format TOML files. Add a config 
file to force reordering of dependencies in Cargo.toml files. Run taplo in CI 
to check formatting.
  • Loading branch information
akonradi-signal authored Mar 26, 2024
1 parent 08513b2 commit 9b34467
Show file tree
Hide file tree
Showing 23 changed files with 124 additions and 65 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,26 @@ jobs:
uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1
with:
path: local-tools
key: ${{ runner.os }}-local-tools-${{ matrix.version }}-${{ hashFiles('acknowledgments/cargo-about-version') }}
key: ${{ runner.os }}-local-tools-${{ matrix.version }}-${{ hashFiles('acknowledgments/cargo-about-version', '.taplo-cli-version') }}

- name: Build cargo-about if needed
run: cargo +stable install --version $(cat acknowledgments/cargo-about-version) --locked cargo-about --root local-tools
if: matrix.version == 'nightly'

- name: Build taplo-cli if needed
run: cargo +stable install --version $(cat .taplo-cli-version) --locked taplo-cli --root local-tools
if: matrix.version == 'nightly'

# This should be done before anything else
# because it also checks that the lockfile is up to date.
- name: Check for duplicate dependencies
run: ./bin/verify_duplicate_crates
if: matrix.version == 'nightly'

- name: Cargo.toml formatting check
run: PATH="$PATH:$PWD/local-tools/bin" taplo format -c .taplo.toml --check
if: matrix.version == 'nightly'

- name: Rustfmt check
run: cargo fmt --all -- --check
if: matrix.version == 'nightly'
Expand Down
1 change: 1 addition & 0 deletions .taplo-cli-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.9.0
13 changes: 13 additions & 0 deletions .taplo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
include = ["Cargo.toml", "rust/**/*.toml"]

[formatting]
reorder_keys = false
indent_string = ' '

[[rule]]
include = ["**/Cargo.toml"]
keys = ["dependencies"]

[rule.formatting]
reorder_keys = true
inline_table_expand = false
1 change: 1 addition & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ generate-bridge:
# Auto-format code in Java, Rust, Swift, and TypeScript
format-all:
cargo fmt
taplo fmt
(cd swift && swiftformat --swiftversion 5 .)
(cd node && yarn format)
(cd java && ./gradlew spotlessApply)
2 changes: 1 addition & 1 deletion rust/attest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ chacha20poly1305 = "0.10.1"
chrono = { version = "0.4", features = ["serde"] }
ciborium = "0.2"
displaydoc = "0.2"
hmac = "0.12"
hex = { version = "0.4", features = ["serde"] }
hex-literal = "0.4.1"
hmac = "0.12"
lazy_static = "1.4.0"
libc = "0.2"
log = "0.4"
Expand Down
5 changes: 2 additions & 3 deletions rust/attest/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ edition = "2021"
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"
attest = { path = "../" }

[dependencies.attest]
path = ".."
libfuzzer-sys = "0.4"

# Prevent this from interfering with workspaces
[workspace]
Expand Down
17 changes: 9 additions & 8 deletions rust/bridge/ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ signal-media = ["libsignal-bridge/signal-media"]
testing-fns = ["libsignal-bridge/testing-fns"]

[dependencies]
libsignal-protocol = { path = "../../protocol" }
libsignal-net = { path = "../../net" }
device-transfer = { path = "../../device-transfer" }
attest = { path = "../../attest" }
device-transfer = { path = "../../device-transfer" }
libsignal-bridge = { path = "../shared", features = ["ffi"] }
libsignal-net = { path = "../../net" }
libsignal-protocol = { path = "../../protocol" }
signal-crypto = { path = "../../crypto" }
zkgroup = { path = "../../zkgroup" }
usernames = { path = "../../usernames" }
signal-pin = { path = "../../pin" }
signal-media = { path = "../../media" }
libsignal-bridge = { path = "../shared", features = ["ffi"] }
signal-pin = { path = "../../pin" }
usernames = { path = "../../usernames" }
zkgroup = { path = "../../zkgroup" }

async-trait = "0.1.41"
futures-util = "0.3"
rand = "0.8"
log = { version = "0.4", features = ["release_max_level_info"] }
log-panics = { version = "2.1.0", features = ["with-backtrace"] }
rand = "0.8"

[target.aarch64-apple-ios.dependencies]
cpufeatures = "0.2.1" # Make sure iOS gets optimized crypto.
35 changes: 31 additions & 4 deletions rust/bridge/ffi/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,22 @@ usize_is_size_t = true
prefix_with_name = true

[export]
include = ["SignalErrorCode", "FfiDirection", "FfiCiphertextMessageType", "FfiContentHint", "RandomnessBytes"]
include = [
"SignalErrorCode",
"FfiDirection",
"FfiCiphertextMessageType",
"FfiContentHint",
"RandomnessBytes",
]
exclude = ["TAG_SIZE", "NONCE_SIZE"]
item_types = ["enums", "functions", "opaque", "structs", "typedefs", "constants"]
item_types = [
"enums",
"functions",
"opaque",
"structs",
"typedefs",
"constants",
]
# FIXME: this doesn't work well with constants in SCREAMING_SNAKE_CASE
prefix = "Signal"
renaming_overrides_prefixing = true
Expand Down Expand Up @@ -65,9 +78,23 @@ args = "horizontal"

[parse]
parse_deps = true
include = ["libsignal-core", "libsignal-protocol", "signal-crypto", "signal-pin", "zkgroup", "signal-media", "mediasan-common", "mp4san", "webpsan"]
include = [
"libsignal-core",
"libsignal-protocol",
"signal-crypto",
"signal-pin",
"zkgroup",
"signal-media",
"mediasan-common",
"mp4san",
"webpsan",
]
extra_bindings = ["libsignal-bridge", "zkgroup"]

[parse.expand]
crates = ["libsignal-ffi", "libsignal-bridge"]
features = ["libsignal-bridge/ffi", "libsignal-bridge/signal-media", "libsignal-bridge/testing-fns"]
features = [
"libsignal-bridge/ffi",
"libsignal-bridge/signal-media",
"libsignal-bridge/testing-fns",
]
5 changes: 3 additions & 2 deletions rust/bridge/jni/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ name = "signal_jni"
crate-type = ["cdylib"]

[dependencies]
libsignal-bridge = { path = "../shared", features = ["jni", "signal-media"] }
libsignal-protocol = { path = "../../protocol" }
signal-crypto = { path = "../../crypto" }
libsignal-bridge = { path = "../shared", features = ["jni", "signal-media"] }

async-trait = "0.1.41"
cfg-if = "1.0.0"
jni = "0.21.0"
rand = "0.8"
log = { version = "0.4", features = ["release_max_level_info"] }
log-panics = { version = "2.1.0", features = ["with-backtrace"] }
rand = "0.8"

[features]
testing-fns = ["libsignal-bridge/testing-fns"]
Expand Down
6 changes: 5 additions & 1 deletion rust/bridge/jni/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ extra_bindings = ["libsignal-bridge"]

[parse.expand]
crates = ["libsignal-jni", "libsignal-bridge"]
features = ["libsignal-bridge/jni", "libsignal-bridge/signal-media", "libsignal-bridge/testing-fns"]
features = [
"libsignal-bridge/jni",
"libsignal-bridge/signal-media",
"libsignal-bridge/testing-fns",
]
15 changes: 8 additions & 7 deletions rust/bridge/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@ name = "signal_node"
crate-type = ["cdylib"]

[dependencies]
libsignal-protocol = { path = "../../protocol" }
libsignal-bridge = { path = "../shared", features = ["node", "signal-media"] }
libsignal-protocol = { path = "../../protocol" }
signal-neon-futures = { path = "futures" }
neon = { version = "1.0.0", default-features = false, features = ["napi-6"] }
rand = "0.8"
log = { version = "0.4", features = ["release_max_level_info"] }
log-panics = { version = "2.0.0", features = ["with-backtrace"] }

async-trait = "0.1.41"
futures = { version = "0.3", default-features = false, features = ["executor"] }
log = { version = "0.4", features = ["release_max_level_info"] }
log-panics = { version = "2.0.0", features = ["with-backtrace"] }
minidump = { version = "0.20.0", default-features = false }
minidump-unwind = { version = "0.20.0", default-features = false }
minidump-processor = { version = "0.20.0", default-features = false }
minidump-unwind = { version = "0.20.0", default-features = false }
neon = { version = "1.0.0", default-features = false, features = ["napi-6"] }
rand = "0.8"

[build-dependencies]
# cmake 0.1.49 breaks no-toolchain Windows cross-compilation using Visual Studio
# https://github.com/rust-lang/cmake-rs/pull/158#issuecomment-1544695163
cmake = ">= 0.1, < 0.1.49"

[features]
testing-fns = ["libsignal-bridge/testing-fns"]
testing-fns = ["libsignal-bridge/testing-fns"]
2 changes: 1 addition & 1 deletion rust/bridge/node/futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ path = "benches/node.rs"
harness = false

[dependencies]
neon = { version = "1.0.0", default-features = false, features = ["napi-4"] }
futures-util = "0.3.7"
neon = { version = "1.0.0", default-features = false, features = ["napi-4"] }

[dev-dependencies]
signal-neon-futures-tests = { path = "tests-node-module" }
Expand Down
3 changes: 2 additions & 1 deletion rust/bridge/node/futures/tests-node-module/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ crate-type = ["cdylib"]

[dependencies]
signal-neon-futures = { path = ".." }
neon = { version = "1.0.0", default-features = false, features = ["napi-1"] }

futures-util = "0.3.7"
neon = { version = "1.0.0", default-features = false, features = ["napi-1"] }

[features]
# Enable default-panic-hook to get backtraces of panics.
Expand Down
19 changes: 10 additions & 9 deletions rust/bridge/shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ edition = "2021"
license = "AGPL-3.0-only"

[dependencies]
libsignal-protocol = { path = "../../protocol" }
attest = { path = "../../attest" }
device-transfer = { path = "../../device-transfer" }
libsignal-bridge-macros = { path = "macros" }
libsignal-message-backup = { path = "../../message-backup" }
libsignal-net = { path = "../../net" }
libsignal-protocol = { path = "../../protocol" }
libsignal-svr3 = { path = "../../svr3" }
signal-crypto = { path = "../../crypto" }
device-transfer = { path = "../../device-transfer" }
attest = { path = "../../attest" }
zkgroup = { path = "../../zkgroup" }
usernames = { path = "../../usernames" }
signal-pin = { path = "../../pin" }
libsignal-message-backup = { path = "../../message-backup" }
signal-media = { path = "../../media", optional = true }
libsignal-bridge-macros = { path = "macros" }
signal-pin = { path = "../../pin" }
usernames = { path = "../../usernames" }
zkgroup = { path = "../../zkgroup" }

aes-gcm-siv = "0.11.1"
async-trait = "0.1.41"
base64 = "0.21"
Expand Down Expand Up @@ -59,8 +60,8 @@ subtle = { version = "2.5", features = ["core_hint_black_box"] }

bytemuck = { version = "1.13.0", optional = true }
jni = { version = "0.21", package = "jni", optional = true }
neon = { version = "1.0.0", optional = true, default-features = false, features = ["napi-6"] }
linkme = { version = "0.3.9", optional = true }
neon = { version = "1.0.0", optional = true, default-features = false, features = ["napi-6"] }
signal-neon-futures = { path = "../node/futures", optional = true }
strum = { version = "0.26", features = ["derive"] }

Expand Down
4 changes: 2 additions & 2 deletions rust/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ license = "AGPL-3.0-only"
aes = { version = "0.8.3", features = ["zeroize"] }
cbc = { version = "0.1.2", features = ["std", "zeroize"] }
ctr = { version = "0.9.2", features = ["zeroize"] }
subtle = "2.3"
displaydoc = "0.2"
ghash = { version = "0.5.0", features = ["zeroize"] }
hmac = { version = "0.12", features = ["reset"] }
sha1 = "0.10"
sha2 = "0.10"
subtle = "2.3"
thiserror = "1.0.38"
displaydoc = "0.2"

[dev-dependencies]
criterion = "0.5"
Expand Down
4 changes: 2 additions & 2 deletions rust/message-backup/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ hkdf = "0.12"
hmac = "0.12"
log = "0.4"
mediasan-common = "0.5.0"
num_enum = "0.6.1"
protobuf = "3.3.0"
protobuf-json-mapping = { version = "3.3.0", optional = true }
serde_json = { version = "1.0", optional = true }
sha2 = "0.10"
strum = { version = "0.26", features = ["derive"] }
subtle = "2.5.0"
thiserror = "1.0.50"
uuid = "1.1.2"
num_enum = "0.6.1"
strum = { version = "0.26", features = ["derive"] }

[dev-dependencies]
libsignal-message-backup = { path = "./", features = ["json"] }
Expand Down
5 changes: 3 additions & 2 deletions rust/net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ authors = ["Signal Messenger LLC"]
license = "AGPL-3.0-only"

[dependencies]
libsignal-svr3 = { path = "../svr3"}
attest = { path = "../attest" }
libsignal-core = { path = "../core" }
libsignal-svr3 = { path = "../svr3" }

async-trait = "0.1.41"
base64 = "0.21"
bincode = "1.0"
Expand All @@ -26,7 +28,6 @@ http-body-util = "0.1.1"
hyper = { version = "1.2.0", features = ["http1", "http2", "client"] }
itertools = "0.12.0"
lazy_static = "1.4.0"
libsignal-core = { path = "../core" }
log = "0.4.19"
pin-project-lite = "0.2.4"
prost = "0.12.1"
Expand Down
4 changes: 2 additions & 2 deletions rust/poksho/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ license = "AGPL-3.0-only"

[dependencies]
curve25519-dalek = "4.0"
hmac = { version = "0.12", features = ["reset"] }
sha2 = "0.10"
subtle = "2.5"
hmac = { version = "0.12", features = ["reset"] }

[dev-dependencies]
hex = "0.4"
Expand All @@ -25,4 +25,4 @@ rand = "0.8"

[[bench]]
name = "sho"
harness = false
harness = false
17 changes: 9 additions & 8 deletions rust/protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,33 @@ license = "AGPL-3.0-only"
[dependencies]
libsignal-core = { path = "../core" }
signal-crypto = { path = "../crypto" }

aes = { version = "0.8.3", features = ["zeroize"] }
aes-gcm-siv = "0.11.1"
arrayref = "0.3.6"
async-trait = "0.1.41"
ctr = { version = "0.9.2", features = ["zeroize"] }
curve25519-dalek = { version = "4.0.0", features = ["digest"] }
derive-where = "1.2.5"
displaydoc = "0.2"
hex = "0.4"
hkdf = "0.12"
hmac = "0.12"
indexmap = "2.1.0"
itertools = "0.12.0"
log = "0.4"
num_enum = "0.6.1"
pqcrypto-kyber = { version = "0.7.6", default-features = false, features = ["std"] }
pqcrypto-traits = "0.3.4"
prost = "0.12"
rand = "0.8"
rayon = "1.8.0"
sha2 = "0.10"
static_assertions = "1.1"
subtle = "2.3"
x25519-dalek = { version = "2.0.0", features = ["static_secrets"] }
hex = "0.4"
log = "0.4"
num_enum = "0.6.1"
uuid = "1.1.2"
displaydoc = "0.2"
thiserror = "1.0.30"
pqcrypto-kyber = { version = "0.7.6", default-features = false, features = ["std"] }
pqcrypto-traits = "0.3.4"
uuid = "1.1.2"
x25519-dalek = { version = "2.0.0", features = ["static_secrets"] }

# WARNING: pqcrypto-kyber 0.8 and 0.7 don't actually coexist, they both depend on the same C symbols.
# We keep this here for if/when that gets cleared up.
Expand Down
Loading

0 comments on commit 9b34467

Please sign in to comment.