Skip to content

Commit

Permalink
compile on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
rfuzzo committed Dec 16, 2023
1 parent 5b9618c commit 5e971c7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cmake::Config;
use std::{fs::File, path::PathBuf};
use std::{env, fs::File, path::PathBuf};

// print build script logs
macro_rules! p {
Expand All @@ -12,34 +12,43 @@ const LIB_NAME: &str = "kraken";
const TARGET_NAME: &str = "kraken_static";

fn main() {
// cmake config
let mut cfg = Config::new(LIB_NAME);
//cfg.profile("RelWithDebInfo");
//cfg.profile("Debug");
let dst = cfg.build_target(TARGET_NAME).build();

// logging
let cmake_profile: String = cfg.get_profile().to_owned();
let rust_profile = std::env::var("PROFILE").unwrap();
p!("CMAKE_PROFILE : {}", cmake_profile);
p!("RUST_PROFILE : {}", rust_profile);
p!("DST: {}", dst.display());

// link
let mut link_path = format!("{}/build/bin/CMake", dst.display());
let mut additional_args = "".to_owned();
if cfg!(windows) {
link_path = format!("{}/{}", link_path, cmake_profile);
} else if cfg!(unix) {
additional_args = "-l".to_owned();
}
let os = env::consts::OS;

if os == "linux" {
let link_path = std::env::current_dir().unwrap().join("lib").join(os);
// link rustc
println!("cargo:rustc-link-search=native={}", link_path.display());
println!("cargo:rustc-link-lib-l=static={}", TARGET_NAME);
} else {
// cmake config
let mut cfg = Config::new(LIB_NAME);
//cfg.profile("RelWithDebInfo");
//cfg.profile("Debug");
let dst = cfg.build_target(TARGET_NAME).build();

// link rustc
println!("cargo:rustc-link-search=native={}", link_path);
println!(
"cargo:rustc-link-lib{}=static={}",
additional_args, TARGET_NAME
);
// logging
let cmake_profile: String = cfg.get_profile().to_owned();
let rust_profile = std::env::var("PROFILE").unwrap();
p!("CMAKE_PROFILE : {}", cmake_profile);
p!("RUST_PROFILE : {}", rust_profile);
p!("DST: {}", dst.display());

// link
let mut link_path = format!("{}/build/bin/CMake", dst.display());
let mut additional_args = "".to_owned();
if cfg!(windows) {
link_path = format!("{}/{}", link_path, cmake_profile);
} else if cfg!(unix) {
additional_args = "-l".to_owned();
}

// link rustc
println!("cargo:rustc-link-search=native={}", link_path);
println!(
"cargo:rustc-link-lib{}=static={}",
additional_args, TARGET_NAME
);
}

// extract resources
let file_path = PathBuf::from("src/metadata-resources.csv");
Expand Down
Binary file added lib/libkraken_static.a
Binary file not shown.

0 comments on commit 5e971c7

Please sign in to comment.