-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cargo_build_script
uses inconsistent vars between compilation and runtime
#878
Comments
cargo_build_script
uses inconsistent build vars between compilation and runtimecargo_build_script
uses inconsistent vars between compilation and runtime
See also #661 :) As far as I know, and can tell, the runtime env vars should be a superset of the compile-time env vars, and the only expected difference in our implementation is rules_rust/cargo/cargo_build_script_runner/lib.rs Lines 184 to 186 in 73f228f
Is there a specific problem you ran into where this is causing problems? |
Yeah, the behavior I added in my draft came wasm-bindgen-shared::build.rs. So now, without patching, the new release of |
Can you expand the reproduction a bit to actually trying to read the files being problematic? I get that the literal values are different, but looking at wasm-bindgen's build.rs, I'd expect both values to work for their needs - |
Because the value of
Note both the sandbox directory |
We already try to address this some - the 423 vs 1016 we should already paper over with the exec-root redaction: rules_rust/cargo/cargo_build_script_runner/lib.rs Lines 184 to 186 in 73f228f
It feels like we could probably do something similar for the path from the exec-root to the runfiles path? So that we're doing the correct replacement in the rustc_env to make this work? |
I think that only impacts runtime arguments, not anything that was compiled into the binary... How would the script runner modify that value in a compiled binary? |
Oh, I see what you mean - yeah, the way we've made other libraries work with this is by giving them an overridable env var which is used at runtime which defaults to the compile-time value... |
Right but the rules should account for this because we can't expect everyone to conform to this restriction and I think it's unreasonable to force users to find workarounds for something that should just work. I suspect if the |
There's always going to be a limit to how much we can cover here - for instance, |
I think the rules should aim to be as compatible as possible. Particularly with Can you show me what the specific issue is with |
Effectively, an absolute path was being baked into the binary at build.rs time and that would be used at runtime (rather than at build-script-run time) |
#842 is another example of a cargo environment variable I don't think is going to work with Bazel so a compromise must be met. |
Sorry, can you break this one down a bit more if you have the context? The issue is that the |
The build.rs used to end up effectively running: println!("cargo:rustc-env=PROTOC={}", std::env::current_dir().unwrap().join("third-party").join("protobuf").join("protoc").display()); and the |
I see now, thanks for the follow-up! Do you know if it'd be possible to allow user defined variables in a BUILD file to supersede variables from a |
I think it would be a pretty hard DSL to express... I really think the answer for this kind of case is to make the build script more configurable, and reduce the assumptions it makes about its environment. |
I ended up opening rustwasm/wasm-bindgen#2657 to try and fix the compatibility issues with |
Bazel uses a sandbox to build crates, and the absolute path used can differ between building the build.rs and running it. Instead of compiling in the value of CARGO_MANIFEST_DIR, read it at runtime to get the correct directory. Refs: bazelbuild/rules_rust#878
Closing this out as I don't think there's a real solution for the issue. |
The way cargo_build_script works today is that a
rust_binary
target is created and used in another rule,_cargo_build_script
a private rule which actually executes thebuild.rs
script. I believe I've found an issue with this pattern where environment/build variables generated for the binary do not match what would be passed at runtime by_cargo_build_script
. This is because the cargo variables (likeCARGO_MANIFEST_DIR
) are set to paths within the sandbox currently used to build the rust_binary but are later set to an expected path within the new sandbox for theCargoBuildScriptRun
action (note, these paths may also now be the runfiles of therust_binary
).I've created a draft to demonstrate the issue:
I believe the fix is to merge the creation of the
build.rs
binary and it's execution into a single rule. Open to other ideas but I think the result should be the pull request linked above passes.The text was updated successfully, but these errors were encountered: