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

[WIP] rust: enable for clangarm64 #10423

Closed
wants to merge 2 commits into from

Conversation

dennisameling
Copy link
Contributor

@dennisameling dennisameling commented Dec 27, 2021

Related to #9046

I'm currently doing this work on an 8-core Intel i7-9700 with 32GB RAM instead of my Surface Pro X because of the project size and long build times

This is some first work to get Rust to compile for Windows arm64. This is a bit tricky as it's a massive project to build (and I ran into long path issues as well - moved the project to C:\_ for that). I learned the following about the Rust build process so far:

  • A stage0 compiler is downloaded as indicated in mingw-w64-rust\src\rustc-1.57.0-src\src\stage0.json. In this case it downloads dist/2021-11-01/cargo-1.56.1-x86_64-pc-windows-gnu.tar.gz
  • Rust will bootstrap the stage0 and stage1 compiler for x86_64-pc-windows-gnu
  • Rust will try to use that compiler to target aarch64-pc-windows-gnu

The build currently fails at the last step where it tries to find crt2.o but fails. I added the COPYING {} TO {} manually as I only saw the panic show up without any further context or details.

COPYING C:/msys64/clang64/bin\llvm-dwp.exe TO C:\_\_\src\CLANG64\build\x86_64-pc-windows-gnu\stage2\lib\rustlib\x86_64-pc-windows-gnu\bin\rust-llvm-dwp.exe
  c Sysroot { compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-pc-windows-gnu", file: None } } }
COPYING C:\_\_\src\CLANG64\build\x86_64-pc-windows-gnu\stage1-rustc\x86_64-pc-windows-gnu\release\rustc-main.exe TO C:\_\_\src\CLANG64\build\x86_64-pc-windows-gnu\stage2\bin\rustc.exe
< Assemble { target_compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-pc-windows-gnu", file: None } } }
> Std { target: TargetSelection { triple: "aarch64-pc-windows-gnu", file: None }, compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-pc-windows-gnu", file: None } } }
  > StartupObjects { compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-pc-windows-gnu", file: None } }, target: TargetSelection { triple: "aarch64-pc-windows-gnu", file
    > Libdir { compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-pc-windows-gnu", file: None } }, target: TargetSelection { triple: "aarch64-pc-windows-gnu", file: None
      c Sysroot { compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-pc-windows-gnu", file: None } } }
    < Libdir { compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-pc-windows-gnu", file: None } }, target: TargetSelection { triple: "aarch64-pc-windows-gnu", file: None
COPYING C:\_\_\src\CLANG64\build\aarch64-pc-windows-gnu\native\rtstartup\rsbegin.o TO C:\_\_\src\CLANG64\build\x86_64-pc-windows-gnu\stage2\lib\rustlib\aarch64-pc-windows-gnu\lib\rsbegin.o
COPYING C:\_\_\src\CLANG64\build\aarch64-pc-windows-gnu\native\rtstartup\rsend.o TO C:\_\_\src\CLANG64\build\x86_64-pc-windows-gnu\stage2\lib\rustlib\aarch64-pc-windows-gnu\lib\rsend.o
  < StartupObjects { compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-pc-windows-gnu", file: None } }, target: TargetSelection { triple: "aarch64-pc-windows-gnu", file
  c Assemble { target_compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-pc-windows-gnu", file: None } } }
  c Libdir { compiler: Compiler { stage: 2, host: TargetSelection { triple: "x86_64-pc-windows-gnu", file: None } }, target: TargetSelection { triple: "aarch64-pc-windows-gnu", file: None }
COPYING crt2.o TO C:\_\_\src\CLANG64\build\x86_64-pc-windows-gnu\stage2\lib\rustlib\aarch64-pc-windows-gnu\lib\self-contained\crt2.o
thread 'main' panicked at 'src.symlink_metadata() failed with Het systeem kan het opgegeven bestand niet vinden. (os error 2)', src\bootstrap\lib.rs:1326:24

@mati865
Copy link
Collaborator

mati865 commented Dec 28, 2021

You need working AArch64 toolchain so you cannot easily cross compile it using x86_64 system.
I have reverted some changes and made other and it failed after about 8 minutes with the same error as yours:

Details
$ git --no-pager diff
diff --git a/0009-windows-aarch64.patch b/0009-windows-aarch64.patch
index 3aac4bd..12e3110 100644
--- a/0009-windows-aarch64.patch
+++ b/0009-windows-aarch64.patch
@@ -1,7 +1,7 @@
 diff --unified --recursive --text --color --new-file rustc-1.57.0-src-orig/compiler/rustc_target/src/spec/aarch64_pc_windows_gnu.rs rustc-1.57.0-src/compiler/rustc_target/src/spec/aarch64_pc_windows_gnu.rs
 --- rustc-1.57.0-src-orig/compiler/rustc_target/src/spec/aarch64_pc_windows_gnu.rs     1970-01-01 01:00:00.000000000 +0100
 +++ rustc-1.57.0-src/compiler/rustc_target/src/spec/aarch64_pc_windows_gnu.rs  2021-12-27 13:57:28.788805700 +0100
-@@ -0,0 +1,19 @@
+@@ -0,0 +1,20 @@
 +use crate::spec::{LinkerFlavor, Target};
 +
 +pub fn target() -> Target {
@@ -10,7 +10,7 @@ diff --unified --recursive --text --color --new-file rustc-1.57.0-src-orig/compi
 +    let gcc_pre_link_args = base.pre_link_args.entry(LinkerFlavor::Gcc).or_default();
 +    gcc_pre_link_args.push("-march=armv8-a".to_string());
 +    base.max_atomic_width = Some(64);
-+    base.linker = Some("aarch64-w64-mingw32-gcc".to_string());
++    base.linker = Some("aarch64-w64-mingw32-clang".to_string());
 +
 +    Target {
 +        llvm_target: "aarch64-pc-windows-gnu".to_string(),
@@ -18,6 +18,7 @@ diff --unified --recursive --text --color --new-file rustc-1.57.0-src-orig/compi
 +        data_layout: "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128"
 +            .to_string(),
 +        arch: "aarch64".to_string(),
++        function_sections: true,
 +        options: base,
 +    }
 +}
@@ -40,7 +41,7 @@ diff --unified --recursive --text --color --new-file rustc-1.57.0-src-orig/src/b
      } else if target == "x86_64-pc-windows-gnu" {
          "x86_64-w64-mingw32-gcc.exe"
 +    } else if target == "aarch64-pc-windows-gnu" {
-+        "aarch64-w64-mingw32-gcc.exe"
++        "aarch64-w64-mingw32-clang.exe"
      } else {
          "gcc.exe"
      };
diff --git a/PKGBUILD b/PKGBUILD
index c3301cd..3e525de 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -46,7 +46,7 @@ sha256sums=('3546f9c3b91b1f8b8efd26c94d6b50312c08210397b4072ed2748e2bd4445c1a'
             'c4e5ffeef84296d39c3e3e8f807fc8b33ce786b1e4edb21eef26b053586aca27'
             '9e2e2eb9c0684f329b1ce6598fcb66727abf84121087b24670a9cfc44a514888'
             '29f84cb8e05ce304e102e28912a3b4464add406a8ec37a6c6d717b9b7d81b67b'
-            'dcf33adc873394444fa9ef4098cd73a66d26a60e1b5b946a88449bee4372faf7'
+            '2c54ed4058fafb2bd405d0933f3d9ea6b408ea903e46b89c2b910399ec6e0154'
             '8a9b997bfd8817a29ef5efb082e7dfb79d6c0d6566ec0a1a462b6b58b9e06d81')
 validpgpkeys=('108F66205EAEB0AAA8DD5E1C85AB96E6FA1BE5FE'  # Rust Language (Tag and Release Signing Key) <rust-key@rust-lang.org>
               '474E22316ABF4785A88C6E8EA2C794A986419D8A'  # Tom Stellard <tstellar@redhat.com>
@@ -98,9 +98,9 @@ build() {
     --sysconfdir=${MINGW_PREFIX}/etc \
     --localstatedir=${MINGW_PREFIX}/var/lib \
     --build=$OSTYPE \
-    --host=$OSTYPE \
+    --host=aarch64-pc-windows-gnu \
     --target=aarch64-pc-windows-gnu \
-    --release-channel=nightly \
+    --release-channel=stable \
     --enable-ninja \
     --enable-extended \
     --disable-codegen-tests \
@@ -112,7 +112,7 @@ build() {
   DEP_OPENSSL_ROOT=${MINGW_PREFIX} \
   DEP_Z_ROOT=${MINGW_PREFIX} \
   RUST_BACKTRACE=full \
-  ${MINGW_PREFIX}/bin/python ../${_realname}c-${pkgver}-src/x.py build --verbose --stage 2 --target aarch64-pc-windows-gnu
+  ${MINGW_PREFIX}/bin/python ../${_realname}c-${pkgver}-src/x.py build --verbose --stage 2

   #create the install at a temporary directory
   DEP_NGHTTP_ROOT=${MINGW_PREFIX} \

They won't help building this on x86_64 machine but with more tweaking (like adding both clang64/ and clangarm64/ to PATH) could work. That said I think it'd be easier and faster to work on bootstrap compiler outside of makepkg.


The build currently fails at the last step where it tries to find crt2.o but fails. I added the COPYING {} TO {} manually as I only saw the panic show up without any further context or details.

Actually the most helpful thing here is the backtrace printed at the end. Especially these 2 lines:

  16:     0x7ff6940dc961 - bootstrap::compile::copy_self_contained_objects::h1e457a866882eb6d
                               at D:\tmp\r\src\rustc-1.57.0-src\src\bootstrap\compile.rs:252:13

Here Rust asks C compiler where to find "crt2.o" and "dllcrt2.o", there is possibility this will work on AArch64 machine (on x86_64 you'd need cross compiler for AArch64) but I think it'll need patching.

@dennisameling
Copy link
Contributor Author

dennisameling commented Dec 30, 2021

I'll close this PR for now for the following reason:

That said I think it'd be easier and faster to work on bootstrap compiler outside of makepkg.

Following up in dennisameling/rust#1 instead. Have been making some progress there.

I'm not in a rush to get Rust to work as I've got all the dependencies I need now, but would like to slowly continue contributing in this area wherever possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants