Skip to content

Added build.build-dir support #29

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ranger-ross
Copy link
Contributor

This PR adds build_dir to the BuildConfig

See: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#build-dir

closes #28

@taiki-e
Copy link
Owner

taiki-e commented Jun 7, 2025

Thanks! The implementation looks good.

However, given that this is an unstable feature and could lead to errors if the accepted syntax changes in the future, it might be better to put it behind a feature flag.

@ranger-ross
Copy link
Contributor Author

Sure, perhaps we add a generic unstable flag similar to cargo_metadata

@taiki-e
Copy link
Owner

taiki-e commented Jun 7, 2025

That sounds like a good idea.

I'm usually against using the Cargo feature for unstable stuff (rust-lang/api-guidelines#284 (comment)), but in this case I think the Cargo feature will be fine since the only users affected are those who explicitly use the unstable feature in their config files.

@ranger-ross ranger-ross force-pushed the build-dir-support branch 2 times, most recently from fd59ba4 to 4755153 Compare June 8, 2025 04:33
@ranger-ross
Copy link
Contributor Author

I added an unstable feature flag and support for it in tools/codegen.
let me know what you think :)

@taiki-e
Copy link
Owner

taiki-e commented Jun 8, 2025

Thanks. That looks good to me.

I looked at the documentation again and it looks like the environment variable is supported, so could you update src/env.rs to handle that?

https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#build-dir

Environment: CARGO_BUILD_BUILD_DIR

@ranger-ross
Copy link
Contributor Author

ranger-ross commented Jun 11, 2025

Added CARGO_BUILD_BUILD_DIR handling in the latest push.

Regarding the failing CI jobs, seems unrelated.

Preparing a careful sysroot (target: x86_64-unknown-linux-gnu)... thread 'main' panicked at src/main.rs:267:10:
failed to build sysroot; run `cargo careful setup` to see what went wrong: sysroot build failed

I pulled the latest nightly and ran cargo +nightly careful test --all --all-features on my machine and could not reproduce a failure.

src/easy.rs Outdated
@@ -564,6 +571,8 @@ impl BuildConfig {
.collect()
});
let target_dir = de.target_dir.map(|v| v.resolve_as_path(current_dir).into_owned());
#[cfg(feature = "unstable")]
let build_dir = de.build_dir.map(|v| v.resolve_as_path(current_dir).into_owned());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... given the presence of templates, I wonder if there is a problem with unconditional invocation of resolve_as_path here.

Cargo Reference says:

This option supports path templating.

Available template variables:

  • {workspace-root} resolves to root of the current workspace.
  • {cargo-cache-home} resolves to CARGO_HOME
  • {workspace-path-hash} resolves to a hash of the manifest path

Perhaps resolve_as_path should be skipped if the path starts with {workspace-root} or {cargo-cache-home}.

Also, it would be nice to mention in the documentation that these templates are not resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, agreed.
Added handling for that in the latest commit.

let build_dir = de.build_dir.map(|v| {
if v.val.starts_with("{workspace-root}")
|| v.val.starts_with("{cargo-cache-home}")
|| v.val.contains("{workspace-path-hash}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to care about {workspace-path-hash} since it doesn't resolve to an absolute path.

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

Successfully merging this pull request may close these issues.

Cargo build-dir support
2 participants