Add CMake example
This commit is contained in:
@@ -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"
|
||||||
@@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
add_library (
|
||||||
|
double
|
||||||
|
STATIC
|
||||||
|
double.c
|
||||||
|
)
|
||||||
|
|
||||||
|
install (TARGETS double DESTINATION .)
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
int double_input(int input) {
|
||||||
|
return input * 2;
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user