Skip to content
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
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
rustup target add aarch64-linux-android x86_64-linux-android
- name: Install Crossbundle
run: |
rustup upgrade
cargo install --path=./crossbundle/cli
- name: Build APK
run: |
Expand Down
50 changes: 20 additions & 30 deletions crossbundle/cli/src/commands/build/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use android_manifest::AndroidManifest;
use android_tools::java_tools::{AabKey, JarSigner};
use clap::Parser;
use crossbundle_tools::{
commands::android::{self, compile_rust_for_android},
commands::android::{self, rust_compile},
tools::*,
types::*,
utils::Config,
Expand Down Expand Up @@ -372,37 +372,27 @@ impl AndroidBuildCommand {
for build_target in build_targets {
let lib_name = format!("lib{}.so", package_name.replace("-", "_"));
let rust_triple = build_target.rust_triple();

config.status_message("Compiling for architecture", rust_triple)?;
let app_wrapper = match self.shared.quad {
true => ApplicationWrapper::Sokol,
false => ApplicationWrapper::NdkGlue,
};

// Compile rust code for android depending on application wrapper
rust_compile(
&ndk,
build_target,
&project_path,
profile,
self.shared.features.clone(),
self.shared.all_features,
self.shared.no_default_features,
target_sdk_version,
&lib_name,
app_wrapper,
)?;

// We need a different compilation process for macroquad projects
// because of the sokol lib dependency
if self.shared.quad {
compile_rust_for_android(
&ndk,
build_target,
&project_path,
profile,
self.shared.features.clone(),
self.shared.all_features,
self.shared.no_default_features,
target_sdk_version,
&lib_name,
ApplicationWrapper::Sokol,
)?;
} else {
compile_rust_for_android(
&ndk,
build_target,
&project_path,
profile,
self.shared.features.clone(),
self.shared.all_features,
self.shared.no_default_features,
target_sdk_version,
&lib_name,
ApplicationWrapper::NdkGlue,
)?;
}
let out_dir = target_dir.join(build_target.rust_triple()).join(&profile);
let compiled_lib = out_dir.join(lib_name);
libs.push((compiled_lib, build_target));
Expand Down
6 changes: 0 additions & 6 deletions crossbundle/cli/src/commands/install/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ const OS_TAG: &str = "mac";
#[cfg(target_os = "linux")]
const OS_TAG: &str = "linux";

#[cfg(target_os = "windows")]
pub const EXECUTABLE_SUFFIX_BAT: &str = ".bat";

#[cfg(not(target_os = "windows"))]
pub const EXECUTABLE_SUFFIX_BAT: &str = "";

const COMMAND_LINE_TOOLS_DOWNLOAD_URL: &'static str = "https://dl.google.com/android/repository/";
const BUNDLETOOL_JAR_FILE_DOWNLOAD_URL: &'static str =
"https://github.com/google/bundletool/releases/download";
Expand Down
7 changes: 4 additions & 3 deletions crossbundle/cli/src/commands/install/sdkmanager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use clap::Parser;
use crossbundle_tools::{error::CommandExt, tools::AndroidSdk, utils::Config};
use crossbundle_tools::{
error::CommandExt, tools::AndroidSdk, utils::Config, EXECUTABLE_SUFFIX_BAT,
};

#[derive(Parser, Clone, Debug, Default)]
pub struct SdkManagerInstallCommand {
Expand Down Expand Up @@ -156,8 +158,7 @@ impl SdkManagerInstallCommand {
pub fn run(&self, _config: &Config) -> crate::error::Result<()> {
let sdk_root = AndroidSdk::sdk_install_path()?;
let sdkmanager_path = sdk_root.join("cmdline-tools").join("bin");
let sdkmanager_bat =
sdkmanager_path.join(format!("sdkmanager{}", super::EXECUTABLE_SUFFIX_BAT));
let sdkmanager_bat = sdkmanager_path.join(format!("sdkmanager{}", EXECUTABLE_SUFFIX_BAT));

let mut sdkmanager = std::process::Command::new(sdkmanager_bat);
if let Some(sdk_root) = &self.sdk_root {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn add_libs_into_aapt2(
recursively_define_needed_libs(
(lib_name, lib_path.to_owned()),
&ndk.toolchain_bin("readelf", build_target)?,
&ndk.sysroot_lib_dir(build_target)?.join("libc++_shared.so"),
&ndk.sysroot_lib_dir(&build_target)?.join("libc++_shared.so"),
&system_libs,
&dylibs_paths,
&mut needed_libs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn add_libs_into_apk(
recursively_define_needed_libs(
(lib_name, lib_path.to_owned()),
&ndk.toolchain_bin("readelf", build_target)?,
&ndk.sysroot_lib_dir(build_target)?.join("libc++_shared.so"),
&ndk.sysroot_lib_dir(&build_target)?.join("libc++_shared.so"),
&system_libs,
&dylibs_paths,
&mut needed_libs,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// Change crate-type from bin to cdylib. Replace output directory with the directory we
/// created
pub fn change_crate_name(
build_target_dir: &std::path::Path,
cmd: &cargo_util::ProcessBuilder,
change_out_dir: bool,
from: &str,
to: &str,
) -> cargo::CargoResult<Vec<std::ffi::OsString>> {
let mut new_args = cmd.get_args().to_owned();
let mut iter = new_args.iter_mut().rev().peekable();
while let Some(arg) = iter.next() {
if let Some(prev_arg) = iter.peek() {
if *prev_arg == "--crate-type" && arg == from {
*arg = to.into();
} else if *prev_arg == "--out-dir" && change_out_dir {
*arg = build_target_dir.into();
}
}
}
Ok(new_args)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use crate::types::*;
use std::io::Write;

/// Sets needed environment variables
pub fn set_cmake_vars(
build_target: crate::types::AndroidTarget,
ndk: &crate::tools::AndroidNdk,
target_sdk_version: u32,
build_target_dir: &std::path::Path,
) -> cargo::CargoResult<()> {
// Return path to toolchain cmake file
let cmake_toolchain_path = write_cmake_toolchain(
target_sdk_version,
ndk.ndk_path(),
build_target_dir,
build_target,
)?;

// Set cmake environment variables
std::env::set_var("CMAKE_TOOLCHAIN_FILE", cmake_toolchain_path);
std::env::set_var("CMAKE_GENERATOR", r#"Unix Makefiles"#);
std::env::set_var("CMAKE_MAKE_PROGRAM", make_path(ndk.ndk_path()));
Ok(())
}

/// Returns path to NDK provided make
pub fn make_path(ndk_path: &std::path::Path) -> std::path::PathBuf {
ndk_path
.join("prebuild")
.join(super::consts::HOST_TAG)
.join("make")
}

/// Write a CMake toolchain which will remove references to the rustc build target before
/// including the NDK provided toolchain. The NDK provided android toolchain will set the
/// target appropriately Returns the path to the generated toolchain file
pub fn write_cmake_toolchain(
min_sdk_version: u32,
ndk_path: &std::path::Path,
build_target_dir: &std::path::Path,
build_target: crate::types::AndroidTarget,
) -> cargo::util::CargoResult<std::path::PathBuf> {
let toolchain_path = build_target_dir.join("cargo-apk.toolchain.cmake");
let mut toolchain_file = std::fs::File::create(&toolchain_path).unwrap();
writeln!(
toolchain_file,
r#"set(ANDROID_PLATFORM android-{min_sdk_version})
set(ANDROID_ABI {abi})
string(REPLACE "--target={build_target}" "" CMAKE_C_FLAGS "${{CMAKE_C_FLAGS}}")
string(REPLACE "--target={build_target}" "" CMAKE_CXX_FLAGS "${{CMAKE_CXX_FLAGS}}")
unset(CMAKE_C_COMPILER CACHE)
unset(CMAKE_CXX_COMPILER CACHE)
include("{ndk_path}/build/cmake/android.toolchain.cmake")"#,
min_sdk_version = min_sdk_version,
ndk_path = dunce::simplified(ndk_path).to_string_lossy(),
build_target = build_target.rust_triple(),
abi = build_target.android_abi(),
)?;
Ok(toolchain_path)
}
176 changes: 0 additions & 176 deletions crossbundle/tools/src/commands/android/rust_compile/compile_bevy.rs

This file was deleted.

Loading