Skip to content

Commit

Permalink
refactor: update target structure for iOS and Android binaries (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
thewh1teagle authored Jan 1, 2025
1 parent 695ef3a commit 2668320
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
11 changes: 6 additions & 5 deletions crates/sherpa-rs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ lazy_static::lazy_static! {
static ref RUST_CLANG_TARGET_MAP: HashMap<String, String> = {
let mut m = HashMap::new();
m.insert("aarch64-linux-android".to_string(), "armv8-linux-androideabi".to_string());
m.insert("aarch64-apple-ios-sim".to_string(), "arm64-apple-ios-sim".to_string());
m.insert("aarch64-apple-ios-sim".to_string(), "arm64-apple-ios-simulator".to_string());
m
};
}
Expand Down Expand Up @@ -338,14 +338,15 @@ fn main() {
debug_log!("Cache dir: {}", cache_dir.display());

let lib_dir = cache_dir.join(&dist.name);

// if is mobile then check if cache dir not empty
// Sherpa uses special directory structure for mobile
let cache_dir_empty = cache_dir
.read_dir()
.map(|mut entries| entries.next().is_none())
.unwrap_or(true);
// Check if cache directory exists
// Sherpa uses special directory structure for mobile
if (!lib_dir.exists() && !is_mobile) || (is_mobile && cache_dir_empty) {

if (is_mobile && cache_dir_empty) || (!is_mobile && !lib_dir.exists()) {
let downloaded_file = fetch_file(&dist.url);
let hash = sha256(&downloaded_file);
// verify checksum
Expand Down Expand Up @@ -377,7 +378,7 @@ fn main() {

sherpa_libs = libs
.iter()
.map(|p| download_binaries::extract_lib_name(p))
.map(download_binaries::extract_lib_name)
.collect();
} else {
sherpa_libs = extract_lib_names(&lib_dir, is_dynamic, &target_os);
Expand Down
45 changes: 28 additions & 17 deletions crates/sherpa-rs-sys/dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,38 @@
"android": {
"archive": "sherpa-onnx-{tag}-android.tar.bz2",
"is_dynamic": true,
"arch": {
"aarch64-linux-android": "arm64-v8a",
"x86_64-linux-android": "x86_64",
"armv7-linux-androideabi": "armeabi-v7a"
},
"libs": [
"jniLibs/{arch}/libsherpa-onnx-c-api.so",
"jniLibs/{arch}/libonnxruntime.so"
]
"targets": {
"aarch64-linux-android": [
"jniLibs/arm64-v8a/libsherpa-onnx-c-api.so",
"jniLibs/arm64-v8a/libonnxruntime.so"
],
"x86_64-linux-android": [
"jniLibs/x86_64/libsherpa-onnx-c-api.so",
"jniLibs/x86_64/libonnxruntime.so"
],
"armv7-linux-androideabi": [
"jniLibs/armeabi-v7a/libsherpa-onnx-c-api.so",
"jniLibs/armeabi-v7a/libonnxruntime.so"
]
}
},
"ios": {
"archive": "sherpa-onnx-{tag}-ios.tar.bz2",
"is_dynamic": false,
"arch": {
"aarch64-apple-ios": "ios-arm64",
"aarch64-apple-ios-sim": "ios-arm64-simulator"
},
"libs": [
"build-ios/ios-onnxruntime/onnxruntime.xcframework/{arch}/libonnxruntime.a",
"build-ios/sherpa-onnx.xcframework/{arch}/libsherpa-onnx.a"
]
"targets": {
"aarch64-apple-ios": [
"build-ios/ios-onnxruntime/1.17.1/onnxruntime.xcframework/ios-arm64/libonnxruntime.a",
"build-ios/sherpa-onnx.xcframework/ios-arm64/libsherpa-onnx.a"
],
"aarch64-apple-ios-sim": [
"build-ios/ios-onnxruntime/1.17.1/onnxruntime.xcframework/ios-arm64_x86_64-simulator/libonnxruntime.a",
"build-ios/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/libsherpa-onnx.a"
],
"x86_64-apple-ios": [
"build-ios/ios-onnxruntime/1.17.1/onnxruntime.xcframework/ios-arm64_x86_64-simulator/libonnxruntime.a",
"build-ios/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/libsherpa-onnx.a"
]
}
}
}
}
16 changes: 2 additions & 14 deletions crates/sherpa-rs-sys/src/download_binaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,24 +164,12 @@ impl DistTable {
let name = archive.replace(".tar.bz2", "");
let name = name.replace(".tar.gz", "");

let mut libs: Option<Vec<String>> = target_dist.get("libs").map(|libs| {
libs.as_array()
.unwrap()
.iter()
let libs: Option<Vec<String>> = target_dist["targets"][target].as_array().map(|libs| {
libs.iter()
.map(|lib| lib.as_str().unwrap().to_string())
.collect()
});

// Replace {arch} in libs
let dist_arch = target_dist["arch"][target].as_str().map(|s| s.to_string());
if let Some(libs) = libs.as_mut() {
if let Some(arch) = dist_arch {
libs.iter_mut().for_each(|lib| {
*lib = lib.replace("{arch}", &arch);
});
}
}

let url = self.url.replace("{archive}", archive);
let checksum = DIST_CHECKSUM.get(archive).unwrap();

Expand Down

0 comments on commit 2668320

Please sign in to comment.