something obvious is wrong..
This commit is contained in:
parent
34e8775ddb
commit
51f3749ba8
29
Cargo.lock
generated
29
Cargo.lock
generated
@ -135,7 +135,6 @@ name = "libcsp-cargo-build"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"walkdir",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -272,15 +271,6 @@ dependencies = [
|
|||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "same-file"
|
|
||||||
version = "1.0.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
|
||||||
dependencies = [
|
|
||||||
"winapi-util",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shlex"
|
name = "shlex"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
@ -304,16 +294,6 @@ version = "1.0.12"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "walkdir"
|
|
||||||
version = "2.5.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
|
|
||||||
dependencies = [
|
|
||||||
"same-file",
|
|
||||||
"winapi-util",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "which"
|
name = "which"
|
||||||
version = "4.4.2"
|
version = "4.4.2"
|
||||||
@ -326,15 +306,6 @@ dependencies = [
|
|||||||
"rustix",
|
"rustix",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-util"
|
|
||||||
version = "0.1.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b"
|
|
||||||
dependencies = [
|
|
||||||
"windows-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.52.0"
|
version = "0.52.0"
|
||||||
|
@ -4,3 +4,5 @@ members = [
|
|||||||
"libcsp-cargo-build", "libcsp-rust",
|
"libcsp-cargo-build", "libcsp-rust",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
resolver = "2"
|
||||||
|
@ -3,6 +3,7 @@ name = "libcsp-cargo-build"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cc = "1"
|
cc = "1"
|
||||||
walkdir = "2"
|
|
||||||
|
@ -23,13 +23,19 @@ pub struct Builder {
|
|||||||
build: cc::Build,
|
build: cc::Build,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Builder {
|
impl Default for Builder {
|
||||||
pub fn new() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
opts: CspBuildOpts::default(),
|
opts: CspBuildOpts::default(),
|
||||||
build: cc::Build::new(),
|
build: cc::Build::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Builder {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self::default()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn cc(&mut self) -> &mut cc::Build {
|
pub fn cc(&mut self) -> &mut cc::Build {
|
||||||
&mut self.build
|
&mut self.build
|
||||||
@ -77,6 +83,7 @@ impl Builder {
|
|||||||
|
|
||||||
self.build.compile("csp");
|
self.build.compile("csp");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn posix_arch_files(&mut self) {
|
fn posix_arch_files(&mut self) {
|
||||||
self.build
|
self.build
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
name = "libcsp-rust"
|
name = "libcsp-rust"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
# links = "csp"
|
links = "csp"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
||||||
|
2421
libcsp-rust/bindings.rs
Normal file
2421
libcsp-rust/bindings.rs
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,12 +1,14 @@
|
|||||||
use std::{env, path::PathBuf};
|
use std::{env, path::PathBuf};
|
||||||
|
|
||||||
use bindgen::CargoCallbacks;
|
|
||||||
use libcsp_cargo_build::Builder;
|
use libcsp_cargo_build::Builder;
|
||||||
//use std::path::PathBuf;
|
|
||||||
|
const GENERATE_BINDINGS_IN_PROJ_ROOT: bool = true;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let project_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
// Pass some important build script environment variables to the binary/library.
|
// Pass some important build script environment variables to the binary/library.
|
||||||
// Remove this at a later stage, this belongs in a concrete example app.
|
// Remove this at a later stage, this belongs in a concrete example app.
|
||||||
|
/*
|
||||||
println!(
|
println!(
|
||||||
"cargo:rustc-env=TARGET={}",
|
"cargo:rustc-env=TARGET={}",
|
||||||
std::env::var("TARGET").unwrap()
|
std::env::var("TARGET").unwrap()
|
||||||
@ -20,32 +22,45 @@ fn main() {
|
|||||||
std::env::var("OPT_LEVEL").unwrap()
|
std::env::var("OPT_LEVEL").unwrap()
|
||||||
);
|
);
|
||||||
println!("cargo:rustc-env=HOST={}", std::env::var("HOST").unwrap());
|
println!("cargo:rustc-env=HOST={}", std::env::var("HOST").unwrap());
|
||||||
|
*/
|
||||||
|
|
||||||
// Tell cargo to tell rustc to link our `csp` library. Cargo will
|
// Tell cargo to tell rustc to link our `csp` library. Cargo will
|
||||||
// automatically know it must look for a `libcsp.a` file.
|
// automatically know it must look for a `libcsp.a` file.
|
||||||
println!("cargo:rustc-link-lib=csp");
|
println!("cargo:rustc-link-lib=csp");
|
||||||
|
println!("cargo:rustc-link-search={}/csp", project_dir);
|
||||||
|
|
||||||
let mut csp_builder = Builder::new();
|
let mut csp_builder = Builder::new();
|
||||||
csp_builder.compile();
|
csp_builder.compile();
|
||||||
|
|
||||||
|
// println!("cargo:rustc-link-search=NATIVE=./");
|
||||||
|
|
||||||
// The bindgen::Builder is the main entry point
|
// The bindgen::Builder is the main entry point
|
||||||
// to bindgen, and lets you build up options for
|
// to bindgen, and lets you build up options for
|
||||||
// the resulting bindings.
|
// the resulting bindings.
|
||||||
let bindings = bindgen::Builder::default()
|
let bindings = bindgen::Builder::default()
|
||||||
// The input header we would like to generate
|
// The input header we would like to generate
|
||||||
// bindings for.
|
// bindings for.
|
||||||
.header(headers_path_str)
|
.clang_arg("-Ilibcsp/include")
|
||||||
|
.clang_arg("-Icfg")
|
||||||
|
.header("wrapper.h")
|
||||||
// Tell cargo to invalidate the built crate whenever any of the
|
// Tell cargo to invalidate the built crate whenever any of the
|
||||||
// included header files changed.
|
// included header files changed.
|
||||||
.parse_callbacks(Box::new(CargoCallbacks::new()))
|
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
||||||
// Finish the builder and generate the bindings.
|
// Finish the builder and generate the bindings.
|
||||||
.generate()
|
.generate()
|
||||||
// Unwrap the Result and panic on failure.
|
// Unwrap the Result and panic on failure.
|
||||||
.expect("Unable to generate bindings");
|
.expect("Unable to generate bindings");
|
||||||
|
|
||||||
|
|
||||||
// Write the bindings to the $OUT_DIR/bindings.rs file.
|
// Write the bindings to the $OUT_DIR/bindings.rs file.
|
||||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs");
|
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs");
|
||||||
bindings
|
bindings
|
||||||
.write_to_file(out_path)
|
.write_to_file(out_path)
|
||||||
.expect("Couldn't write bindings!");
|
.expect("Couldn't write bindings!");
|
||||||
|
if GENERATE_BINDINGS_IN_PROJ_ROOT {
|
||||||
|
let local_path = PathBuf::from("./bindings.rs");
|
||||||
|
bindings
|
||||||
|
.write_to_file(local_path)
|
||||||
|
.expect("Couldn't write bindings!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
8
libcsp-rust/src/lib.rs
Normal file
8
libcsp-rust/src/lib.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#![allow(non_upper_case_globals)]
|
||||||
|
#![allow(non_camel_case_types)]
|
||||||
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
|
// include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||||
|
// extern "C" {
|
||||||
|
// pub fn csp_print_func(fmt: *const ::std::os::raw::c_char, ...);
|
||||||
|
//}
|
@ -1,3 +1,10 @@
|
|||||||
|
|
||||||
|
// include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||||
|
extern "C" {
|
||||||
|
pub fn csp_print_func(fmt: *const ::std::os::raw::c_char, ...);
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
println!("Hello, world!");
|
||||||
|
unsafe { csp_print_func("Hello, world!\n".as_ptr() as *const i8); }
|
||||||
}
|
}
|
||||||
|
@ -1 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include "csp/csp.h"
|
#include "csp/csp.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user