From a5f6f5a3d1c165645e22e4e9be3d31640abcaf8b Mon Sep 17 00:00:00 2001 From: "Jason S. Clary" Date: Wed, 11 Oct 2023 07:14:23 -0500 Subject: [PATCH 1/3] Support the x86_64-linux-android build target. * Initial support for x86_64-linux-android targets. * Improve target selection for clang link phase. * Only add clang target if it differs from the host. --- xbuild/src/cargo/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xbuild/src/cargo/mod.rs b/xbuild/src/cargo/mod.rs index 895c04a..910f0bb 100644 --- a/xbuild/src/cargo/mod.rs +++ b/xbuild/src/cargo/mod.rs @@ -321,7 +321,9 @@ impl CargoBuild { target_sdk_version ); self.use_ld("lld"); - self.add_link_arg("--target=aarch64-linux-android"); + if let Some(triple) = self.triple { + self.add_link_arg(&format!("--target={}", triple)); + } self.add_link_arg(&format!("-B{}", sdk_lib_dir.display())); self.add_link_arg(&format!("-L{}", sdk_lib_dir.display())); self.add_link_arg(&format!("-L{}", lib_dir.display())); From 8920f8cd8f4b35e932c35053973d0545eb0e5128 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Tue, 7 Jan 2025 16:24:33 +0100 Subject: [PATCH 2/3] android: Set SDK/API level via version-suffxed `--target` triple We haven't set the SDK/API level via the `__ANDROID_API__` define for a very long time and so far got away with it. However, while debugging why `backtrace` (and by extension Rust `std` which reuses that crate) wasn't generating symbolicated stacktraces in `panic_log`, and why `findshlibs` wasn't providing the list of loaded libraries to `sentry`, we found that both rely on expanding the `__ANDROID_API__` define via compiling a small C file via `cc` to make the code conditional on SDK/API >= 21: https://github.com/gimli-rs/findshlibs/pull/65 https://github.com/rust-lang/backtrace-rs/pull/415 (It would have been lovely if these crates emitted a `cargo:warning` when the define wasn't set at all, indicating an "incomplete" cross-compiler setup, and/or looked at the runtime Android API version via something like https://github.com/rust-mobile/ndk/pull/479.) Note that `backtrace 0.3.74` / Rust 1.82 (https://github.com/rust-lang/rust/commit/0763a3a) no longer rely on this because Rust 1.82 bumped the minimum SDK/API level to 21: https://github.com/rust-lang/backtrace-rs/pull/656 We could set this define directly, or rely on `clang` to set it for us by appending the SDK/API level to the target triple, of the form `-linux-android`. The latter is more common. Keep in mind that the `cc` crate adds an unversioned `--target=-linux-android` to the command line arguments as well, but clang seems to deduplicate them (or look at the latter `--target` which contains our version). Note that this effectively reverts https://github.com/rust-mobile/xbuild/pull/127/commits/32efed6 because we must now always pass the SDK level via the triple again, even if the host also happens to be Android with the same architecture. --- xbuild/src/cargo/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xbuild/src/cargo/mod.rs b/xbuild/src/cargo/mod.rs index 910f0bb..233252a 100644 --- a/xbuild/src/cargo/mod.rs +++ b/xbuild/src/cargo/mod.rs @@ -307,11 +307,14 @@ impl CargoBuild { pub fn use_android_ndk(&mut self, path: &Path, target_sdk_version: u32) -> Result<()> { let path = dunce::canonicalize(path)?; let ndk_triple = self.target.ndk_triple(); + assert_eq!(Some(ndk_triple), self.triple); + let ndk_versioned_triple = format!("{ndk_triple}{target_sdk_version}"); self.cfg_tool(Tool::Cc, "clang"); self.cfg_tool(Tool::Cxx, "clang++"); self.cfg_tool(Tool::Ar, "llvm-ar"); self.cfg_tool(Tool::Linker, "clang"); self.set_sysroot(&path); + self.add_cflag(&format!("--target={ndk_versioned_triple}")); self.add_cxxflag("-stdlib=libc++"); let lib_dir = path.join("usr").join("lib").join(ndk_triple); let sdk_lib_dir = lib_dir.join(target_sdk_version.to_string()); @@ -321,9 +324,7 @@ impl CargoBuild { target_sdk_version ); self.use_ld("lld"); - if let Some(triple) = self.triple { - self.add_link_arg(&format!("--target={}", triple)); - } + self.add_link_arg(&format!("--target={ndk_versioned_triple}")); self.add_link_arg(&format!("-B{}", sdk_lib_dir.display())); self.add_link_arg(&format!("-L{}", sdk_lib_dir.display())); self.add_link_arg(&format!("-L{}", lib_dir.display())); From 2df97d7297eb8a0bef3cce2b2400b08b683eb4bf Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Thu, 9 Jan 2025 14:09:05 +0100 Subject: [PATCH 3/3] CI: Drop broken template building We don't use the template and its `wry` feature in this fork. Remove it now that `ubuntu-latest` no longer has the necessary packages which requires a tedious and complicated upgrade of the `wry` "nonsense". This is attempted upstream at: https://togithub.com/rust-mobile/xbuild/pull/210 --- .github/workflows/ci.yml | 71 ---------------------------------------- 1 file changed, 71 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7651701..7013836 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,74 +31,3 @@ jobs: with: name: ${{ matrix.host }}-x path: bin/x${{ matrix.host == 'windows-latest' && '.exe' || '' }} - - build-template: - strategy: - fail-fast: false - matrix: - host: - - ubuntu-latest - - macos-latest - - windows-latest - opt: - - debug - - release - target: - - platform: linux - arch: x64 - - platform: macos - arch: x64 - - platform: windows - arch: x64 - - platform: android - arch: arm64 - - platform: ios - arch: arm64 - - runs-on: ${{ matrix.host }} - needs: build - steps: - - name: install rust - uses: hecrj/setup-rust-action@v1 - with: - rust-version: stable - - - name: install x - uses: actions/download-artifact@v3 - with: - name: ${{ matrix.host }}-x - - run: chmod +x ./x - if: ${{ matrix.host == 'ubuntu-latest' || matrix.host == 'macos-latest' }} - - - name: install llvm ubuntu - if: ${{ matrix.host == 'ubuntu-latest' }} - run: sudo apt-get update && sudo apt-get install llvm - - - name: install llvm macos - if: ${{ matrix.host == 'macos-latest' }} - run: | - brew install llvm - echo "/usr/local/opt/llvm/bin" >> $GITHUB_PATH - - - name: install java - uses: actions/setup-java@v2 - with: - distribution: temurin - java-version: 11 - - - name: install linux dependencies - if: ${{ matrix.host == 'ubuntu-latest' }} - run: sudo apt-get update && sudo apt-get install libwebkit2gtk-4.0-dev libgtk-3-dev squashfs-tools - - - name: create project - run: ./x new template - - # only linux can target linux as it is not clear what that even is exactly - # glibc/musl gtk/qt x11/wayland - # windows doesn't support posix symlinks so can't cross compile to macos/ios - - name: build project - if: > - !(matrix.host == 'macos-latest' && matrix.target.platform == 'linux' || - matrix.host == 'windows-latest' && contains(fromJson('["linux", "macos", "ios"]'), matrix.target.platform)) - run: ../x build --platform ${{ matrix.target.platform }} --arch ${{ matrix.target.arch }} --${{ matrix.opt }} - working-directory: template