-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
1,287 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "deps/fastlanez"] | ||
path = deps/fastlanez | ||
url = https://github.com/fulcrum-so/fastlanez.git |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "fastlanez-sys" | ||
version = "0.1.0" | ||
edition = "2021" | ||
links = "fastlanez" | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
arrayref = "0.3.7" | ||
paste = "1.0.14" | ||
seq-macro = "0.3.5" | ||
uninit = "0.6.2" | ||
|
||
[build-dependencies] | ||
bindgen = "0.69.1" | ||
walkdir = "2.4.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
use std::env; | ||
use std::path::{Path, PathBuf}; | ||
use std::process::{Command, Stdio}; | ||
|
||
use walkdir::WalkDir; | ||
|
||
fn main() { | ||
let buildrs_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()) | ||
.canonicalize() | ||
.expect("Failed to canonicalize CARGO_MANIFEST_DIR"); | ||
let root_dir = buildrs_dir | ||
.join("../") | ||
.canonicalize() | ||
.expect("Failed to canonicalize root dir"); | ||
let fastlanez_dir = root_dir.join("deps/fastlanez"); | ||
|
||
// Tell cargo to tell rustc to link codecz | ||
println!( | ||
"cargo:rustc-link-search={}", | ||
fastlanez_dir.join("zig-out/lib").to_str().unwrap() | ||
); | ||
println!("cargo:rustc-link-lib=fastlanez"); | ||
|
||
rerun_if_changed(&buildrs_dir.join("build.rs")); | ||
WalkDir::new(fastlanez_dir.join("src")) | ||
.into_iter() | ||
.filter_map(|e| e.ok()) | ||
.for_each(|e| rerun_if_changed(e.path())); | ||
|
||
let zig_opt = get_zig_opt(); | ||
println!("cargo:info=invoking `zig build` with {}", zig_opt); | ||
if !Command::new("zig") | ||
.args(["build", "lib"]) | ||
.arg(zig_opt) | ||
.args(["--summary", "all"]) | ||
.current_dir(fastlanez_dir.clone()) | ||
.spawn() | ||
.expect("Could not invoke `zig build`") | ||
.wait() | ||
.unwrap() | ||
.success() | ||
{ | ||
// Panic if the command was not successful. | ||
panic!( | ||
"failed to successfully invoke `zig build` in {}", | ||
root_dir.to_str().unwrap() | ||
); | ||
} | ||
|
||
let bindings = bindgen::Builder::default() | ||
.header( | ||
fastlanez_dir | ||
.join("zig-out/include/fastlanez.h") | ||
.to_str() | ||
.unwrap(), | ||
) | ||
.clang_args(&[ | ||
get_zig_include().as_ref(), | ||
"-DZIG_TARGET_MAX_INT_ALIGNMENT=16", | ||
]) | ||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) | ||
.allowlist_item("fl_.*") | ||
.generate() | ||
.expect("Unable to generate bindings"); | ||
|
||
// Write the bindings to the $OUT_DIR/bindings.rs file. | ||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); | ||
bindings | ||
.write_to_file(out_path.join("bindings.rs")) | ||
.expect("Couldn't write bindings!"); | ||
} | ||
|
||
fn rerun_if_changed(path: &Path) { | ||
println!( | ||
"cargo:rerun-if-changed={}", | ||
path.canonicalize() | ||
.unwrap_or_else(|_| panic!("failed to canonicalize {}", path.to_str().unwrap())) | ||
.to_str() | ||
.unwrap() | ||
); | ||
} | ||
|
||
fn get_zig_opt() -> &'static str { | ||
let profile_env = env::var("PROFILE").unwrap(); | ||
let opt_level_zero = env::var("OPT_LEVEL").unwrap() == "0"; | ||
|
||
// based on https://doc.rust-lang.org/cargo/reference/environment-variables.html | ||
// | ||
// confusingly, the PROFILE env var will be either "debug" or "release" depending on whether the cargo profile | ||
// derives from the "dev" or "release" profile, respectively. *facepalm* | ||
// so `cargo build` and `cargo test` will be "debug"; `cargo build --release` and `cargo bench` will be "release" | ||
// | ||
// we also check whether debug_assertions are enabled (to pick a sane value for custom profiles) | ||
if profile_env == "debug" || cfg!(debug_assertions) { | ||
"-Doptimize=Debug" | ||
} else if profile_env == "release" || !opt_level_zero { | ||
"-Doptimize=ReleaseSmall" | ||
} else { | ||
// we're in a custom profile, the opt_level is 0, but debug assertions aren't enabled | ||
// pretty weird case, let's default to debug | ||
println!( | ||
"cargo:warning=unrecognized cargo profile {}, defaulting to `zig build -Doptimize=Debug`", profile_env | ||
); | ||
"-Doptimize=Debug" | ||
} | ||
} | ||
|
||
fn get_zig_include() -> String { | ||
String::from_utf8( | ||
Command::new("bash") | ||
.arg("-c") | ||
.arg("zig env | grep lib_dir | awk -F'\"' '{print \"-I\"$4}'") | ||
.stdout(Stdio::piped()) | ||
.output() | ||
.expect("Failed to execute command") | ||
.stdout, | ||
) | ||
.expect("Failed to convert command output to string") | ||
.trim_end() | ||
.to_string() | ||
} |
Oops, something went wrong.