Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[experiment] Try building Rust for AArch64 #13278

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions mingw-w64-rust/0009-gnullvm-target.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
diff -urN rustc-1.64.0-src.orig/compiler/rustc_llvm/build.rs rustc-1.64.0-src/compiler/rustc_llvm/build.rs
--- rustc-1.64.0-src.orig/compiler/rustc_llvm/build.rs 2022-09-24 00:14:19.728138800 +0200
+++ rustc-1.64.0-src/compiler/rustc_llvm/build.rs 2022-09-24 17:42:37.065263700 +0200
@@ -235,9 +235,8 @@
let mut cmd = Command::new(&llvm_config);
cmd.arg(llvm_link_arg).arg("--libs");

- if !is_crossed {
- cmd.arg("--system-libs");
- } else if target.contains("windows-gnu") {
+ cmd.arg("--system-libs");
+ if target.contains("windows-gnu") {
println!("cargo:rustc-link-lib=shell32");
println!("cargo:rustc-link-lib=uuid");
} else if target.contains("netbsd") || target.contains("haiku") || target.contains("darwin") {
diff -urN rustc-1.64.0-src.orig/library/unwind/src/libunwind.rs rustc-1.64.0-src/library/unwind/src/libunwind.rs
--- rustc-1.64.0-src.orig/library/unwind/src/libunwind.rs 2022-09-19 16:07:21.000000000 +0200
+++ rustc-1.64.0-src/library/unwind/src/libunwind.rs 2022-09-24 16:33:03.606975800 +0200
@@ -90,7 +90,7 @@
// rustc_codegen_ssa::src::back::symbol_export, rustc_middle::middle::exported_symbols
// and RFC 2841
#[cfg_attr(
- all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")),
+ any(all(feature = "llvm-libunwind", any(target_os = "fuchsia", target_os = "linux")), all(target_os = "windows", target_env = "gnu", target_abi = "llvm")),
link(name = "unwind", kind = "static", modifiers = "-bundle")
)]
extern "C-unwind" {
diff -urN rustc-1.64.0-src.orig/src/bootstrap/compile.rs rustc-1.64.0-src/src/bootstrap/compile.rs
--- rustc-1.64.0-src.orig/src/bootstrap/compile.rs 2022-09-19 16:07:21.000000000 +0200
+++ rustc-1.64.0-src/src/bootstrap/compile.rs 2022-09-24 16:19:22.998368200 +0200
@@ -206,7 +206,6 @@
}

if target == "x86_64-fortanix-unknown-sgx"
- || target.contains("pc-windows-gnullvm")
|| builder.config.llvm_libunwind(target) == LlvmLibunwind::InTree
&& (target.contains("linux") || target.contains("fuchsia"))
{
diff -urN rustc-1.64.0-src.orig/src/bootstrap/dist.rs rustc-1.64.0-src/src/bootstrap/dist.rs
--- rustc-1.64.0-src.orig/src/bootstrap/dist.rs 2022-09-24 00:14:19.929176800 +0200
+++ rustc-1.64.0-src/src/bootstrap/dist.rs 2022-09-24 20:04:09.511879200 +0200
@@ -364,18 +364,6 @@

builder.install(&builder.rustdoc(compiler), &image.join("bin"), 0o755);

- let ra_proc_macro_srv = builder
- .ensure(tool::RustAnalyzerProcMacroSrv {
- compiler: builder.compiler_for(
- compiler.stage,
- builder.config.build,
- compiler.host,
- ),
- target: compiler.host,
- })
- .expect("rust-analyzer-proc-macro-server always builds");
- builder.install(&ra_proc_macro_srv, &image.join("libexec"), 0o755);
-
let libdir_relative = builder.libdir_relative(compiler);

// Copy runtime DLLs needed by the compiler
74 changes: 51 additions & 23 deletions mingw-w64-rust/PKGBUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pkgver=1.64.0
pkgrel=1
pkgdesc="Systems programming language focused on safety, speed and concurrency (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
mingw_arch=('clangarm64')
url="https://www.rust-lang.org/"
license=('MIT' 'Apache')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
Expand All @@ -27,6 +27,8 @@ makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
"${MINGW_PACKAGE_PREFIX}-autotools"
$([[ "$_bootstrapping" == "no" ]] && echo "${MINGW_PACKAGE_PREFIX}-rust")
"${MINGW_PACKAGE_PREFIX}-zlib"
"mingw-w64-x86_64-gcc"
"mingw-w64-x86_64-llvm"
"git")
options=('staticlibs' 'strip')
#install=rust.install
Expand All @@ -36,14 +38,16 @@ source=("https://static.rust-lang.org/dist/${_realname}c-${pkgver}-src.tar.gz"{,
"0004-unbundle-gcc.patch"
"0005-win32-config.patch"
"0007-clang-subsystem.patch"
"0008-disable-self-contained.patch")
"0008-disable-self-contained.patch"
"0009-gnullvm-target.patch")
sha256sums=('b3cd9f481e1a2901bf6f3808d30c69cc4ea80d93c4cc4e2ed52258b180381205'
'SKIP'
'7cb1773c288ffb1c1e751edc49b1890c84bf9c362742bc5225d19d474edb73a0'
'36c531c73a2c12b3e66aa22526a404c3f770f1ab7e0e76c55af6fcc1a17e46fe'
'c4e5ffeef84296d39c3e3e8f807fc8b33ce786b1e4edb21eef26b053586aca27'
'c38450682a48bb1d5a0ddaa37ae5b324d39a9e0626daa2fc695caec1a53d6c35'
'29f84cb8e05ce304e102e28912a3b4464add406a8ec37a6c6d717b9b7d81b67b')
'29f84cb8e05ce304e102e28912a3b4464add406a8ec37a6c6d717b9b7d81b67b'
'03073682837e628eb4d5bfb74c03f6c9d4ad25022ac214f9253a53f132f3084f')
validpgpkeys=('108F66205EAEB0AAA8DD5E1C85AB96E6FA1BE5FE' # Rust Language (Tag and Release Signing Key) <rust-key@rust-lang.org>
'474E22316ABF4785A88C6E8EA2C794A986419D8A' # Tom Stellard <tstellar@redhat.com>
'B6C8F98282B944E3B0D5C2530FC3042E345AD05D') # Hans Wennborg <hans@chromium.org>
Expand All @@ -70,18 +74,23 @@ prepare() {
0005-win32-config.patch \
0008-disable-self-contained.patch

if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then
if [[ $MINGW_PACKAGE_PREFIX == *-clang-x86_64 ]]; then
apply_patch_with_msg \
0007-clang-subsystem.patch
fi

if [[ $MINGW_PACKAGE_PREFIX == *-clang-aarch64 ]]; then
apply_patch_with_msg \
0009-gnullvm-target.patch
fi
}

build() {
[[ -d "${srcdir}/${MSYSTEM}" ]] && rm -rf "${srcdir}/${MSYSTEM}"
mkdir -p "${srcdir}/${MSYSTEM}" && cd "${srcdir}/${MSYSTEM}"

# The ultimate hack to let the bootstrap compiler use libgcc* libs
if [[ $MINGW_PACKAGE_PREFIX == *-clang-* ]]; then
if [[ $MINGW_PACKAGE_PREFIX == *-clang-x86_64 ]]; then
export GCC_LIBS_HACK="$(cygpath -am build/missing-libs-hack)"
mkdir -p "${GCC_LIBS_HACK}"
cp "$(cygpath -u $(clang -print-libgcc-file-name))" "${GCC_LIBS_HACK}/libgcc.a"
Expand All @@ -90,30 +99,45 @@ build() {
export RUSTFLAGS_BOOTSTRAP="-C link-arg=-L$(cygpath -am build/missing-libs-hack)"
fi

# We have to do the following because rust doesn't count x86_64-w64-mingw32 as a target triple
OSTYPE="$CARCH-pc-windows-gnu"

# Otherwise it uses gcc during bootstrap, even when we build for clang
export CARGO_TARGET_${CARCH^^}_PC_WINDOWS_GNU_LINKER="${CC}"

local -a _rust_conf=()
if [ "${_bootstrapping}" = "no" ]; then
_rust_conf+=("--local-rust-root=$(cygpath -m ${MINGW_PREFIX})")
fi

# Cross compile to gnullvm host
if [[ $MINGW_PACKAGE_PREFIX == *-clang-aarch64 ]]; then
BUILD="x86_64-pc-windows-gnu"
HOST="$CARCH-pc-windows-gnullvm"
export PATH="/mingw64/bin:${PATH}"
_rust_conf+=("--set target.${BUILD}.cc=/mingw64/bin/gcc.exe"
"--set target.${BUILD}.cxx=/mingw64/bin/g++.exe"
"--set target.${BUILD}.linker=/mingw64/bin/gcc.exe"
"--set target.${BUILD}.llvm-config=/mingw64/bin/llvm-config.exe"
"--set target.${HOST}.cc=${MINGW_PREFIX}/bin/clang.exe"
"--set target.${HOST}.cxx=${MINGW_PREFIX}/bin/clang++.exe"
"--set target.${HOST}.linker=${MINGW_PREFIX}/bin/clang.exe"
"--set target.${HOST}.llvm-config=${MINGW_PREFIX}/bin/llvm-config.exe"
"--tools=cargo,clippy,rustfmt,src"
)
else
BUILD="$CARCH-pc-windows-gnu"
HOST="$BUILD"
fi

# For a faster build:
# - add --disable-docs and --disable-compiler-docs
# - compile only rustc by removing --enable-extended
# - run makepkg-mingw with --nocheck
# - remove --stage 2 (or set it to 1)

MSYS2_ARG_CONV_EXCL="--prefix;--sysconfdir;--localstatedir" \
../${_realname}c-${pkgver}-src/configure \
--prefix=${MINGW_PREFIX} \
--sysconfdir=${MINGW_PREFIX}/etc \
--localstatedir=${MINGW_PREFIX}/var/lib \
--build=$OSTYPE \
--host=$OSTYPE \
--target=$OSTYPE \
--build=$BUILD \
--host=$HOST \
--target=$HOST \
--release-channel=stable \
--release-description="Rev${pkgrel}, Built by MSYS2 project" \
--enable-ninja \
Expand All @@ -122,34 +146,38 @@ build() {
--disable-codegen-tests \
--llvm-root=${MINGW_PREFIX} \
--python=${MINGW_PREFIX}/bin/python \
${_rust_conf}
--set target.${BUILD}.linker="${CC}" \
${_rust_conf[@]}

DEP_NGHTTP_ROOT=${MINGW_PREFIX} \
DEP_OPENSSL_ROOT=${MINGW_PREFIX} \
DEP_Z_ROOT=${MINGW_PREFIX} \
${MINGW_PREFIX}/bin/python ../${_realname}c-${pkgver}-src/x.py build --verbose --stage 2
${MINGW_PREFIX}/bin/python ../${_realname}c-${pkgver}-src/x.py build

# create the install at a temporary directory
DEP_NGHTTP_ROOT=${MINGW_PREFIX} \
DEP_OPENSSL_ROOT=${MINGW_PREFIX} \
DEP_Z_ROOT=${MINGW_PREFIX} \
DESTDIR="$PWD"/dest-rust ${MINGW_PREFIX}/bin/python ../${_realname}c-${pkgver}-src/x.py install --stage 2 --verbose
DESTDIR="$PWD"/dest-rust ${MINGW_PREFIX}/bin/python ../${_realname}c-${pkgver}-src/x.py install

# move docs out of the way for splitting
mv dest-rust/${MINGW_PREFIX}/share/doc dest-doc

rm -f dest-rust/${MINGW_PREFIX}/bin/libgcc*.dll
rm -f dest-rust/${MINGW_PREFIX}/bin/libstd*.dll
rm -f dest-rust/${MINGW_PREFIX}/bin/libwinpthread*.dll
rm -f dest-rust/${MINGW_PREFIX}/lib/rustlib/$OSTYPE/lib/self-contained/*
rm -f dest-rust/${MINGW_PREFIX}/lib/rustlib/$HOST/lib/self-contained/*
}

check() {
cd "${srcdir}/${MSYSTEM}"
DEP_NGHTTP_ROOT=${MINGW_PREFIX} \
DEP_OPENSSL_ROOT=${MINGW_PREFIX} \
DEP_Z_ROOT=${MINGW_PREFIX} \
${MINGW_PREFIX}/bin/python ../${_realname}c-${pkgver}-src/x.py test --stage 2 --exclude src/test/debuginfo
# The tests won't succeed in cross-compilation
if [[ $MINGW_PACKAGE_PREFIX != *-clang-aarch64 ]]; then
cd "${srcdir}/${MSYSTEM}"
DEP_NGHTTP_ROOT=${MINGW_PREFIX} \
DEP_OPENSSL_ROOT=${MINGW_PREFIX} \
DEP_Z_ROOT=${MINGW_PREFIX} \
${MINGW_PREFIX}/bin/python ../${_realname}c-${pkgver}-src/x.py test --stage 2 --exclude src/test/debuginfo
fi
}


Expand Down