Update build system to now overwrite leechcore-sys/src/leechcore_os.rs

macos
ko1N 3 days ago
parent 1984e9755c
commit 3952747906

@ -15,7 +15,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest, windows-latest, macOS-latest]
flags: [--all-features, --no-default-features]
steps:
- uses: actions/checkout@v4
@ -43,7 +43,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest, windows-latest, macOS-latest]
flags: [--all-features, --no-default-features]
steps:
- uses: actions/checkout@v4

@ -24,7 +24,13 @@ jobs:
- os_name: windows-x86_64
os: windows-latest
target: x86_64-pc-windows-msvc
toolchain:
- os_name: macOS-x86_64
os: macOS-latest
target: x86_64-apple-darwin
- os_name: macOS-aarch64
os: macOS-latest
target: aarch64-apple-darwin
toolchain:
- stable
steps:
- uses: actions/checkout@v4

1104
Cargo.lock generated

File diff suppressed because it is too large Load Diff

@ -1,27 +0,0 @@
// builds the connector from a given path (never called by the engine directly)
fn build_from_path(ctx, repo_path) {
info("Installing connector");
cargo("build --release", repo_path);
ctx.copy_cargo_plugin_artifact(repo_path, name_to_lib(ctx.crate_name()));
// TODO: download leechcore_ft601_driver_linux
}
// builds the connector from local path
fn build_local(ctx) {
build_from_path(ctx, ctx.build_path())
}
fn get_source(ctx) {
ctx.clone_repository()
}
// builds the connector from source
fn build_from_source(ctx) {
build_from_path(ctx, get_source(ctx))
}
// downloads a binary release of the plugin, still needs dkms
fn install(ctx) {
}

@ -9,12 +9,12 @@ license = "GPL-3.0"
links = "leechcore"
[dependencies]
ctor = "0.2"
ctor = "0.4"
[build-dependencies]
cc = "1.0"
pkg-config = "0.3"
bindgen = { version = "0.69", optional = true }
bindgen = { version = "0.71", optional = true }
[features]
default = [ ]

@ -5,7 +5,7 @@ extern crate pkg_config;
extern crate bindgen;
use std::env;
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::process::Command;
#[cfg(target_os = "windows")]
@ -23,7 +23,7 @@ fn os_define() -> &'static str {
"LINUX"
}
fn build_leechcore(target: &str) {
fn build() {
let mut files = vec![
"device_file.c",
"device_fpga.c",
@ -43,7 +43,7 @@ fn build_leechcore(target: &str) {
"ob/ob_map.c",
"ob/ob_set.c",
];
if target.contains("windows") {
if target().contains("windows") {
files.push("leechrpc_c.c");
files.push("leechrpcshared.c");
}
@ -61,7 +61,7 @@ fn build_leechcore(target: &str) {
.flag("-D_GNU_SOURCE");
// EXPORTED_FUNCTION= to not export any symbols
if !target.contains("windows") {
if !target().contains("windows") {
// setup additional flags
cfg.flag("-fPIC");
cfg.flag("-pthread");
@ -97,8 +97,10 @@ fn build_leechcore(target: &str) {
}
} else {
// copy pre-compiled idl file into the leechcore folder
std::fs::copy("gen/leechrpc_c.c", "src/leechcore/leechcore/leechrpc_c.c").expect("Failed to copy leechrpc_c.c");
std::fs::copy("gen/leechrpc_h.h", "src/leechcore/leechcore/leechrpc_h.h").expect("Failed to copy leechrpc_h.h");
std::fs::copy("gen/leechrpc_c.c", "src/leechcore/leechcore/leechrpc_c.c")
.expect("Failed to copy leechrpc_c.c");
std::fs::copy("gen/leechrpc_h.h", "src/leechcore/leechcore/leechrpc_h.h")
.expect("Failed to copy leechrpc_h.h");
// link against required libraries
println!("cargo:rustc-link-lib=rpcrt4");
@ -112,24 +114,26 @@ fn build_leechcore(target: &str) {
cfg.compile("libleechcore.a");
if target.contains("windows") {
if target().contains("windows") {
// remove temporary generated files
std::fs::remove_file("src/leechcore/leechcore/leechrpc_c.c").expect("Failed to remove leechrpc_c.c");
std::fs::remove_file("src/leechcore/leechcore/leechrpc_h.h").expect("Failed to remove leechrpc_h.h");
std::fs::remove_file("src/leechcore/leechcore/leechrpc_c.c")
.expect("Failed to remove leechrpc_c.c");
std::fs::remove_file("src/leechcore/leechcore/leechrpc_h.h")
.expect("Failed to remove leechrpc_h.h");
}
println!("cargo:rustc-link-lib=static=leechcore");
}
#[cfg(feature = "bindgen")]
fn gen_leechcore<P: AsRef<Path>>(target: &str, out_dir: P) {
fn generate_bindings() {
let mut builder = bindgen::builder()
.clang_arg(format!("-D{} -D_GNU_SOURCE", os_define()))
.header("./src/leechcore/leechcore/leechcore.h");
// workaround for windows.h
// see https://github.com/rust-lang/rust-bindgen/issues/1556
if target.contains("windows") {
if target().contains("windows") {
builder = builder.blocklist_type("_?P?IMAGE_TLS_DIRECTORY.*")
}
@ -137,34 +141,49 @@ fn gen_leechcore<P: AsRef<Path>>(target: &str, out_dir: P) {
.generate()
.unwrap_or_else(|err| panic!("Failed to generate bindings: {:?}", err));
let bindings_path = out_dir.as_ref().to_path_buf().join("leechcore.rs");
bindings
.write_to_file(&bindings_path)
.unwrap_or_else(|_| panic!("Failed to write {}", bindings_path.display()));
.write_to_file(&bindings_src_path())
.unwrap_or_else(|_| panic!("Failed to write {}", bindings_src_path().display()));
}
#[cfg(not(feature = "bindgen"))]
fn gen_leechcore<P: AsRef<Path>>(_target: &str, out_dir: P) {
fn copy_bindings() {
let bindings_src_path = bindings_src_path();
let bindings_dst_path = bindings_dst_path();
std::fs::copy(bindings_src_path, bindings_dst_path)
.expect("Failed to copy leechcore.rs bindings to OUT_DIR");
}
// path helper functions
fn target() -> String {
env::var("TARGET").unwrap()
}
fn out_dir() -> PathBuf {
PathBuf::from(env::var("OUT_DIR").unwrap())
}
fn bindings_src_path() -> PathBuf {
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
#[cfg(target_os = "windows")]
let bindings_src_path = manifest_dir.join("src").join("leechcore_windows.rs");
#[cfg(target_os = "linux")]
let bindings_src_path = manifest_dir.join("src").join("leechcore_linux.rs");
#[cfg(target_os = "macos")]
let bindings_src_path = manifest_dir.join("src").join("leechcore_mac.rs");
let bindings_dst_path = out_dir.as_ref().to_path_buf().join("leechcore.rs");
std::fs::copy(bindings_src_path, bindings_dst_path)
.expect("Failed to copy leechcore.rs bindings to OUT_DIR");
bindings_src_path
}
fn bindings_dst_path() -> PathBuf {
out_dir().to_path_buf().join("leechcore.rs")
}
fn main() {
let target = env::var("TARGET").unwrap();
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
// build leechcore
build_leechcore(&target);
build();
// generate bindings from headers (optional)
#[cfg(feature = "bindgen")]
generate_bindings();
// generate or copy bindings
gen_leechcore(&target, out_dir);
// copy bindings to build directory
copy_bindings();
}

File diff suppressed because it is too large Load Diff

@ -125,7 +125,8 @@ impl PciLeech {
// open device
let mut conf = build_lc_config(device, remote, mem_map.is_some());
let p_lc_config_error_info = std::ptr::null_mut::<LC_CONFIG_ERRORINFO>();
let pp_lc_config_error_info = &raw const p_lc_config_error_info as *mut PLC_CONFIG_ERRORINFO;
let pp_lc_config_error_info =
&raw const p_lc_config_error_info as *mut PLC_CONFIG_ERRORINFO;
let handle = unsafe { LcCreateEx(&mut conf, pp_lc_config_error_info) };
if handle.is_null() {
error!("Unable to create leechcore context: {conf:?} ppErr: {pp_lc_config_error_info:?} pErr: {p_lc_config_error_info:?}");
@ -139,7 +140,7 @@ impl PciLeech {
};
return Err(Error(ErrorOrigin::Connector, ErrorKind::Configuration)
.log_error(format!("unable to create leechcore context: {err:?}", )));
.log_error(format!("unable to create leechcore context: {err:?}",)));
}
// TODO: allow handling these errors properly

Loading…
Cancel
Save