Skip to content

Commit

Permalink
Fetching precompiled binaries from github releases
Browse files Browse the repository at this point in the history
  • Loading branch information
katyo committed Jan 7, 2020
1 parent 97dae33 commit d82ef61
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 14 deletions.
2 changes: 1 addition & 1 deletion oboe-demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ path = "../oboe"
#features = ["generate-bindings", "compile-library"]
#features = ["compile-library", "java-interface"]
#features = ["compile-library", "generate-bindings", "java-interface"]
features = ["compile-library", "java-interface"]
features = ["java-interface"]

[dependencies.apl]
git = "https://github.com/katyo/mixui"
Expand Down
4 changes: 4 additions & 0 deletions oboe-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ include = ["/src/*.rs", "/oboe-ext", "/README.md"]
[badges]
maintenance = { status = "experimental" }

[build-dependencies.fetch_unroll]
version = "0.1"
#optional = true

[build-dependencies.git2]
version = "0.11"
optional = true
Expand Down
6 changes: 6 additions & 0 deletions oboe-sys/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ lib ?= oboe
crate ?= oboe-sys
conf ?= release
link ?= shared
ver ?= 0.1.0

arch = $(firstword $(subst -, ,$(1)))
outpath = ../target/$(1)/$(conf)/build/$(crate)-*/out/$(2)
Expand All @@ -28,8 +29,13 @@ ifneq ($(call out,$(1)),)
else
@echo No prebuild outputs for target:$(1) and config:$(conf)
endif
pack-out: copy-out-$(1)
endef

pack-out:
@mkdir -p ../target/prebuilt
@tar -czf ../target/prebuilt/$(crate)_$(ver)_$(conf).tar.gz -C lib/$(conf) .

$(foreach target,$(TARGETS),$(eval $(call copy-target-rs,$(target))))

doc:
Expand Down
60 changes: 47 additions & 13 deletions oboe-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use bindgen;
#[cfg(all(feature = "compile-library", feature = "cmake"))]
use cmake;

use std::env;
#[cfg(not(feature = "compile-library"))]
use fetch_unroll::{fetch_unroll};

#[cfg(any(feature = "generate-bindings", feature = "compile-library"))]
use std::{
env,
path::{Path, PathBuf},
fs::metadata,
};
Expand All @@ -25,15 +26,54 @@ use self::LinkArg::*;

fn main() {
if !env::var("CARGO_FEATURE_RUSTDOC").is_ok() {
#[cfg(any(feature = "generate-bindings", feature = "compile-library"))]
let out_dir = PathBuf::from(
env::var("OUT_DIR").expect("OUT_DIR is set by cargo.")
);

// guess target dir
let target_dir = out_dir
.parent().unwrap()
.parent().unwrap()
.parent().unwrap()
.parent().unwrap()
.parent().unwrap();

#[cfg(not(feature = "compile-library"))]
let prebuilt_dir = {
let profile = env::var("PROFILE")
.expect("PROFILE is set by cargo.");

let prebuilt_dir = target_dir.join(&profile).join("liboboe-ext");

// TODO: check contents
if !metadata(&prebuilt_dir)
.map(|meta| meta.is_dir())
.unwrap_or(false) {
let prebuilt_url = format!(
"{repo}/releases/download/{ver}/{pkg}_{prof}.tar.gz",
repo = env::var("CARGO_PKG_REPOSITORY")
.expect("Unfortunately CARGO_PKG_REPOSITORY is not set."),
pkg = "liboboe-ext",
ver = env::var("CARGO_PKG_VERSION")
.expect("Unfortunately CARGO_PKG_VERSION is not set."),
prof = &profile,
);

fetch_unroll(&prebuilt_url, &prebuilt_dir, fetch_unroll::Config::default())
.map_err(|error| {
format!("Unable to fetch prebuilt binaries from: \"{}\" due to: {}", prebuilt_url, error)
})
.unwrap();
}

prebuilt_dir
};

#[cfg(any(feature = "generate-bindings", feature = "compile-library"))]
let oboe_src = {
let oboe_src = out_dir.join("oboe-src");
let oboe_src = target_dir.join("oboe-src");

// TODO: check contents
if !metadata(oboe_src.join(".git"))
.map(|meta| meta.is_dir())
.unwrap_or(false) {
Expand All @@ -52,7 +92,7 @@ fn main() {

// select precompiled oboe library for specified target
#[cfg(not(feature = "compile-library"))]
let link_args = select_library();
let link_args = select_library(&prebuilt_dir);

for link_arg in link_args {
match link_arg {
Expand All @@ -71,22 +111,16 @@ fn main() {
}

#[cfg(not(feature = "compile-library"))]
fn select_library() -> Vec<LinkArg> {
fn select_library(prebuilt_dir: &Path) -> Vec<LinkArg> {
let target_arch = env::var("CARGO_CFG_TARGET_ARCH")
.expect("CARGO_CFG_TARGET_ARCH is set by cargo.");

let lib_path = env::var("CARGO_MANIFEST_DIR")
.expect("CARGO_MANIFEST_DIR is set by cargo.");

let lib_arch = rustc_target(&target_arch);

let lib_conf = env::var("PROFILE")
.expect("PROFILE is set by cargo.");

let lib_name = "oboe-ext".into();

vec![
SearchPath(format!("{}/lib/{}/{}", lib_path, lib_conf, lib_arch)),
SearchPath(prebuilt_dir.join(lib_arch).display().to_string()),
if cfg!(feature = "static-link") { StaticLib(lib_name) } else { SharedLib(lib_name) },
]
}
Expand Down

0 comments on commit d82ef61

Please sign in to comment.