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

Re: [PATCH v2 1/2] rust: pick a GCC-compatible Cargo target under MSYS2/MinGW

From
James Le Cuirot <chewi@gentoo.org>
Date
Sep 11, 2026, 22:26 UTC
Message-ID
<c29cd39efc7b472ff1aeaede367d7f39f3ca1eeb.camel@gentoo.org>
In-Reply-To
<xmqqa4pna411.fsf@gitster.g>
On Fri, 2026-09-11 at 14:09 -0700, Junio C Hamano wrote:
Show 15 quoted lines
> "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
> writes:
> 
> > @@ -993,6 +993,7 @@ endif
> >  ifndef DEBUG
> >  CARGO_ARGS += --release
> >  endif
> > +CARGO_ARGS += $(if $(CARGO_TARGET),--target $(CARGO_TARGET))
> 
> Should this use CARGO_BUILD_TARGET (instead of CARGO_TARGET) to
> match what the officially supported Cargo environment variable is
> called?  It would also help us work better with the changes from the
> jc/rust-cargo-build-target topic.
> 
> Thanks.

Yes, without explicitly setting --target at all. This is how Gentoo Linux supports cross-compiling of its Rust packages. Just avoid setting CARGO_BUILD_TARGET (or passing --target) when you're not cross-compiling. It will cause Cargo to behave differently, even if you give the native tuple. For example, RUSTFLAGS is normally applied to both the build host binaries and the target host binaries, but when an explicit target is set, RUSTFLAGS is only applied to the target host binaries.

Regards, Chewi

Show 43 quoted lines
> Author: James Le Cuirot <chewi@gentoo.org>
> Date:   Thu Sep 10 11:20:14 2026 +0100
> 
>     rust: respect CARGO_BUILD_TARGET when locating build output
>     
>     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>
>     Signed-off-by: Junio C Hamano <gitster@pobox.com>
> 
> diff --git a/Makefile b/Makefile
> index d4b775953d..f0ca2e4f72 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -959,7 +959,7 @@ RUST_LIB_NAME = gitcore.lib
>  else
>  RUST_LIB_NAME = libgitcore.a
>  endif
> -RUST_LIB = target/$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME)
> +RUST_LIB = target/$(if $(CARGO_BUILD_TARGET),$(CARGO_BUILD_TARGET)/)$(RUST_BUILD_CONFIG)/$(RUST_LIB_NAME)
>  endif
>  
>  GITLIBS = common-main.o $(LIB_FILE)
> diff --git a/src/cargo-meson.sh b/src/cargo-meson.sh
> index 75f3cd1265..83c7e7b79b 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:+$CARGO_BUILD_TARGET/}$BUILD_TYPE/$LIBNAME" "$BUILD_DIR/libgitcore.a" >/dev/null 2>&1
>  then
> -	cp "$BUILD_DIR/$BUILD_TYPE/$LIBNAME" "$BUILD_DIR/libgitcore.a"
> +	cp "$BUILD_DIR/${CARGO_BUILD_TARGET:+$CARGO_BUILD_TARGET/}$BUILD_TYPE/$LIBNAME" "$BUILD_DIR/libgitcore.a"
>  fi
Previous: Junio C HamanoNext: Johannes Schindelin
Message 10 of 21 in “Use Rust in the Windows CI jobs”
  1. 0/2 Use Rust in the Windows CI jobsJohannes Schindelin via GitGitGadget, Sep 1, 2026
  2. 1/2 rust: pick a GCC-compatible Cargo target under MSYS2/MinGWJohannes Schindelin via GitGitGadget, Sep 1, 2026
  3. Junio C HamanoSep 2, 2026
  4. Johannes SchindelinSep 11, 2026
  5. 2/2 ci(windows): build with RustJohannes Schindelin via GitGitGadget, Sep 1, 2026
  6. 0/2 Use Rust in the Windows CI jobsJohannes Schindelin via GitGitGadget, Sep 11, 2026
  7. 2/2 ci(windows): build with RustJohannes Schindelin via GitGitGadget, Sep 11, 2026
  8. 1/2 rust: pick a GCC-compatible Cargo target under MSYS2/MinGWJohannes Schindelin via GitGitGadget, Sep 11, 2026
  9. Junio C HamanoSep 11, 2026
  10. James Le CuirotSep 11, 2026
  11. Johannes SchindelinSep 13, 2026
  12. 0/2 Use Rust in the Windows CI jobsJohannes Schindelin via GitGitGadget, Sep 13, 2026
  13. 1/2 rust: pick a GCC-compatible Cargo target under MSYS2/MinGWJohannes Schindelin via GitGitGadget, Sep 13, 2026
  14. 2/2 ci(windows): build with RustJohannes Schindelin via GitGitGadget, Sep 13, 2026
  15. 0/2 Use Rust in the Windows CI jobsJohannes Schindelin via GitGitGadget, Sep 13, 2026
  16. 1/2 rust: pick a GCC-compatible Cargo target under MSYS2/MinGWJohannes Schindelin via GitGitGadget, Sep 13, 2026
  17. 2/2 ci(windows): build with RustJohannes Schindelin via GitGitGadget, Sep 13, 2026
  18. Junio C HamanoSep 13, 2026
  19. Junio C HamanoSep 18, 2026
  20. Johannes SchindelinSep 21, 2026
  21. Junio C HamanoSep 21, 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.