something obvious is wrong..

This commit is contained in:
Robin Müller 2024-05-29 12:41:05 +02:00
parent 34e8775ddb
commit 51f3749ba8
10 changed files with 2471 additions and 37 deletions

29
Cargo.lock generated
View File

@ -135,7 +135,6 @@ name = "libcsp-cargo-build"
version = "0.1.0"
dependencies = [
"cc",
"walkdir",
]
[[package]]
@ -272,15 +271,6 @@ dependencies = [
"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]]
name = "shlex"
version = "1.3.0"
@ -304,16 +294,6 @@ version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "which"
version = "4.4.2"
@ -326,15 +306,6 @@ dependencies = [
"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]]
name = "windows-sys"
version = "0.52.0"

View File

@ -4,3 +4,5 @@ members = [
"libcsp-cargo-build", "libcsp-rust",
]
resolver = "2"

View File

@ -3,6 +3,7 @@ name = "libcsp-cargo-build"
version = "0.1.0"
edition = "2021"
[lib]
[dependencies]
cc = "1"
walkdir = "2"

View File

@ -23,13 +23,19 @@ pub struct Builder {
build: cc::Build,
}
impl Builder {
pub fn new() -> Self {
impl Default for Builder {
fn default() -> Self {
Self {
opts: CspBuildOpts::default(),
build: cc::Build::new(),
}
}
}
impl Builder {
pub fn new() -> Self {
Self::default()
}
pub fn cc(&mut self) -> &mut cc::Build {
&mut self.build
@ -77,6 +83,7 @@ impl Builder {
self.build.compile("csp");
}
#[cfg(unix)]
fn posix_arch_files(&mut self) {
self.build

View File

@ -2,7 +2,7 @@
name = "libcsp-rust"
version = "0.1.0"
edition = "2021"
# links = "csp"
links = "csp"
[dependencies]

2421
libcsp-rust/bindings.rs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,14 @@
use std::{env, path::PathBuf};
use bindgen::CargoCallbacks;
use libcsp_cargo_build::Builder;
//use std::path::PathBuf;
const GENERATE_BINDINGS_IN_PROJ_ROOT: bool = true;
fn main() {
let project_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
// Pass some important build script environment variables to the binary/library.
// Remove this at a later stage, this belongs in a concrete example app.
/*
println!(
"cargo:rustc-env=TARGET={}",
std::env::var("TARGET").unwrap()
@ -20,32 +22,45 @@ fn main() {
std::env::var("OPT_LEVEL").unwrap()
);
println!("cargo:rustc-env=HOST={}", std::env::var("HOST").unwrap());
*/
// Tell cargo to tell rustc to link our `csp` library. Cargo will
// automatically know it must look for a `libcsp.a` file.
println!("cargo:rustc-link-lib=csp");
println!("cargo:rustc-link-search={}/csp", project_dir);
let mut csp_builder = Builder::new();
csp_builder.compile();
// println!("cargo:rustc-link-search=NATIVE=./");
// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// 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
// included header files changed.
.parse_callbacks(Box::new(CargoCallbacks::new()))
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.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()).join("bindings.rs");
bindings
.write_to_file(out_path)
.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
View 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, ...);
//}

View File

@ -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() {
println!("Hello, world!");
unsafe { csp_print_func("Hello, world!\n".as_ptr() as *const i8); }
}

View File

@ -1 +1,3 @@
#pragma once
#include "csp/csp.h"