Skip to content

Commit

Permalink
Switch out two submodules for one (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliddell authored Jan 6, 2024
1 parent a622f2d commit e322ae9
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 63 deletions.
10 changes: 3 additions & 7 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
[submodule "acquire-video-runtime"]
path = acquire-libs/acquire-video-runtime
url = ../acquire-video-runtime.git
branch = main
[submodule "acquire-libs/acquire-core-libs"]
path = acquire-libs/acquire-core-libs
url = ../acquire-core-libs.git
[submodule "acquire-common"]
path = acquire-common
url = [email protected]:aliddell/acquire-common.git
1 change: 1 addition & 0 deletions acquire-common
Submodule acquire-common added at ba689e
11 changes: 0 additions & 11 deletions acquire-libs/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion acquire-libs/acquire-core-libs
Submodule acquire-core-libs deleted from f2dd74
1 change: 0 additions & 1 deletion acquire-libs/acquire-video-runtime
Submodule acquire-video-runtime deleted from ba0fdc
85 changes: 43 additions & 42 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ use std::fs;
#[derive(Deserialize)]
#[serde(rename_all = "kebab-case")]
struct DriverManifest {
acquire_driver_common: String,
acquire_driver_zarr: String,
acquire_driver_egrabber: String,
acquire_driver_hdcam: String,
acquire_driver_spinnaker: String,
}

fn main() {
let dst = cmake::Config::new("acquire-libs")
.target("acquire-video-runtime")
let drivers_json =
fs::read_to_string("drivers.json").expect("Failed to read from drivers.json.");
let tags: DriverManifest =
serde_json::from_str(drivers_json.as_str()).expect("Failed to parse drivers.json");

let dst = cmake::Config::new("acquire-common")
.target("acquire-common")
.profile("RelWithDebInfo")
.static_crt(true)
.define("NOTEST", "TRUE")
Expand All @@ -24,39 +28,6 @@ fn main() {
.define("CMAKE_OSX_ARCHITECTURES", "x86_64;arm64")
.build();

let drivers_json =
fs::read_to_string("drivers.json").expect("Failed to read from drivers.json.");
let tags: DriverManifest =
serde_json::from_str(drivers_json.as_str()).expect("Failed to parse drivers.json");

let drivers_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()).join("drivers");

fetch_acquire_driver(
&drivers_dir,
"acquire-driver-common",
tags.acquire_driver_common.as_str(),
);
fetch_acquire_driver(
&drivers_dir,
"acquire-driver-zarr",
tags.acquire_driver_zarr.as_str(),
);
fetch_acquire_driver(
&drivers_dir,
"acquire-driver-egrabber",
tags.acquire_driver_egrabber.as_str(),
);
fetch_acquire_driver(
&drivers_dir,
"acquire-driver-hdcam",
tags.acquire_driver_hdcam.as_str(),
);
fetch_acquire_driver(
&drivers_dir,
"acquire-driver-spinnaker",
tags.acquire_driver_spinnaker.as_str(),
);

println!("cargo:rustc-link-search=native={}/lib", dst.display());
println!("cargo:rustc-link-lib=static=acquire-video-runtime");
println!("cargo:rustc-link-lib=static=acquire-device-properties");
Expand All @@ -80,9 +51,36 @@ fn main() {
bindings
.write_to_file(dst.join("bindings.rs"))
.expect("Failed to write bindings.");

// copy acquire-driver-common
copy_shared_lib(&dst, "acquire-driver-common");

// download and copy driver artifacts
let drivers_dir = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()).join("drivers");

fetch_acquire_driver(
&drivers_dir,
"acquire-driver-zarr",
tags.acquire_driver_zarr.as_str(),
);
fetch_acquire_driver(
&drivers_dir,
"acquire-driver-egrabber",
tags.acquire_driver_egrabber.as_str(),
);
fetch_acquire_driver(
&drivers_dir,
"acquire-driver-hdcam",
tags.acquire_driver_hdcam.as_str(),
);
fetch_acquire_driver(
&drivers_dir,
"acquire-driver-spinnaker",
tags.acquire_driver_spinnaker.as_str(),
);
}

fn fetch_acquire_driver(dst: &std::path::PathBuf, name: &str, tag: &str) {
fn fetch_artifact(dst: &std::path::PathBuf, name: &str, tag: &str) {
let build = if cfg!(target_os = "windows") {
"win64"
} else if cfg!(target_os = "macos") {
Expand Down Expand Up @@ -121,11 +119,14 @@ fn fetch_acquire_driver(dst: &std::path::PathBuf, name: &str, tag: &str) {
zip_extract::extract(std::io::Cursor::new(archive), &dst, true).expect(&*format!(
"Failed to extract {name}-{tag}-{build}.zip from response."
));
}

copy_acquire_driver(&dst, name);
fn fetch_acquire_driver(dst: &std::path::PathBuf, name: &str, tag: &str) {
fetch_artifact(dst, name, tag);
copy_shared_lib(dst, name);
}

fn copy_acquire_driver(dst: &std::path::PathBuf, name: &str) {
fn copy_shared_lib(src: &std::path::PathBuf, name: &str) {
let (prefix, postfix) = if cfg!(target_os = "windows") {
("", ".dll")
} else if cfg!(target_os = "macos") {
Expand All @@ -138,12 +139,12 @@ fn copy_acquire_driver(dst: &std::path::PathBuf, name: &str) {

let lib = format!("{prefix}{name}{postfix}");

std::fs::copy(
format!("{}/lib/{lib}", dst.display()),
fs::copy(
format!("{}/lib/{lib}", src.display()),
format!("python/acquire/{lib}"),
)
.expect(&format!(
"Failed to copy {}/lib/{lib} to python folder.",
dst.display()
src.display()
));
}
1 change: 0 additions & 1 deletion drivers.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"acquire-driver-common": "0.1.6",
"acquire-driver-zarr": "0.1.8",
"acquire-driver-egrabber": "0.1.5",
"acquire-driver-hdcam": "0.1.7",
Expand Down

0 comments on commit e322ae9

Please sign in to comment.