dedicated folder for generating bindings
This commit is contained in:
10
examples/Cargo.toml
Normal file
10
examples/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "libcsp-rust-examples"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
libcsp-rust = { path = "../libcsp-rust" }
|
||||
|
||||
[build-dependencies]
|
||||
libcsp-cargo-build = { path = "../libcsp-cargo-build" }
|
32
examples/build.rs
Normal file
32
examples/build.rs
Normal file
@ -0,0 +1,32 @@
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
use libcsp_cargo_build::Builder;
|
||||
|
||||
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()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-env=OUT_DIR={}",
|
||||
std::env::var("OUT_DIR").unwrap()
|
||||
);
|
||||
println!(
|
||||
"cargo:rustc-env=OPT_LEVEL={}",
|
||||
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();
|
||||
}
|
12
examples/src/main.rs
Normal file
12
examples/src/main.rs
Normal file
@ -0,0 +1,12 @@
|
||||
use std::ffi::CString;
|
||||
|
||||
use libcsp_rust::{csp_init, csp_print_func};
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
unsafe {
|
||||
csp_init();
|
||||
let c_str = CString::new("hello world\n").unwrap();
|
||||
csp_print_func(c_str.as_ptr());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user