Merge pull request #30 from miehe-dup/master

Add CMake example
This commit is contained in:
Alex Crichton
2019-08-16 08:27:54 -05:00
committed by GitHub
5 changed files with 43 additions and 0 deletions

11
rust-to-cmake/Cargo.toml Normal file
View File

@@ -0,0 +1,11 @@
[package]
name = "rust-to-cmake"
version = "0.1.0"
authors = ["Alex Crichton <alex@alexcrichton.com>"]
build = "build.rs"
[dependencies]
libc = "0.2"
[build-dependencies]
cmake = "0.1.41"

11
rust-to-cmake/build.rs Normal file
View File

@@ -0,0 +1,11 @@
extern crate cmake;
fn main() {
// Builds the project in the directory located in `libfoo`, installing it
// into $OUT_DIR
let dst = cmake::build("libdouble");
println!("cargo:rustc-link-search=native={}", dst.display());
println!("cargo:rustc-link-lib=static=double");
}

View File

@@ -0,0 +1,7 @@
add_library (
double
STATIC
double.c
)
install (TARGETS double DESTINATION .)

View File

@@ -0,0 +1,3 @@
int double_input(int input) {
return input * 2;
}

11
rust-to-cmake/src/main.rs Normal file
View File

@@ -0,0 +1,11 @@
extern crate libc;
extern {
fn double_input(input: libc::c_int) -> libc::c_int;
}
fn main() {
let input = 4;
let output = unsafe { double_input(input) };
println!("{} * 2 = {}", input, output);
}