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

android: Set SDK/API level via version-suffxed --target triple #24

Merged
merged 3 commits into from
Jan 9, 2025
Merged
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
71 changes: 0 additions & 71 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion xbuild/src/cargo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -321,7 +324,7 @@ impl CargoBuild {
target_sdk_version
);
self.use_ld("lld");
self.add_link_arg("--target=aarch64-linux-android");
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()));
Expand Down
Loading