-
Notifications
You must be signed in to change notification settings - Fork 534
Open
Labels
Description
I think the cause is:
- build.rs embeds a cargo envvar:
PathBuf::from(env!("CARGO_MANIFEST_DIR")). - when the buildscript actually runs, the embedded envvar points to the previous sandbox (the one of the compilation), that is not present any more.
(see build.rs in this commit)
I verified this by adding some eprintln!s into build.rs:
CARGO_MANIFEST_DIR: .../sandbox/linux-sandbox/14/execroot/_main/external/rules_rust~~crate~crates__pq-sys-0.7.0
source_path: ".../sandbox/linux-sandbox/14/execroot/_main/external/rules_rust~~crate~crates__pq-sys-0.7.0/src/bindings_linux.rs"
out_path: ".../sandbox/linux-sandbox/15/execroot/_main/bazel-out/k8-fastbuild/bin/external/rules_rust~~crate~crates__pq-sys-0.7.0/_bs.out_dir/bindings.rs"
There's one thing I do not understand. aquery of the builds script compilation shows:
$ bazel aquery @@rules_rust~~crate~crates__pq-sys-0.7.0//:_bs_
action 'Compiling Rust bin _bs_ (8 files) [for tool]'
Mnemonic: Rustc
Target: @@rules_rust~~crate~crates__pq-sys-0.7.0//:_bs_
[...]
CARGO_MANIFEST_DIR=${pwd}/external/rules_rust~~crate~crates__pq-sys-0.7.0
What replaces ${pwd} with the actual absolute path? There's such a transformation in cargo/cargo_build_script_runner/bin.rs , but that is for the envvars passed to the buildscript runtime.
This issue is reproducible locally with these files:
# MODULE.bazel
bazel_dep(name = "rules_rust", version = "0.58.0")
crate = use_extension("@rules_rust//crate_universe:extension.bzl", "crate")
crate.spec(package = "pq-sys", version = "=0.7.0", features = [], default_features = False)
crate.from_specs(
isolated = False,
supported_platform_triples = [
"x86_64-unknown-linux-gnu",
],
)
use_repo(crate, "crates")
BUILD.bazel is empty.
.bazelversion is "8.1.1".
Then:
bazel build @crates//:pq-sys
Produces:
thread 'main' panicked at external/rules_rust++crate+crates__pq-sys-0.7.0/build.rs:118:46:
Couldn't write bindings: Os { code: 2, kind: NotFound, message: "No such file or directory" }
Same with --remote_download_all. No remote exec or any other special config is needed.
aran