{"thread":{"id":"66294","subject":"[PATCH] rust: respect CARGO_BUILD_TARGET when locating build output","startedAt":"2026-09-08T15:25:15Z","lastAt":"2026-09-10T10:23:47Z","messageCount":5,"participants":["James Le Cuirot","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"552217","messageId":"20260908152425.153131-2-chewi@gentoo.org","threadId":"66294","inReplyTo":null,"subject":"[PATCH] rust: respect CARGO_BUILD_TARGET when locating build output","fromName":"James Le Cuirot","fromEmail":"chewi@gentoo.org","sentAt":"2026-09-08T15:24:26Z","receivedAt":"2026-09-08T15:25:15Z","isPatch":true,"body":"When cross-compiling, Cargo always writes to a target-tuple subdirectory\ndetermined by CARGO_BUILD_TARGET, even when it matches the native tuple.\nThe script looked in $BUILD_DIR/$BUILD_TYPE directly, so it failed to\nfind (and copy) the freshly built library.\n\nRespect CARGO_BUILD_TARGET in the output path so the correct artifact\nis located.\n\nSigned-off-by: James Le Cuirot <chewi@gentoo.org>\n---\n src/cargo-meson.sh | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/src/cargo-meson.sh b/src/cargo-meson.sh\nindex 75f3cd1..3a558aa 100755\n--- a/src/cargo-meson.sh\n+++ b/src/cargo-meson.sh\n@@ -38,7 +38,7 @@ then\n \texit $RET\n fi\n \n-if ! cmp \"$BUILD_DIR/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\" >/dev/null 2>&1\n+if ! cmp \"$BUILD_DIR/${CARGO_BUILD_TARGET-}/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\" >/dev/null 2>&1\n then\n-\tcp \"$BUILD_DIR/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\"\n+\tcp \"$BUILD_DIR/${CARGO_BUILD_TARGET-}/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\"\n fi\n-- \n2.55.0\n\n"},{"id":"552222","messageId":"xmqqo6e7yaw1.fsf@gitster.g","threadId":"66294","inReplyTo":"20260908152425.153131-2-chewi@gentoo.org","subject":"Re: [PATCH] rust: respect CARGO_BUILD_TARGET when locating build output","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-09-08T16:18:38Z","receivedAt":"2026-09-08T16:18:40Z","isPatch":true,"body":"James Le Cuirot <chewi@gentoo.org> writes:\n\n> Subject: Re: [PATCH] rust: respect CARGO_BUILD_TARGET when locating build output\n>\n> When cross-compiling, Cargo always writes to a target-tuple subdirectory\n> determined by CARGO_BUILD_TARGET, even when it matches the native tuple.\n> The script looked in $BUILD_DIR/$BUILD_TYPE directly, so it failed to\n> find (and copy) the freshly built library.\n>\n> Respect CARGO_BUILD_TARGET in the output path so the correct artifact\n> is located.\n\nNowhere in the above description I see mention of meson, but the\npatch is only to cargo-meson that is referenced by src/meson.build\nwhich invites a few questions:\n\n * Does \"make\" work fine without any change similar to this?\n\n * Shouldn't the commit title say \"meson\" somewhere if this change\n   is only for \"meson\" driven build?\n\nThanks.\n\n\n>\n> Signed-off-by: James Le Cuirot <chewi@gentoo.org>\n> ---\n>  src/cargo-meson.sh | 4 ++--\n>  1 file changed, 2 insertions(+), 2 deletions(-)\n>\n> diff --git a/src/cargo-meson.sh b/src/cargo-meson.sh\n> index 75f3cd1..3a558aa 100755\n> --- a/src/cargo-meson.sh\n> +++ b/src/cargo-meson.sh\n> @@ -38,7 +38,7 @@ then\n>  \texit $RET\n>  fi\n>  \n> -if ! cmp \"$BUILD_DIR/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\" >/dev/null 2>&1\n> +if ! cmp \"$BUILD_DIR/${CARGO_BUILD_TARGET-}/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\" >/dev/null 2>&1\n>  then\n> -\tcp \"$BUILD_DIR/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\"\n> +\tcp \"$BUILD_DIR/${CARGO_BUILD_TARGET-}/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\"\n>  fi\n"},{"id":"552264","messageId":"20260908215344.24843-2-chewi@gentoo.org","threadId":"66294","inReplyTo":"xmqqo6e7yaw1.fsf@gitster.g","subject":"[PATCH v2] rust: respect CARGO_BUILD_TARGET when locating build output","fromName":"James Le Cuirot","fromEmail":"chewi@gentoo.org","sentAt":"2026-09-08T21:53:45Z","receivedAt":"2026-09-08T21:56:15Z","isPatch":true,"body":"When cross-compiling, Cargo always writes to a target-tuple subdirectory\ndetermined by CARGO_BUILD_TARGET, even when it matches the native tuple.\nThe build looked in $BUILD_DIR/$BUILD_TYPE directly, so it failed to\nlocate the freshly built library.\n\nRespect CARGO_BUILD_TARGET in the output path so the correct artifact\nis located.\n\nSigned-off-by: James Le Cuirot <chewi@gentoo.org>\n---\n\n> Nowhere in the above description I see mention of meson, but the\n> patch is only to cargo-meson that is referenced by src/meson.build\n> which invites a few questions:\n>\n>  * Does \"make\" work fine without any change similar to this?\n>\n>  * Shouldn't the commit title say \"meson\" somewhere if this change\n>    is only for \"meson\" driven build?\n\nGood point. I hadn't realised that Make is still supported. I have now\namended the Makefile and tested both the native and cross cases.\n\n Makefile           | 4 ++--\n src/cargo-meson.sh | 4 ++--\n 2 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 1cec251..5cd5889 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -940,9 +940,9 @@ TEST_SHELL_PATH = $(SHELL_PATH)\n LIB_FILE = libgit.a\n\n ifdef DEBUG\n-RUST_TARGET_DIR = target/debug\n+RUST_TARGET_DIR = target/$(CARGO_BUILD_TARGET)/debug\n else\n-RUST_TARGET_DIR = target/release\n+RUST_TARGET_DIR = target/$(CARGO_BUILD_TARGET)/release\n endif\n\n ifeq ($(uname_S),Windows)\ndiff --git a/src/cargo-meson.sh b/src/cargo-meson.sh\nindex 75f3cd1..3a558aa 100755\n--- a/src/cargo-meson.sh\n+++ b/src/cargo-meson.sh\n@@ -38,7 +38,7 @@ then\n \texit $RET\n fi\n\n-if ! cmp \"$BUILD_DIR/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\" >/dev/null 2>&1\n+if ! cmp \"$BUILD_DIR/${CARGO_BUILD_TARGET-}/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\" >/dev/null 2>&1\n then\n-\tcp \"$BUILD_DIR/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\"\n+\tcp \"$BUILD_DIR/${CARGO_BUILD_TARGET-}/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\"\n fi\n--\n2.55.0\n"},{"id":"552375","messageId":"xmqq4ifyqjdi.fsf@gitster.g","threadId":"66294","inReplyTo":"20260908215344.24843-2-chewi@gentoo.org","subject":"Re: [PATCH v2] rust: respect CARGO_BUILD_TARGET when locating build output","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-09-09T20:07:05Z","receivedAt":"2026-09-09T20:07:08Z","isPatch":true,"body":"James Le Cuirot <chewi@gentoo.org> writes:\n\n> When cross-compiling, Cargo always writes to a target-tuple subdirectory\n> determined by CARGO_BUILD_TARGET, even when it matches the native tuple.\n> The build looked in $BUILD_DIR/$BUILD_TYPE directly, so it failed to\n> locate the freshly built library.\n>\n> Respect CARGO_BUILD_TARGET in the output path so the correct artifact\n> is located.\n>\n> Signed-off-by: James Le Cuirot <chewi@gentoo.org>\n> ---\n>\n>> Nowhere in the above description I see mention of meson, but the\n>> patch is only to cargo-meson that is referenced by src/meson.build\n>> which invites a few questions:\n>>\n>>  * Does \"make\" work fine without any change similar to this?\n>>\n>>  * Shouldn't the commit title say \"meson\" somewhere if this change\n>>    is only for \"meson\" driven build?\n>\n> Good point. I hadn't realised that Make is still supported. I have now\n> amended the Makefile and tested both the native and cross cases.\n>\n>  Makefile           | 4 ++--\n>  src/cargo-meson.sh | 4 ++--\n>  2 files changed, 4 insertions(+), 4 deletions(-)\n>\n> diff --git a/Makefile b/Makefile\n> index 1cec251..5cd5889 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -940,9 +940,9 @@ TEST_SHELL_PATH = $(SHELL_PATH)\n>  LIB_FILE = libgit.a\n>\n>  ifdef DEBUG\n> -RUST_TARGET_DIR = target/debug\n> +RUST_TARGET_DIR = target/$(CARGO_BUILD_TARGET)/debug\n>  else\n> -RUST_TARGET_DIR = target/release\n> +RUST_TARGET_DIR = target/$(CARGO_BUILD_TARGET)/release\n>  endif\n\nThis seems to be based on a bit stale codebase.  Specifically you\nwould want to build on top of post-924dfced6b (Makefile: support\nuniversal macOS builds via RUST_TARGETS, 2026-07-08) version of\nMakefile.\n\n>\n>  ifeq ($(uname_S),Windows)\n> diff --git a/src/cargo-meson.sh b/src/cargo-meson.sh\n> index 75f3cd1..3a558aa 100755\n> --- a/src/cargo-meson.sh\n> +++ b/src/cargo-meson.sh\n> @@ -38,7 +38,7 @@ then\n>  \texit $RET\n>  fi\n>\n> -if ! cmp \"$BUILD_DIR/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\" >/dev/null 2>&1\n> +if ! cmp \"$BUILD_DIR/${CARGO_BUILD_TARGET-}/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\" >/dev/null 2>&1\n\nWhen CARGO_BUILD_TARGET is not defined, this leaves double slashes\nin the resujlting pathname, which may not be incorrect per-se, but\nstill is not what you meant to say, which is probably a lot closer\nto\n\n    ${CARGO_BUILD_TARGET+$CARGO_BUILD_TARGET/}\n\n\n\n>  then\n> -\tcp \"$BUILD_DIR/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\"\n> +\tcp \"$BUILD_DIR/${CARGO_BUILD_TARGET-}/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\"\n>  fi\n> --\n> 2.55.0\n"},{"id":"552430","messageId":"20260910102013.1235066-2-chewi@gentoo.org","threadId":"66294","inReplyTo":"xmqq4ifyqjdi.fsf@gitster.g","subject":"[PATCH v3] rust: respect CARGO_BUILD_TARGET when locating build output","fromName":"James Le Cuirot","fromEmail":"chewi@gentoo.org","sentAt":"2026-09-10T10:20:14Z","receivedAt":"2026-09-10T10:23:47Z","isPatch":true,"body":"When cross-compiling, Cargo always writes to a target-tuple subdirectory\ndetermined by CARGO_BUILD_TARGET, even when it matches the native tuple.\nThe build looked in $BUILD_DIR/$BUILD_TYPE directly, so it failed to\nlocate the freshly built library.\n\nRespect CARGO_BUILD_TARGET in the output path so the correct artifact\nis located.\n\nSigned-off-by: James Le Cuirot <chewi@gentoo.org>\n---\n\n> This seems to be based on a bit stale codebase.  Specifically you\n> would want to build on top of post-924dfced6b (Makefile: support\n> universal macOS builds via RUST_TARGETS, 2026-07-08) version of\n> Makefile.\n\nApologies, I had used the maint branch. Now rebased on master.\n\n> When CARGO_BUILD_TARGET is not defined, this leaves double slashes\n> in the resulting pathname, which may not be incorrect per-se, but\n> still is not what you meant to say, which is probably a lot closer\n> to\n>\n>     ${CARGO_BUILD_TARGET+$CARGO_BUILD_TARGET/}\n\nI believed this would not cause an issue, so I intentionally went with\nsimplicity over correctness. It's not a big difference though, so this\nrevision goes with correctness.\n\n Makefile           | 2 +-\n src/cargo-meson.sh | 4 ++--\n 2 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex d4b7759..f0ca2e4 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -959,7 +959,7 @@ RUST_LIB_NAME = gitcore.lib\n else\n RUST_LIB_NAME = libgitcore.a\n endif\n-RUST_LIB = target/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME)\n+RUST_LIB = target/$(if $(CARGO_BUILD_TARGET),$(CARGO_BUILD_TARGET)/)$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME)\n endif\n\n GITLIBS = common-main.o $(LIB_FILE)\ndiff --git a/src/cargo-meson.sh b/src/cargo-meson.sh\nindex 75f3cd1..83c7e7b 100755\n--- a/src/cargo-meson.sh\n+++ b/src/cargo-meson.sh\n@@ -38,7 +38,7 @@ then\n \texit $RET\n fi\n\n-if ! cmp \"$BUILD_DIR/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\" >/dev/null 2>&1\n+if ! cmp \"$BUILD_DIR/${CARGO_BUILD_TARGET:+$CARGO_BUILD_TARGET/}$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\" >/dev/null 2>&1\n then\n-\tcp \"$BUILD_DIR/$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\"\n+\tcp \"$BUILD_DIR/${CARGO_BUILD_TARGET:+$CARGO_BUILD_TARGET/}$BUILD_TYPE/$LIBNAME\" \"$BUILD_DIR/libgitcore.a\"\n fi\n--\n2.55.0\n"}]}