Skip to content

Commit e4b6aee

Browse files
committed
Support prebuilt binaries for MacOS on arm64
1 parent f13becf commit e4b6aee

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

tensorflow-sys/build.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,15 @@ fn main() {
6464
Ok(s) => s == "true",
6565
Err(_) => false,
6666
};
67+
log_var!(force_src);
6768

68-
let target_os = target_os();
69-
if !force_src
70-
&& target_arch() == "x86_64"
71-
&& (target_os == "linux" || target_os == "macos" || target_os == "windows")
72-
{
69+
let prebuilt_supported = match (&target_arch() as &str, &target_os() as &str) {
70+
("x86_64", "linux") => true,
71+
("x86_64", "windows") => true,
72+
("aarch64", "macos") => true,
73+
_ => false,
74+
};
75+
if !force_src && prebuilt_supported {
7376
install_prebuilt();
7477
} else {
7578
build_from_src();
@@ -185,11 +188,17 @@ fn extract<P: AsRef<Path>, P2: AsRef<Path>>(archive_path: P, extract_to: P2) {
185188

186189
// Downloads and unpacks a prebuilt binary. Only works for certain platforms.
187190
fn install_prebuilt() {
191+
log!("Installing prebuilt");
188192
// Figure out the file names.
189193
let os = match &target_os() as &str {
190194
"macos" => "darwin".to_string(),
191195
x => x.to_string(),
192196
};
197+
let arch = match &target_arch() as &str {
198+
"aarch64" => "arm64",
199+
x => x,
200+
}
201+
.to_string();
193202
let proc_type = if cfg!(feature = "tensorflow_gpu") {
194203
"gpu"
195204
} else {
@@ -199,11 +208,7 @@ fn install_prebuilt() {
199208
let ext = if windows { ".zip" } else { ".tar.gz" };
200209
let binary_url = format!(
201210
"https://storage.googleapis.com/tensorflow/versions/{}/libtensorflow-{}-{}-{}{}",
202-
VERSION,
203-
proc_type,
204-
os,
205-
target_arch(),
206-
ext
211+
VERSION, proc_type, os, arch, ext
207212
);
208213
log_var!(binary_url);
209214
let short_file_name = binary_url.split('/').last().unwrap();
@@ -301,6 +306,7 @@ fn symlink<P: AsRef<Path>, P2: AsRef<Path>>(target: P, link: P2) {
301306
}
302307

303308
fn build_from_src() {
309+
log!("Building from source");
304310
let dll_suffix = dll_suffix();
305311
let framework_target = FRAMEWORK_TARGET.to_string() + dll_suffix;
306312
let target = TARGET.to_string() + dll_suffix;

0 commit comments

Comments
 (0)