Skip to content
Open
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
14 changes: 14 additions & 0 deletions cargo-tai/src/opts/library.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::path::PathBuf;

use clap::Parser;

#[derive(Parser, Debug)]
pub struct LibraryOptions {
/// Libraries to include in the app that the built units link to. Format: `local_path`
///
/// Example:
///
/// `cargo-tai test -l ./openssl-1.1.1s/libssl.so.1.1
#[clap(short, long)]
pub libraries: Option<Vec<PathBuf>>,
}
6 changes: 6 additions & 0 deletions cargo-tai/src/opts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod binary;
pub mod cli;
pub mod compiler;
pub mod ios;
pub mod library;
pub mod resource;

use self::{
Expand All @@ -17,6 +18,7 @@ use self::{
cli::CliOptions,
compiler::CompilerOptions,
ios::IosOptions,
library::LibraryOptions,
resource::ResourceOptions,
};

Expand All @@ -40,6 +42,9 @@ pub struct LocalRun {
#[structopt(flatten)]
compiler: CompilerOptions,

#[structopt(flatten)]
libraries: LibraryOptions,

#[structopt(flatten)]
resources: ResourceOptions,

Expand Down Expand Up @@ -68,6 +73,7 @@ fn from_local_run(command: Command, options: LocalRun) -> opts::Options {
opts::Options {
command,
compiler: options.compiler.into(),
libraries: options.libraries.libraries,
resources: options.resources.resources,
binary: options.binary.into(),
android: options.android.into(),
Expand Down
7 changes: 6 additions & 1 deletion tai-lib/src/android/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tracing::{debug, instrument};

use crate::{
common::{
bundle::{copy_resources, BuiltBundle},
bundle::{copy_libraries, copy_resources, BuiltBundle},
compiler::BuiltUnit,
},
TaiResult,
Expand All @@ -17,6 +17,7 @@ use crate::{
pub fn create_bundle<P: AsRef<Path>>(
unit: BuiltUnit,
bundles_root: P,
libraries: &Option<Vec<PathBuf>>,
resources: &Option<Vec<(String, PathBuf)>>,
) -> TaiResult<BuiltBundle> {
let bundle_root = bundles_root
Expand All @@ -34,6 +35,10 @@ pub fn create_bundle<P: AsRef<Path>>(
copy(&unit.artifact, &to)?;
debug!("copy {} to {}", &unit.artifact.display(), to.display());

if let Some(libraries) = libraries {
copy_libraries(&bundle_root, libraries)?;
}

if let Some(resources) = resources {
copy_resources(&bundle_root, resources)?;
}
Expand Down
6 changes: 4 additions & 2 deletions tai-lib/src/android/task/create_bundles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ pub struct CreateBundles;
impl Task<Context> for CreateBundles {
fn run(&self, mut context: Context) -> TaiResult<Context> {
let built_units = context.remove::<BuiltUnits>().0;
let resources = &context.get::<Options>().resources;
let options = &context.get::<Options>();
let libraries = &options.libraries;
let resources = &options.resources;
let project_meta: &ProjectMetadata = context.get();

let bundles = create_bundles(built_units, &project_meta.tai_target, |unit, root| {
create_bundle(unit, root, resources)
create_bundle(unit, root, libraries, resources)
})?;

context.insert(bundles);
Expand Down
36 changes: 35 additions & 1 deletion tai-lib/src/common/bundle/bundles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
path::{Path, PathBuf},
};

use anyhow::{Context, Error};
use anyhow::{anyhow, Context, Error};
use tracing::debug;

use crate::{common::compiler::BuiltUnit, TaiResult};
Expand All @@ -23,6 +23,40 @@ pub fn create_bundles(
Ok(BuiltBundles { bundles })
}

pub fn copy_libraries<P: AsRef<Path>>(
dest_dir: P,
libraries: &[PathBuf]
) -> TaiResult<()> {
debug!("copy libraries");

let lib_root = dest_dir.as_ref().join(tai_util::LIB_DIR_NAME);
create_dir_all(&lib_root).with_context(|| {
format!(
"Failed to create library root {}",
lib_root.display()
)
})?;
debug!("create dir: {}", lib_root.display());

let copied: TaiResult<Vec<()>> = libraries
.iter()
.map(|local_path| {
let file_name =
local_path
.file_name()
.ok_or_else(|| anyhow!("Cannot get file name for {}", local_path.display()))?;
let remote_path = lib_root.join(file_name);
copy(local_path, &remote_path)
.with_context(|| format!("Failed to copy library {}", local_path.display()))?;
debug!("copy {} to {}", local_path.display(), remote_path.display());
Ok(())
})
.collect();
copied?;

Ok(())
}

pub fn copy_resources<P: AsRef<Path>>(
dest_dir: P,
resources: &[(String, PathBuf)],
Expand Down
2 changes: 1 addition & 1 deletion tai-lib/src/common/bundle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::common::compiler::BuiltUnit;

mod bundles;

pub use bundles::{copy_resources, create_bundles};
pub use bundles::{copy_libraries, copy_resources, create_bundles};

#[derive(Debug)]
pub struct BuiltBundles {
Expand Down
1 change: 1 addition & 0 deletions tai-lib/src/common/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use super::command::Command;
pub struct Options {
pub command: Command,
pub compiler: CompilerOptions,
pub libraries: Option<Vec<PathBuf>>,
pub resources: Option<Vec<(String, PathBuf)>>,
pub binary: Option<BinaryOptions>,
pub android: Option<AndroidOptions>,
Expand Down
1 change: 1 addition & 0 deletions tai-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{env, path::PathBuf};

// cannot use resources https://stackoverflow.com/questions/29271548/code-sign-error-bundle-format-unrecognized-invalid-or-unsuitable
pub const DATA_DIR_NAME: &str = "test-data";
pub const LIB_DIR_NAME: &str = "lib";

pub fn resources_file_path(test_data_id: &str) -> PathBuf {
try_resources_file_path(test_data_id)
Expand Down