Re: [PATCH v2] rust: respect CARGO_BUILD_TARGET when locating build output
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 9, 2026, 20:07 UTC
- Message-ID
- <xmqq4ifyqjdi.fsf@gitster.g>
- In-Reply-To
- <20260908215344.24843-2-chewi@gentoo.org>
James Le Cuirot <chewi@gentoo.org> writes:
Show 41 quoted lines
> When cross-compiling, Cargo always writes to a target-tuple subdirectory > determined by CARGO_BUILD_TARGET, even when it matches the native tuple. > The build looked in $BUILD_DIR/$BUILD_TYPE directly, so it failed to > locate the freshly built library. > > Respect CARGO_BUILD_TARGET in the output path so the correct artifact > is located. > > Signed-off-by: James Le Cuirot <chewi@gentoo.org> > --- > >> Nowhere in the above description I see mention of meson, but the >> patch is only to cargo-meson that is referenced by src/meson.build >> which invites a few questions: >> >> * Does "make" work fine without any change similar to this? >> >> * Shouldn't the commit title say "meson" somewhere if this change >> is only for "meson" driven build? > > Good point. I hadn't realised that Make is still supported. I have now > amended the Makefile and tested both the native and cross cases. > > Makefile | 4 ++-- > src/cargo-meson.sh | 4 ++-- > 2 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/Makefile b/Makefile > index 1cec251..5cd5889 100644 > --- a/Makefile > +++ b/Makefile > @@ -940,9 +940,9 @@ TEST_SHELL_PATH = $(SHELL_PATH) > LIB_FILE = libgit.a > > ifdef DEBUG > -RUST_TARGET_DIR = target/debug > +RUST_TARGET_DIR = target/$(CARGO_BUILD_TARGET)/debug > else > -RUST_TARGET_DIR = target/release > +RUST_TARGET_DIR = target/$(CARGO_BUILD_TARGET)/release > endif
This seems to be based on a bit stale codebase. Specifically you would want to build on top of post-924dfced6b (Makefile: support universal macOS builds via RUST_TARGETS, 2026-07-08) version of Makefile.
Show 12 quoted lines
>
> ifeq ($(uname_S),Windows)
> diff --git a/src/cargo-meson.sh b/src/cargo-meson.sh
> index 75f3cd1..3a558aa 100755
> --- a/src/cargo-meson.sh
> +++ b/src/cargo-meson.sh
> @@ -38,7 +38,7 @@ then
> exit $RET
> fi
>
> -if ! cmp "$BUILD_DIR/$BUILD_TYPE/$LIBNAME" "$BUILD_DIR/libgitcore.a" >/dev/null 2>&1
> +if ! cmp "$BUILD_DIR/${CARGO_BUILD_TARGET-}/$BUILD_TYPE/$LIBNAME" "$BUILD_DIR/libgitcore.a" >/dev/null 2>&1When CARGO_BUILD_TARGET is not defined, this leaves double slashes in the resujlting pathname, which may not be incorrect per-se, but still is not what you meant to say, which is probably a lot closer to
${CARGO_BUILD_TARGET+$CARGO_BUILD_TARGET/}Show 6 quoted lines
> then
> - cp "$BUILD_DIR/$BUILD_TYPE/$LIBNAME" "$BUILD_DIR/libgitcore.a"
> + cp "$BUILD_DIR/${CARGO_BUILD_TARGET-}/$BUILD_TYPE/$LIBNAME" "$BUILD_DIR/libgitcore.a"
> fi
> --
> 2.55.0