Build Rust in Clang32 subsystem

This commit is contained in:
Mateusz Mikuła
2022-11-11 14:09:04 +01:00
parent 031f5a4f81
commit c149d80c8c
3 changed files with 158 additions and 44 deletions

View File

@@ -1,10 +1,78 @@
diff -urN rustc-1.65.0-src/compiler/rustc_target/src/spec/windows_gnu_base.rs.orig rustc-1.65.0-src/compiler/rustc_target/src/spec/windows_gnu_base.rs
--- rustc-1.65.0-src/compiler/rustc_target/src/spec/windows_gnu_base.rs.orig 2022-11-02 15:36:24.000000000 +0100
+++ rustc-1.65.0-src/compiler/rustc_target/src/spec/windows_gnu_base.rs 2022-11-04 14:02:11.995756500 +0100
diff -urN rustc-1.65.0-src.orig/compiler/rustc_target/src/spec/crt_objects.rs rustc-1.65.0-src/compiler/rustc_target/src/spec/crt_objects.rs
--- rustc-1.65.0-src.orig/compiler/rustc_target/src/spec/crt_objects.rs 2022-11-02 15:36:24.000000000 +0100
+++ rustc-1.65.0-src/compiler/rustc_target/src/spec/crt_objects.rs 2022-11-09 22:12:19.171603900 +0100
@@ -52,17 +52,6 @@
obj_table.iter().map(|(z, k)| (*z, k.iter().map(|b| (*b).into()).collect())).collect()
}
-pub(super) fn all(obj: &'static str) -> CrtObjects {
- new(&[
- (LinkOutputKind::DynamicNoPicExe, &[obj]),
- (LinkOutputKind::DynamicPicExe, &[obj]),
- (LinkOutputKind::StaticNoPicExe, &[obj]),
- (LinkOutputKind::StaticPicExe, &[obj]),
- (LinkOutputKind::DynamicDylib, &[obj]),
- (LinkOutputKind::StaticDylib, &[obj]),
- ])
-}
-
pub(super) fn pre_musl_self_contained() -> CrtObjects {
new(&[
(LinkOutputKind::DynamicNoPicExe, &["crt1.o", "crti.o", "crtbegin.o"]),
@@ -87,25 +76,25 @@
pub(super) fn pre_mingw_self_contained() -> CrtObjects {
new(&[
- (LinkOutputKind::DynamicNoPicExe, &["crt2.o", "rsbegin.o"]),
- (LinkOutputKind::DynamicPicExe, &["crt2.o", "rsbegin.o"]),
- (LinkOutputKind::StaticNoPicExe, &["crt2.o", "rsbegin.o"]),
- (LinkOutputKind::StaticPicExe, &["crt2.o", "rsbegin.o"]),
- (LinkOutputKind::DynamicDylib, &["dllcrt2.o", "rsbegin.o"]),
- (LinkOutputKind::StaticDylib, &["dllcrt2.o", "rsbegin.o"]),
+ (LinkOutputKind::DynamicNoPicExe, &["crt2.o"]),
+ (LinkOutputKind::DynamicPicExe, &["crt2.o"]),
+ (LinkOutputKind::StaticNoPicExe, &["crt2.o"]),
+ (LinkOutputKind::StaticPicExe, &["crt2.o"]),
+ (LinkOutputKind::DynamicDylib, &["dllcrt2.o"]),
+ (LinkOutputKind::StaticDylib, &["dllcrt2.o"]),
])
}
pub(super) fn post_mingw_self_contained() -> CrtObjects {
- all("rsend.o")
+ CrtObjects::new()
}
pub(super) fn pre_mingw() -> CrtObjects {
- all("rsbegin.o")
+ CrtObjects::new()
}
pub(super) fn post_mingw() -> CrtObjects {
- all("rsend.o")
+ CrtObjects::new()
}
pub(super) fn pre_wasi_self_contained() -> CrtObjects {
diff -urN rustc-1.65.0-src.orig/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs rustc-1.65.0-src/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs
--- rustc-1.65.0-src.orig/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs 2022-11-09 21:53:40.404728900 +0100
+++ rustc-1.65.0-src/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs 2022-11-09 22:07:46.188364200 +0100
@@ -5,7 +5,7 @@
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.frame_pointer = FramePointer::Always; // Required for backtraces
- base.linker = Some("i686-w64-mingw32-gcc".into());
+ base.linker = Some("i686-w64-mingw32-clang".into());
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
// space available to x86 Windows binaries on x86_64.
diff -urN rustc-1.65.0-src.orig/compiler/rustc_target/src/spec/windows_gnu_base.rs rustc-1.65.0-src/compiler/rustc_target/src/spec/windows_gnu_base.rs
--- rustc-1.65.0-src.orig/compiler/rustc_target/src/spec/windows_gnu_base.rs 2022-11-09 21:53:40.397722900 +0100
+++ rustc-1.65.0-src/compiler/rustc_target/src/spec/windows_gnu_base.rs 2022-11-09 22:07:46.181335200 +0100
@@ -24,30 +24,10 @@
],
);
- // Order of `late_link_args*` was found through trial and error to work with various
- // mingw-w64 versions (not tested on the CI). It's expected to change from time to time.
- let mingw_libs = &[
@@ -41,7 +109,7 @@ diff -urN rustc-1.65.0-src/compiler/rustc_target/src/spec/windows_gnu_base.rs.or
+ let static_unwind_libs = &["-l:libunwind.a"];
let mut late_link_args_static = TargetOptions::link_args(LinkerFlavor::Ld, static_unwind_libs);
super::add_link_args(&mut late_link_args_static, LinkerFlavor::Gcc, static_unwind_libs);
@@ -65,7 +45,8 @@
env: "gnu".into(),
vendor: "pc".into(),
@@ -60,13 +128,25 @@ diff -urN rustc-1.65.0-src/compiler/rustc_target/src/spec/windows_gnu_base.rs.or
late_link_args_dynamic,
late_link_args_static,
abi_return_struct_as_int: true,
diff -urN rustc-1.63.0-src/src/bootstrap/bootstrap.py.orig rustc-1.63.0-src/src/bootstrap/bootstrap.py
--- rustc-1.63.0-src/src/bootstrap/bootstrap.py.orig 2022-08-12 19:32:07.547564900 +0200
+++ rustc-1.63.0-src/src/bootstrap/bootstrap.py 2022-08-12 19:51:33.210101800 +0200
@@ -482,6 +482,12 @@
diff -urN rustc-1.65.0-src.orig/compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs rustc-1.65.0-src/compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs
--- rustc-1.65.0-src.orig/compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs 2022-11-09 21:53:40.408733200 +0100
+++ rustc-1.65.0-src/compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs 2022-11-09 22:07:46.192364800 +0100
@@ -7,7 +7,7 @@
base.add_pre_link_args(LinkerFlavor::Ld, &["-m", "i386pep", "--high-entropy-va"]);
base.add_pre_link_args(LinkerFlavor::Gcc, &["-m64", "-Wl,--high-entropy-va"]);
base.max_atomic_width = Some(64);
- base.linker = Some("x86_64-w64-mingw32-gcc".into());
+ base.linker = Some("x86_64-w64-mingw32-clang".into());
Target {
llvm_target: "x86_64-pc-windows-gnu".into(),
diff -urN rustc-1.65.0-src.orig/src/bootstrap/bootstrap.py rustc-1.65.0-src/src/bootstrap/bootstrap.py
--- rustc-1.65.0-src.orig/src/bootstrap/bootstrap.py 2022-11-09 21:53:40.400733100 +0100
+++ rustc-1.65.0-src/src/bootstrap/bootstrap.py 2022-11-09 22:07:46.184853700 +0100
@@ -448,6 +448,12 @@
with output(self.rustc_stamp()) as rust_stamp:
rust_stamp.write(key)
+ gcc_libs_hack = os.environ.get('GCC_LIBS_HACK')
+ gcc_libs_hack_dest = '{}/rustlib/{}/lib'.format(lib_dir, self.build)
+ shutil.copy(gcc_libs_hack + '/libgcc.a', gcc_libs_hack_dest)
@@ -76,25 +156,3 @@ diff -urN rustc-1.63.0-src/src/bootstrap/bootstrap.py.orig rustc-1.63.0-src/src
def _download_component_helper(
self, filename, pattern, tarball_suffix,
):
--- rustc-1.61.0-src/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs.orig 2022-05-22 16:08:33.258876100 +0200
+++ rustc-1.61.0-src/compiler/rustc_target/src/spec/i686_pc_windows_gnu.rs 2022-05-22 16:13:31.577741200 +0200
@@ -7,7 +7,7 @@
.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["-m".to_string(), "i386pe".to_string()]);
base.max_atomic_width = Some(64);
base.frame_pointer = FramePointer::Always; // Required for backtraces
- base.linker = Some("i686-w64-mingw32-gcc".into());
+ base.linker = Some("i686-w64-mingw32-clang".into());
// Mark all dynamic libraries and executables as compatible with the larger 4GiB address
// space available to x86 Windows binaries on x86_64.
--- rustc-1.61.0-src/compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs.orig 2022-05-22 16:08:33.258876100 +0200
+++ rustc-1.61.0-src/compiler/rustc_target/src/spec/x86_64_pc_windows_gnu.rs 2022-05-22 16:13:31.577741200 +0200
@@ -10,7 +10,7 @@
base.pre_link_args
.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec!["-m".into(), "i386pep".into()]);
base.max_atomic_width = Some(64);
- base.linker = Some("x86_64-w64-mingw32-gcc".into());
+ base.linker = Some("x86_64-w64-mingw32-clang".into());
Target {
llvm_target: "x86_64-pc-windows-gnu".into(),

View File

@@ -0,0 +1,46 @@
diff -urN rustc-1.64.0-src.orig/Cargo.lock rustc-1.64.0-src/Cargo.lock
--- rustc-1.64.0-src.orig/Cargo.lock 2022-09-19 16:07:21.000000000 +0200
+++ rustc-1.64.0-src/Cargo.lock 2022-11-08 00:40:11.028288600 +0100
@@ -1227,6 +1227,12 @@
]
[[package]]
+name = "embed-manifest"
+version = "1.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "40ff574b0b0a794f8995383bb83f21f8f99214422cae791cb48d66da524b00f7"
+
+[[package]]
name = "ena"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1911,6 +1917,7 @@
dependencies = [
"anyhow",
"clap",
+ "embed-manifest",
"flate2",
"lazy_static",
"num_cpus",
diff -urN rustc-1.64.0-src.orig/src/tools/rust-installer/build.rs rustc-1.64.0-src/src/tools/rust-installer/build.rs
--- rustc-1.64.0-src.orig/src/tools/rust-installer/build.rs 1970-01-01 01:00:00.000000000 +0100
+++ rustc-1.64.0-src/src/tools/rust-installer/build.rs 2022-11-08 00:18:24.231485300 +0100
@@ -0,0 +1,8 @@
+use embed_manifest::{embed_manifest, new_manifest};
+
+fn main() {
+ if std::env::var_os("CARGO_CFG_WINDOWS").is_some() {
+ embed_manifest(new_manifest("Rust.Installer")).expect("unable to embed manifest file");
+ }
+ println!("cargo:rerun-if-changed=build.rs");
+}
diff -urN rustc-1.64.0-src.orig/src/tools/rust-installer/Cargo.toml rustc-1.64.0-src/src/tools/rust-installer/Cargo.toml
--- rustc-1.64.0-src.orig/src/tools/rust-installer/Cargo.toml 2022-09-19 16:07:38.000000000 +0200
+++ rustc-1.64.0-src/src/tools/rust-installer/Cargo.toml 2022-11-08 00:17:47.651048800 +0100
@@ -26,3 +26,6 @@
[target."cfg(windows)".dependencies]
lazy_static = "1"
winapi = { version = "0.3", features = ["errhandlingapi", "handleapi", "ioapiset", "winerror", "winioctl", "winnt"] }
+
+[build-dependencies]
+embed-manifest = "1.3.1"

View File

@@ -12,10 +12,10 @@ pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}"
"${MINGW_PACKAGE_PREFIX}-rust-docs")
pkgver=1.65.0
pkgrel=1
pkgrel=2
pkgdesc="Systems programming language focused on safety, speed and concurrency (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
url="https://www.rust-lang.org/"
license=('MIT' 'Apache')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
@@ -41,16 +41,18 @@ source=("https://static.rust-lang.org/dist/${_realname}c-${pkgver}-src.tar.gz"{,
"0007-clang-subsystem.patch"
"0008-disable-self-contained.patch"
"0009-build-gnullvm-targets-natively.patch"
"0010-gnullvm-debuginfo-fix.patch")
"0010-gnullvm-debuginfo-fix.patch"
"0011-disable-uac-for-installer.patch")
sha256sums=('5828bb67f677eabf8c384020582b0ce7af884e1c84389484f7f8d00dd82c0038'
'SKIP'
'7cb1773c288ffb1c1e751edc49b1890c84bf9c362742bc5225d19d474edb73a0'
'36c531c73a2c12b3e66aa22526a404c3f770f1ab7e0e76c55af6fcc1a17e46fe'
'c4e5ffeef84296d39c3e3e8f807fc8b33ce786b1e4edb21eef26b053586aca27'
'aa847d81e733543dd8a242f957b7acf39b013952eeee6f0bf7c0f543be1328c4'
'ae9ed98e6bd74ee5ea3bbb2a55f4dbb326164fdc8d55a96e65b98dd33bd49813'
'a214cd8394ab7416fd170c7fa05daf701a5357d38e4e54149370e6efff208e50'
'b0a593a1a954dc51cd214e6ac5aabd2d88922202944eaceb7dd077d78d6dae3a'
'9c16adfddded1aac5ed812d82768dbe625614162639c05d63a0845e37e74fa0e')
'9c16adfddded1aac5ed812d82768dbe625614162639c05d63a0845e37e74fa0e'
'214cd060efd4908d253d78c95e4f6288fdeb56a5dd9303c3718752f32f35af51')
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>
@@ -93,7 +95,7 @@ prepare() {
0008-disable-self-contained.patch \
0010-gnullvm-debuginfo-fix.patch
if [[ $MINGW_PACKAGE_PREFIX == *-clang-x86_64 ]]; then
if [[ $MINGW_PACKAGE_PREFIX == *-clang-i686 || $MINGW_PACKAGE_PREFIX == *-clang-x86_64 ]]; then
apply_patch_with_msg \
0007-clang-subsystem.patch
fi
@@ -101,6 +103,10 @@ prepare() {
apply_patch_with_msg \
0009-build-gnullvm-targets-natively.patch
fi
if [[ $MINGW_PACKAGE_PREFIX == *-clang-i686 ]]; then
apply_patch_with_msg \
0011-disable-uac-for-installer.patch
fi
}
build() {
@@ -108,7 +114,7 @@ build() {
mkdir -p "${srcdir}/${MSYSTEM}" && cd "${srcdir}/${MSYSTEM}"
# The ultimate hack to let the bootstrap compiler use libgcc* libs
if [[ $MINGW_PACKAGE_PREFIX == *-clang-x86_64 ]]; then
if [[ $MINGW_PACKAGE_PREFIX == *-clang-i686 || $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"
@@ -145,6 +151,9 @@ build() {
if [ "${_bootstrapping}" = "no" ]; then
_rust_conf+=("--local-rust-root=$(cygpath -m ${MINGW_PREFIX})")
fi
if [[ $MINGW_PACKAGE_PREFIX != *-clang-i686 ]]; then
_rust_conf+=("--enable-vendor")
fi
# For a faster build:
# - add --disable-docs and --disable-compiler-docs
@@ -164,22 +173,23 @@ build() {
--release-description="Rev${pkgrel}, Built by MSYS2 project" \
--enable-ninja \
--enable-extended \
--enable-vendor \
--disable-llvm-static-stdcpp \
--disable-codegen-tests \
--llvm-root=${MINGW_PREFIX} \
--python=${MINGW_PREFIX}/bin/python \
${_rust_conf}
# Building out of tree is not officially supported so we have to workaround some things like vendored deps
cp -r ../${_realname}c-${pkgver}-src/.cargo .
sed -i "s|directory = \"vendor\"|directory = \"../${_realname}c-${pkgver}-src/vendor\"|" .cargo/config.toml
if [[ $MINGW_PACKAGE_PREFIX != *-clang-i686 ]]; then
# Building out of tree is not officially supported so we have to workaround some things like vendored deps
cp -r ../${_realname}c-${pkgver}-src/.cargo .
sed -i "s|directory = \"vendor\"|directory = \"../${_realname}c-${pkgver}-src/vendor\"|" .cargo/config.toml
fi
# 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 --stage 2
# move docs out of the way for splitting
mv dest-rust/${MINGW_PREFIX}/share/doc dest-doc