I'm trying to include Foundry as an external dependency in my repository. In particular, I want its forge
cli command in github.com/foundry-rs/foundry/blob/master/crates/cli.
I've set up a WORKSPACE file that includes the CLI's crates and a bit more:
crates_repository(
name = "foundry",
annotations = {
"svm-rs": [crate.annotation(
gen_binaries = True,
)],
"foundry-cli": [crate.annotation(
gen_binaries = True,
)],
"forge": [crate.annotation(
gen_binaries = True,
)],
"serde": [crate.annotation(
gen_binaries = True,
)],
},
cargo_lockfile = "//:Cargo.lock",
lockfile = "//:Cargo.Bazel.lock",
packages = {
"svm-rs": crate.spec(
git = "https://github.com/alloy-rs/svm-rs",
rev = "b55c47b09437cf8dc01e1028aa0ab0a2300083d4",
),
"forge": crate.spec(
git = "https://github.com/foundry-rs/foundry",
rev = "d5db2c514fea76291715b019db65b60aa41eb421",
),
"foundry-cli": crate.spec(
git = "https://github.com/foundry-rs/foundry",
rev = "d5db2c514fea76291715b019db65b60aa41eb421",
),
"serde": crate.spec(
version = "1",
features = ["derive"],
),
#### Added the below while debugging
"camino": crate.spec(
version = "1.1.6",
features = ["serde1"],
),
"globset": crate.spec(
version = "0.4.9",
features = ["serde1"],
),
"serde_derive": crate.spec(
version = "1",
),
"serde_json": crate.spec(
version = "1",
),
"hex": crate.spec(
features = ["serde"],
),
### end of added
},
)
I then need to change a generated rule in .cache/bazel/_bazel_j/6c68e123d5be80edfb5e3a8f56f57687/external/foundry__svm-rs-0.3.0/BUILD.bazel
from
rust_binary(
name = "svm__bin",
...
to
rust_binary(
name = "svm",
...
then when trying to run bazel build @foundry//:foundry-cli__forge
I then get the following:
ERROR: .cache/bazel/_bazel_j/6c68e123d5be80edfb5e3a8f56f57687/external/foundry__camino-1.1.6/BUILD.bazel:22:13: Compiling Rust rlib camino v1.1.6 (6 files) failed: (Exit 1): process_wrapper failed: error executing command bazel-out/k8-opt-exec-2B5CBBC6/bin/external/rules_rust/util/process_wrapper/process_wrapper --env-file bazel-out/k8-fastbuild/bin/external/foundry__camino-1.1.6/camino_build_script.env --arg-file ... (remaining 35 arguments skipped)
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
error: proc-macro derive panicked
--> external/foundry__camino-1.1.6/src/lib.rs:108:39
|
108 | #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
| ^^^^^^^^^^^^^^^^
|
= help: message: file missing from serde_derive manifest directory during macro expansion: .cache/bazel/_bazel_j/6c68e123d5be80edfb5e3a8f56f57687/sandbox/linux-sandbox/7574/execroot/external/foundry__serde_derive-1.0.183/serde_derive-x86_64-unknown-linux-gnu
error: proc-macro derive panicked
--> external/foundry__camino-1.1.6/src/lib.rs:108:57
|
108 | #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
| ^^^^^^^^^^^^^^^^^^
|
= help: message: file missing from serde_derive manifest directory during macro expansion: .cache/bazel/_bazel_j/6c68e123d5be80edfb5e3a8f56f57687/sandbox/linux-sandbox/7574/execroot/external/foundry__serde_derive-1.0.183/serde_derive-x86_64-unknown-linux-gnu
error[E0599]: no function or associated item named `deserialize` found for struct `Utf8PathBuf` in the current scope
--> external/foundry__camino-1.1.6/src/serde_impls.rs:62:25
|
62 | Ok(Utf8PathBuf::deserialize(deserializer)?.into())
| ^^^^^^^^^^^ function or associated item not found in `Utf8PathBuf`
|
::: external/foundry__camino-1.1.6/src/lib.rs:111:1
|
111 | pub struct Utf8PathBuf(PathBuf);
| ---------------------- function or associated item `deserialize` not found for this struct
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following traits define an item `deserialize`, perhaps you need to implement one of them:
candidate #1: `Deserialize`
candidate #2: `DeserializeSeed`
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0599`.
It looks like I'm missing serde1
since Deserialize
and DeserializeSeed
are both part of serde1 according to https://serde.rs/derive.html, but I thought I'm already including the serde1
feature - what am I missing?
There's an open bug with serde_derive
and rules_rust
: https://github.com/bazelbuild/rules_rust/issues/2071#issuecomment-1656204269
Pinning my package version with the below fixed this
"serde": crate.spec(
features = ["derive"],
version = "=1.0.164",
),