{"thread":{"id":"66580","subject":"[PATCH] Makefile: pin cargo --target-dir to ./target","startedAt":"2026-10-18T20:53:05Z","lastAt":"2026-10-20T21:15:44Z","messageCount":7,"participants":["Andy Koppe","Patrick Steinhardt","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"555366","messageId":"20261018205305.2634339-1-andy.koppe@gmail.com","threadId":"66580","inReplyTo":null,"subject":"[PATCH] Makefile: pin cargo --target-dir to ./target","fromName":"Andy Koppe","fromEmail":"andy.koppe@gmail.com","sentAt":"2026-10-18T20:53:05Z","receivedAt":"2026-10-18T20:53:05Z","isPatch":true,"sender":{"key":"andy.koppe@gmail.com","avatar":"https://avatars.githubusercontent.com/u/223411?v=4"},"body":"The Makefile assumes that cargo places build artifacts under ./target.\nThat assumption breaks if the user has a custom target dir setting, e.g.\nin their ~/.cargo/config.toml file or in the CARGO_TARGET_DIR env var.\nThis results in a link error due to failing to find the gitcore library\nbuilt with cargo.\n\nTo fix this, pass '--target-dir target' to the cargo commands that build\ngitcore. Add it directly to the recipes rather than to CARGO_ARGS, so\nthat it isn't lost if CARGO_ARGS is overridden.\n\nLeave the contrib/libgit-{sys,rs} targets alone, as nothing depends on\nthe location of their build output.\n\nThe Meson build of gitcore already passes --target-dir explicitly.\n\nSigned-off-by: Andy Koppe <andy.koppe@gmail.com>\n---\n Makefile | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex c649c93c51..aea99a3639 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -3039,7 +3039,7 @@ $(LIB_FILE): $(LIB_OBJS)\n ifndef NO_RUST\n ifeq ($(RUST_TARGETS),)\n $(RUST_LIB): Cargo.toml $(RUST_SOURCES) $(LIB_FILE)\n-\t$(QUIET_CARGO)cargo build $(CARGO_ARGS)\n+\t$(QUIET_CARGO)cargo build $(CARGO_ARGS) --target-dir target\n else\n ifneq ($(words $(RUST_TARGETS)),1)\n ifneq ($(uname_S),Darwin)\n@@ -3049,7 +3049,7 @@ endif\n \n RUST_MEMBER_LIBS = $(foreach target,$(RUST_TARGETS),target/$(target)/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME))\n $(RUST_MEMBER_LIBS): target/%/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME): Cargo.toml $(RUST_SOURCES) $(LIB_FILE)\n-\t$(QUIET_CARGO)cargo build $(CARGO_ARGS) --target $*\n+\t$(QUIET_CARGO)cargo build $(CARGO_ARGS) --target-dir target --target $*\n \n $(RUST_LIB): $(RUST_MEMBER_LIBS)\n \t$(call mkdir_p_parent_template)\n-- \n2.56.0\n\n\n"},{"id":"555387","messageId":"atW8otvbLGDtDBG9@pks.im","threadId":"66580","inReplyTo":"20261018205305.2634339-1-andy.koppe@gmail.com","subject":"Re: [PATCH] Makefile: pin cargo --target-dir to ./target","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-10-19T06:45:54Z","receivedAt":"2026-10-19T06:45:54Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Sun, Oct 18, 2026 at 09:53:05PM +0100, Andy Koppe wrote:\n> The Makefile assumes that cargo places build artifacts under ./target.\n> That assumption breaks if the user has a custom target dir setting, e.g.\n> in their ~/.cargo/config.toml file or in the CARGO_TARGET_DIR env var.\n> This results in a link error due to failing to find the gitcore library\n> built with cargo.\n> \n> To fix this, pass '--target-dir target' to the cargo commands that build\n> gitcore. Add it directly to the recipes rather than to CARGO_ARGS, so\n> that it isn't lost if CARGO_ARGS is overridden.\n> \n> Leave the contrib/libgit-{sys,rs} targets alone, as nothing depends on\n> the location of their build output.\n\nRight. I sometimes wonder whether we maybe want to start merging this\ninto the main Rust library. But that's certainly a topic for another\nday.\n\n> The Meson build of gitcore already passes --target-dir explicitly.\n\nIndeed it does.\n\n> diff --git a/Makefile b/Makefile\n> index c649c93c51..aea99a3639 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -3039,7 +3039,7 @@ $(LIB_FILE): $(LIB_OBJS)\n>  ifndef NO_RUST\n>  ifeq ($(RUST_TARGETS),)\n>  $(RUST_LIB): Cargo.toml $(RUST_SOURCES) $(LIB_FILE)\n> -\t$(QUIET_CARGO)cargo build $(CARGO_ARGS)\n> +\t$(QUIET_CARGO)cargo build $(CARGO_ARGS) --target-dir target\n>  else\n>  ifneq ($(words $(RUST_TARGETS)),1)\n>  ifneq ($(uname_S),Darwin)\n> @@ -3049,7 +3049,7 @@ endif\n>  \n>  RUST_MEMBER_LIBS = $(foreach target,$(RUST_TARGETS),target/$(target)/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME))\n>  $(RUST_MEMBER_LIBS): target/%/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME): Cargo.toml $(RUST_SOURCES) $(LIB_FILE)\n> -\t$(QUIET_CARGO)cargo build $(CARGO_ARGS) --target $*\n> +\t$(QUIET_CARGO)cargo build $(CARGO_ARGS) --target-dir target --target $*\n>  \n>  $(RUST_LIB): $(RUST_MEMBER_LIBS)\n>  \t$(call mkdir_p_parent_template)\n\nMakes sense. I would have preferred to use the \"--target-dir=target\"\nform, but that really only is a nit that does not warrant a reroll in my\nopinion.\n\nSo overall this patch looks good to me, thanks!\n\nPatrick\n\n"},{"id":"555434","messageId":"xmqq33u165dp.fsf@gitster.g","threadId":"66580","inReplyTo":"20261018205305.2634339-1-andy.koppe@gmail.com","subject":"Re: [PATCH] Makefile: pin cargo --target-dir to ./target","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-19T16:07:30Z","receivedAt":"2026-10-19T16:07:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andy Koppe <andy.koppe@gmail.com> writes:\n\n> The Makefile assumes that cargo places build artifacts under ./target.\n> That assumption breaks if the user has a custom target dir setting, e.g.\n> in their ~/.cargo/config.toml file or in the CARGO_TARGET_DIR env var.\n> This results in a link error due to failing to find the gitcore library\n> built with cargo.\n>\n> To fix this, pass '--target-dir target' to the cargo commands that build\n> gitcore. Add it directly to the recipes rather than to CARGO_ARGS, so\n> that it isn't lost if CARGO_ARGS is overridden.\n>\n> Leave the contrib/libgit-{sys,rs} targets alone, as nothing depends on\n> the location of their build output.\n>\n> The Meson build of gitcore already passes --target-dir explicitly.\n>\n> Signed-off-by: Andy Koppe <andy.koppe@gmail.com>\n> ---\n>  Makefile | 4 ++--\n>  1 file changed, 2 insertions(+), 2 deletions(-)\n\nThe change might make sense, but these areas are touched by other\ntopics in flight.\n\nGiven that they both appear on the same line as $(CARGO_ARGS)\nappears, I have to wonder if we want to instead just add a single\n\n    CARGO_ARGS += --target-dir target\n\nsomewhere early that are unreleated to these individual rules?\n\n> diff --git a/Makefile b/Makefile\n> index c649c93c51..aea99a3639 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -3039,7 +3039,7 @@ $(LIB_FILE): $(LIB_OBJS)\n>  ifndef NO_RUST\n>  ifeq ($(RUST_TARGETS),)\n>  $(RUST_LIB): Cargo.toml $(RUST_SOURCES) $(LIB_FILE)\n> -\t$(QUIET_CARGO)cargo build $(CARGO_ARGS)\n> +\t$(QUIET_CARGO)cargo build $(CARGO_ARGS) --target-dir target\n>  else\n>  ifneq ($(words $(RUST_TARGETS)),1)\n>  ifneq ($(uname_S),Darwin)\n> @@ -3049,7 +3049,7 @@ endif\n>  \n>  RUST_MEMBER_LIBS = $(foreach target,$(RUST_TARGETS),target/$(target)/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME))\n>  $(RUST_MEMBER_LIBS): target/%/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME): Cargo.toml $(RUST_SOURCES) $(LIB_FILE)\n> -\t$(QUIET_CARGO)cargo build $(CARGO_ARGS) --target $*\n> +\t$(QUIET_CARGO)cargo build $(CARGO_ARGS) --target-dir target --target $*\n>  \n>  $(RUST_LIB): $(RUST_MEMBER_LIBS)\n>  \t$(call mkdir_p_parent_template)\n\n"},{"id":"555452","messageId":"CAHWeT-Z5OhJLYx21V417DoL3xOQJj6viUzCm+04iDe0zu=jVWw@mail.gmail.com","threadId":"66580","inReplyTo":"xmqq33u165dp.fsf@gitster.g","subject":"Re: [PATCH] Makefile: pin cargo --target-dir to ./target","fromName":"Andy Koppe","fromEmail":"andy.koppe@gmail.com","sentAt":"2026-10-19T19:43:24Z","receivedAt":"2026-10-19T19:43:24Z","isPatch":true,"sender":{"key":"andy.koppe@gmail.com","avatar":"https://avatars.githubusercontent.com/u/223411?v=4"},"body":"On Mon, 19 Oct 2026 at 17:07, Junio C Hamano <gitster@pobox.com> wrote:\n> Andy Koppe <andy.koppe@gmail.com> writes:\n> > The Makefile assumes that cargo places build artifacts under ./target.\n> > That assumption breaks if the user has a custom target dir setting, e.g.\n> > in their ~/.cargo/config.toml file or in the CARGO_TARGET_DIR env var.\n> > This results in a link error due to failing to find the gitcore library\n> > built with cargo.\n> >\n> > To fix this, pass '--target-dir target' to the cargo commands that build\n> > gitcore. Add it directly to the recipes rather than to CARGO_ARGS, so\n> > that it isn't lost if CARGO_ARGS is overridden.\n>\n> The change might make sense, but these areas are touched by other\n> topics in flight.\n>\n> Given that they both appear on the same line as $(CARGO_ARGS)\n> appears, I have to wonder if we want to instead just add a single\n>\n>     CARGO_ARGS += --target-dir target\n>\n> somewhere early that are unreleated to these individual rules?\n\nThe problem I see with that approach is that CARGO_ARGS looks like it\nis intended for build preferences similar to CFLAGS or LDFLAGS that\ncould be overridden on the make command line, whereas the target dir\nis a hard requirement of the subsequent link step.\n\nI suppose `override CARGO_ARGS += --target-dir target` would avoid\nthat concern, but also set a trap because any subsequent modifications\nof the variable without `override` would be quietly ignored.\n\nThe conflicting topic apparently is mh/rust-crate-subdir by Mike\nHommey, which moves things into a 'rust' subdirectory, but is looking\nsomewhat stalled:\nhttps://lore.kernel.org/git/20260917060415.2986259-1-mh@glandium.org/\n\nI'd of course be happy to reapply the --target-dir tweak here on top\nof that if it does go ahead, or for Mike to just add it there.\n\nAndy\n\n"},{"id":"555581","messageId":"xmqq7bjcxqkr.fsf@gitster.g","threadId":"66580","inReplyTo":"CAHWeT-Z5OhJLYx21V417DoL3xOQJj6viUzCm+04iDe0zu=jVWw@mail.gmail.com","subject":"Re: [PATCH] Makefile: pin cargo --target-dir to ./target","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-20T16:52:04Z","receivedAt":"2026-10-20T16:52:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andy Koppe <andy.koppe@gmail.com> writes:\n\n> The problem I see with that approach is that CARGO_ARGS looks like it\n> is intended for build preferences similar to CFLAGS or LDFLAGS that\n> could be overridden on the make command line, whereas the target dir\n> is a hard requirement of the subsequent link step.\n>\n> I suppose `override CARGO_ARGS += --target-dir target` would avoid\n> that concern, but also set a trap because any subsequent modifications\n> of the variable without `override` would be quietly ignored.\n\nBut we are already tweaking it with += in the Makefile, aren't we?\n\n    # Rust flags\n    CARGO_ARGS =\n    ifndef V\n    CARGO_ARGS += --quiet\n    endif\n    ifndef DEBUG\n    CARGO_ARGS += --release\n    endif\n    \n\n"},{"id":"555621","messageId":"CAHWeT-aD9pNEdWHVf+M9dXzav1P7dTD+h4mQ8c4gkrpvdYxTxA@mail.gmail.com","threadId":"66580","inReplyTo":"xmqq7bjcxqkr.fsf@gitster.g","subject":"Re: [PATCH] Makefile: pin cargo --target-dir to ./target","fromName":"Andy Koppe","fromEmail":"andy.koppe@gmail.com","sentAt":"2026-10-20T20:05:14Z","receivedAt":"2026-10-20T20:05:14Z","isPatch":true,"sender":{"key":"andy.koppe@gmail.com","avatar":"https://avatars.githubusercontent.com/u/223411?v=4"},"body":"Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Andy Koppe <andy.koppe@gmail.com> writes:\n>\n> > The problem I see with that approach is that CARGO_ARGS looks like it\n> > is intended for build preferences similar to CFLAGS or LDFLAGS that\n> > could be overridden on the make command line, whereas the target dir\n> > is a hard requirement of the subsequent link step.\n> >\n> > I suppose `override CARGO_ARGS += --target-dir target` would avoid\n> > that concern, but also set a trap because any subsequent modifications\n> > of the variable without `override` would be quietly ignored.\n>\n> But we are already tweaking it with += in the Makefile, aren't we?\n>\n>     # Rust flags\n>     CARGO_ARGS =\n>     ifndef V\n>     CARGO_ARGS += --quiet\n>     endif\n>     ifndef DEBUG\n>     CARGO_ARGS += --release\n>     endif\n\nYes, but those are preferences that can be overridden on the make\ncommand line without doing harm (within reason), similar to the\ndefault 'CFLAGS = -g -O2 -Wall', whereas the --target-dir should\nalways be passed to ensure the cargo output is going where it's\nexpected.\n\n"},{"id":"555625","messageId":"xmqq1p9kt6nz.fsf@gitster.g","threadId":"66580","inReplyTo":"CAHWeT-aD9pNEdWHVf+M9dXzav1P7dTD+h4mQ8c4gkrpvdYxTxA@mail.gmail.com","subject":"Re: [PATCH] Makefile: pin cargo --target-dir to ./target","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-10-20T21:15:44Z","receivedAt":"2026-10-20T21:15:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andy Koppe <andy.koppe@gmail.com> writes:\n\n> Junio C Hamano <gitster@pobox.com> wrote:\n>>\n>> Andy Koppe <andy.koppe@gmail.com> writes:\n>>\n>> > The problem I see with that approach is that CARGO_ARGS looks like it\n>> > is intended for build preferences similar to CFLAGS or LDFLAGS that\n>> > could be overridden on the make command line, whereas the target dir\n>> > is a hard requirement of the subsequent link step.\n>> >\n>> > I suppose `override CARGO_ARGS += --target-dir target` would avoid\n>> > that concern, but also set a trap because any subsequent modifications\n>> > of the variable without `override` would be quietly ignored.\n>>\n>> But we are already tweaking it with += in the Makefile, aren't we?\n>>\n>>     # Rust flags\n>>     CARGO_ARGS =\n>>     ifndef V\n>>     CARGO_ARGS += --quiet\n>>     endif\n>>     ifndef DEBUG\n>>     CARGO_ARGS += --release\n>>     endif\n>\n> Yes, but those are preferences that can be overridden on the make\n> command line without doing harm (within reason), similar to the\n> default 'CFLAGS = -g -O2 -Wall', whereas the --target-dir should\n> always be passed to ensure the cargo output is going where it's\n> expected.\n\nThat's fair.\n\nSo if we wanted to go that route, we'd need a companion variable for\nCARGO_ARGS that is similar to BASIC_CFLAGS we have for CFLAGS, which\nmay not be a bad thing to have in the longer term assuming that we\nwould have more targets that need to use CARGO_ARGS.\n\nAnyway, this was not an objection to the way the patch was\noriginally written.  Just I noticed while resolving conflicts\nbetween in-flight topics.\n\nThanks.\n\n\n\n"}]}