Skip to content

Build into a fixed target directory - #212

Open
giri256 wants to merge 1 commit into
abba23:mainfrom
giri256:fix-cargo-target-dir
Open

giri256 wants to merge 1 commit into
abba23:mainfrom
giri256:fix-cargo-target-dir

Conversation

@giri256

@giri256 giri256 commented Oct 9, 2026

Copy link
Copy Markdown

Fixes #211.

If someone has CARGO_TARGET_DIR (or build.target-dir in ~/.cargo/config.toml) set globally, make builds fine but puts the library somewhere else, and make install then fails with:

install: cannot stat 'target/release/libspotifyadblock.so': No such file or directory

This passes --target-dir to cargo, so the library always ends up where install looks for it. The directory is a TARGET_DIR variable that defaults to target, so anyone who wants their build output somewhere else can still do make TARGET_DIR=... && sudo make install TARGET_DIR=....

I went with this instead of asking cargo for the target directory (e.g. via cargo metadata) because sudo make install usually runs as root without the user's cargo setup, so it wouldn't see the same directory anyway.

While I was there, I also changed the dependency from src to $(wildcard src/*.rs). Depending on the directory only triggers a rebuild when files are added or removed, not when an existing file is edited in place.

Tested with CARGO_TARGET_DIR pointing elsewhere: make followed by make install DESTDIR=... now installs both files, and editing a source file triggers a rebuild.

Pass --target-dir to cargo so the library always ends up where the
install target expects it, even if CARGO_TARGET_DIR or build.target-dir
is set globally. The directory can still be changed with TARGET_DIR.

Also depend on the source files instead of the src directory, so editing
a file in place triggers a rebuild.

Fixes abba23#211
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.

Makefile assumes local target/ dir; fails when CARGO_TARGET_DIR is set globally

1 participant