git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Makefile: pin cargo --target-dir to ./target

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 19, 2026, 06:45 UTC
Message-ID
<atW8otvbLGDtDBG9@pks.im>
In-Reply-To
<20261018205305.2634339-1-andy.koppe@gmail.com>
On Sun, Oct 18, 2026 at 09:53:05PM +0100, Andy Koppe wrote:
Show 12 quoted lines
> The Makefile assumes that cargo places build artifacts under ./target.
> That assumption breaks if the user has a custom target dir setting, e.g.
> in their ~/.cargo/config.toml file or in the CARGO_TARGET_DIR env var.
> This results in a link error due to failing to find the gitcore library
> built with cargo.
> 
> To fix this, pass '--target-dir target' to the cargo commands that build
> gitcore. Add it directly to the recipes rather than to CARGO_ARGS, so
> that it isn't lost if CARGO_ARGS is overridden.
> 
> Leave the contrib/libgit-{sys,rs} targets alone, as nothing depends on
> the location of their build output.

Right. I sometimes wonder whether we maybe want to start merging this into the main Rust library. But that's certainly a topic for another day.

> The Meson build of gitcore already passes --target-dir explicitly.
Indeed it does.
Show 22 quoted lines
> diff --git a/Makefile b/Makefile
> index c649c93c51..aea99a3639 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -3039,7 +3039,7 @@ $(LIB_FILE): $(LIB_OBJS)
>  ifndef NO_RUST
>  ifeq ($(RUST_TARGETS),)
>  $(RUST_LIB): Cargo.toml $(RUST_SOURCES) $(LIB_FILE)
> -	$(QUIET_CARGO)cargo build $(CARGO_ARGS)
> +	$(QUIET_CARGO)cargo build $(CARGO_ARGS) --target-dir target
>  else
>  ifneq ($(words $(RUST_TARGETS)),1)
>  ifneq ($(uname_S),Darwin)
> @@ -3049,7 +3049,7 @@ endif
>  
>  RUST_MEMBER_LIBS = $(foreach target,$(RUST_TARGETS),target/$(target)/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME))
>  $(RUST_MEMBER_LIBS): target/%/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME): Cargo.toml $(RUST_SOURCES) $(LIB_FILE)
> -	$(QUIET_CARGO)cargo build $(CARGO_ARGS) --target $*
> +	$(QUIET_CARGO)cargo build $(CARGO_ARGS) --target-dir target --target $*
>  
>  $(RUST_LIB): $(RUST_MEMBER_LIBS)
>  	$(call mkdir_p_parent_template)

Makes sense. I would have preferred to use the "--target-dir=target" form, but that really only is a nit that does not warrant a reroll in my opinion.

So overall this patch looks good to me, thanks!
Patrick
Previous: Andy KoppeNext: Junio C Hamano
Message 2 of 7 in “Makefile: pin cargo --target-dir to ./target”
  1. Makefile: pin cargo --target-dir to ./targetAndy Koppe, Oct 18, 2026
  2. Patrick SteinhardtOct 19, 2026
  3. Junio C HamanoOct 19, 2026
  4. Andy KoppeOct 19, 2026
  5. Junio C HamanoOct 20, 2026
  6. Andy KoppeOct 20, 2026
  7. Junio C HamanoOct 20, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.