Support custom cargo build dirs on MacOS.
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
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?
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 https://github.com/rust-lang/cargo/issues/9661#issuecomment-1769481293 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.
I've updated the PR to use OUT_DIR.
Can you rebase this PR so that I can tell the CI to run? Thanks!
No problems! Done.