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

Support custom cargo build dirs on MacOS. #5894

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

aldhsu
Copy link

@aldhsu aldhsu commented Aug 3, 2024

Loving wezterm! I was attempting to add new lua hooks and ran into this problem on MacOs.

Expected

Clean build succeeds on MacOS

Actual

Fails to build.

 Caused by:
      No such file or directory (os error 2)
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@wez
Copy link
Owner

wez commented Aug 3, 2024

Thanks, but this shouldn't be needed if you follow the https://wezfurlong.org/wezterm/install/source.html instructions.
What's different about your environment/setup that results in you needing this?

@aldhsu
Copy link
Author

aldhsu commented Aug 4, 2024

Ah I see the problem. I just blindly made the folder without looking at what it's doing.
I should have read the error more closely.

I use a custom CARGO_TARGET_DIR in ~/.cargo/.config.toml:

[build]
target-dir = "/Users/ahsu/.cargo/builds/"

This is so deps are shared.

Might just be my configuration but I tried cargo build -vv --target-dir=target which forces the target dir over other config and printing out the "CARGO_TARGET_DIR" env var in the build script. "CARGO_TARGET_DIR" seems to always be empty? This comment rust-lang/cargo#9661 (comment) seems to suggest that not passing "CARGO_TARGET_DIR" from Cargo to build scripts is intentional currently.

A user can set it themselves though eg. CARGO_TARGET_DIR=target cargo build -vv but this will not come from cargo.toml by default.

The script currently always falls back to the default "target" on any systems building with a custom Cargo target directory.

A general solution would be to walk back from "OUT_DIR" which is passed into the build script.
I'm not sure I know enough to suggest a good solution but if the above will suffice I can amend the PR.

- rust-lang/cargo#9661 (comment)
  CARGO_TARGET_DIR from cargo.toml is not available during build scripts at the moment
@aldhsu
Copy link
Author

aldhsu commented Aug 6, 2024

I've updated the PR to use OUT_DIR.

@aldhsu aldhsu changed the title Create dirs before writing file. Support custom cargo build dirs on MacOS. Aug 11, 2024
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.

2 participants