Skip to content
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

Rust bindings build script accesses CARGO_MANIFEST_DIR at compile time instead of run time #3353

Closed
redsun82 opened this issue May 8, 2024 · 0 comments · Fixed by #3352
Closed
Labels

Comments

@redsun82
Copy link
Contributor

redsun82 commented May 8, 2024

Problem

CARGO_MANIFEST_DIR is accessed in build.rs via the env! macro rather than env::var, which makes it access that variable at compile time instead of run time as it should.

This is for example causing problems when pulling in tree-sitter via rules_rust in bazel, where compilation and running happen in completely separate environments.

Steps to reproduce

Reported error:

ERROR: /home/redsun82/.cache/bazel/_bazel_redsun82/bc5487f033a0af65dff1ff0bd4000d75/external/rules_rust~~crate~crate__tree-sitter-0.22.6/BUILD.bazel:92:19: Running Cargo build script tree-sitter failed: (Exit 1): cargo_build_script_runner failed: error executing CargoBuildScriptRun command (from target @@rules_rust~~crate~crate__tree-sitter-0.22.6//:tree-sitter_bs) bazel-out/k8-opt-exec-ST-13d3ddad9198/bin/external/rules_rust~/cargo/cargo_build_script_runner/cargo_build_script_runner ... (remaining 11 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
Build script process failed with exit code 101
--stdout:
cargo:rerun-if-env-changed=CARGO_FEATURE_WASM

--stderr:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', external/rules_rust~~crate~crate__tree-sitter-0.22.6/binding_rust/build.rs:33:42

followed by a stack trace.

Expected behavior

Build works, which happens if patching tree-sitter with #3352 🙂

Tree-sitter version (tree-sitter --version)

tree-sitter 0.22.6

Operating system/version

Linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant