@@ -51,6 +51,17 @@ if [ ${AUTOMERGE_FOUND} -eq 0 ]; then
5151 # Minimum Rust version required (MSRV)
5252 RUST_MSRV=" 1.85"
5353
54+ # Infer the Rust target from the C toolchain
55+ case ` ${CC} -dumpmachine 2> /dev/null` in
56+ aarch64* )
57+ CARGO_TARGET=" aarch64-pc-windows-gnullvm"
58+ ;;
59+ * )
60+ CARGO_TARGET=" x86_64-pc-windows-gnu"
61+ ;;
62+ esac
63+ echo " Using Rust target: ${CARGO_TARGET} "
64+
5465 # Check for Rust toolchain (cargo and rustc)
5566 # CRAN policy: check both system PATH and ~/.cargo/bin
5667 CARGO_CMD=" "
@@ -82,7 +93,7 @@ if [ ${AUTOMERGE_FOUND} -eq 0 ]; then
8293 echo " "
8394 echo " Install Rust from https://rustup.rs/:"
8495 echo " 1. Download and run rustup-init.exe"
85- echo " 2. Select: x86_64-pc-windows-gnu toolchain "
96+ echo " 2. After installation run: rustup target add ${CARGO_TARGET} "
8697 echo " "
8798 echo " Or via winget: winget install Rustlang.Rustup"
8899 echo " Or via scoop: scoop install rustup"
@@ -110,9 +121,15 @@ if [ ${AUTOMERGE_FOUND} -eq 0 ]; then
110121 exit 1
111122 fi
112123
113- # Ensure GNU toolchain is used (required for Rtools compatibility)
114- if ! $RUSTC_CMD --version --verbose 2> /dev/null | grep -q " host:.*windows-gnu" ; then
115- echo " Note: Configuring Rust to use GNU toolchain for Rtools compatibility"
124+ # Fail before the lengthy build if the target stdlib is absent
125+ TARGET_LIBDIR=$( $RUSTC_CMD --print target-libdir --target " ${CARGO_TARGET} " 2> /dev/null)
126+ if [ ! -d " $TARGET_LIBDIR " ]; then
127+ echo " -------------------- RUST TARGET NOT INSTALLED --------------------"
128+ echo " The Rust standard library for ${CARGO_TARGET} is not installed."
129+ echo " "
130+ echo " Install it with: rustup target add ${CARGO_TARGET} "
131+ echo " --------------------------------------------------------------------"
132+ exit 1
116133 fi
117134
118135 echo " Building automerge-c from bundled source..."
@@ -153,13 +170,10 @@ EOF
153170 xz -dc src/automerge/rust/vendor.tar.xz | tar -xf - -C src/automerge/rust
154171 fi
155172
156- # Force GNU target to match MinGW toolchain from Rtools
157- export RUSTUP_TOOLCHAIN=" stable-x86_64-pc-windows-gnu"
158-
159173 echo " Building (this may take several minutes)..."
160174 # Default features select UTF-32 indexing; -j2 respects CRAN's core limit.
161175 # build.rs runs cbindgen to emit ${CBINDGEN_TARGET_DIR}/automerge.h.
162- " $CARGO_CMD " build --release -j2 \
176+ " $CARGO_CMD " build --release -j2 --target " ${CARGO_TARGET} " \
163177 --manifest-path src/automerge/rust/automerge-c/Cargo.toml \
164178 || { echo " ERROR: cargo build failed" ; exit 1; }
165179
178192 " $HEADER " > " ${HEADER} .tmp" && mv " ${HEADER} .tmp" " $HEADER "
179193
180194 # Stage the static library where Makevars expects it
181- cp am-build/target/release/libautomerge_core.a am-install/lib/libautomerge.a \
195+ cp " am-build/target/${CARGO_TARGET} / release/libautomerge_core.a" am-install/lib/libautomerge.a \
182196 || { echo " ERROR: failed to stage static library" ; exit 1; }
183197
184198 rm -rf am-build
0 commit comments