Skip to content

Commit

Permalink
fix: 🐛 Fix client build, add client_openxr lib xtask command
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Apr 12, 2024
1 parent 88b6073 commit 6757867
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion alvr/client_openxr/src/c_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(target_os = "android")]
#[no_mangle]
pub extern "C" fn alvr_entry_point(java_vm: *mut std::ffi::c_void, context: *mut std::ffi::c_void) {
ndk_context::initialize_android_context(java_vm, context);
unsafe { ndk_context::initialize_android_context(java_vm, context) };

crate::entry_point();
}
47 changes: 33 additions & 14 deletions alvr/xtask/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,41 +297,60 @@ pub fn build_launcher(profile: Profile, enable_messagebox: bool, reproducible: b
.unwrap();
}

pub fn build_client_lib(profile: Profile, link_stdcpp: bool) {
fn build_android_lib_impl(dir_name: &str, profile: Profile, link_stdcpp: bool) {
let sh = Shell::new().unwrap();

let strip_flag = matches!(profile, Profile::Debug).then_some("--no-strip");

let mut flags = vec![];
let ndk_flags = &[
"-t",
"arm64-v8a",
"-t",
"armeabi-v7a",
"-t",
"x86_64",
"-t",
"x86",
"-p",
"26",
"--no-strip",
];

let mut rust_flags = vec![];
match profile {
Profile::Distribution => {
flags.push("--profile");
flags.push("distribution")
rust_flags.push("--profile");
rust_flags.push("distribution")
}
Profile::Release => flags.push("--release"),
Profile::Release => rust_flags.push("--release"),
Profile::Debug => (),
}
if !link_stdcpp {
flags.push("--no-default-features");
rust_flags.push("--no-default-features");
}
let flags_ref = &flags;
let rust_flags_ref = &rust_flags;

let build_dir = afs::build_dir().join("alvr_client_core");
let build_dir = afs::build_dir().join(format!("alvr_{dir_name}"));
sh.create_dir(&build_dir).unwrap();

let _push_guard = sh.push_dir(afs::crate_dir("client_core"));

let _push_guard = sh.push_dir(afs::crate_dir(dir_name));
cmd!(
sh,
"cargo ndk -t arm64-v8a -t armeabi-v7a -t x86_64 -t x86 -p 26 {strip_flag...} -o {build_dir} build {flags_ref...}"
"cargo ndk {ndk_flags...} -o {build_dir} build {rust_flags_ref...}"
)
.run()
.unwrap();

let out = build_dir.join("alvr_client_core.h");
let out = build_dir.join(format!("alvr_{dir_name}.h"));
cmd!(sh, "cbindgen --output {out}").run().unwrap();
}

pub fn build_android_client_core_lib(profile: Profile, link_stdcpp: bool) {
build_android_lib_impl("client_core", profile, link_stdcpp)
}

pub fn build_android_client_openxr_lib(profile: Profile, link_stdcpp: bool) {
build_android_lib_impl("client_openxr", profile, link_stdcpp)
}

pub fn build_android_client(profile: Profile) {
let sh = Shell::new().unwrap();

Expand Down
6 changes: 5 additions & 1 deletion alvr/xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ SUBCOMMANDS:
build-server-lib Build a C-ABI ALVR server library and header
build-client Build client, then copy binaries to build folder
build-client-lib Build a C-ABI ALVR client library and header
build-client-xr-lib Build a C-ABI ALVR OpenXR entry point client library and header
run-streamer Build streamer and then open the dashboard
run-launcher Build launcher and then open it
package-streamer Build streamer with distribution profile, make archive
Expand Down Expand Up @@ -195,7 +196,10 @@ fn main() {
"build-launcher" => build::build_launcher(profile, true, false),
"build-server-lib" => build::build_server_lib(profile, true, gpl, None, false),
"build-client" => build::build_android_client(profile),
"build-client-lib" => build::build_client_lib(profile, link_stdcpp),
"build-client-lib" => build::build_android_client_core_lib(profile, link_stdcpp),
"build-client-xr-lib" => {
build::build_android_client_openxr_lib(profile, link_stdcpp)
}
"run-streamer" => {
if !no_rebuild {
build::build_streamer(
Expand Down
2 changes: 1 addition & 1 deletion alvr/xtask/src/packaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub fn package_launcher(appimage: bool) {
pub fn package_client_lib(link_stdcpp: bool) {
let sh = Shell::new().unwrap();

build::build_client_lib(Profile::Distribution, link_stdcpp);
build::build_android_client_core_lib(Profile::Distribution, link_stdcpp);

command::zip(&sh, &afs::build_dir().join("alvr_client_core")).unwrap();
}

0 comments on commit 6757867

Please sign in to comment.