Add CMake example
This commit is contained in:
11
rust-to-cmake/Cargo.toml
Normal file
11
rust-to-cmake/Cargo.toml
Normal 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
11
rust-to-cmake/build.rs
Normal 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");
|
||||||
|
}
|
||||||
|
|
||||||
7
rust-to-cmake/libdouble/CMakeLists.txt
Normal file
7
rust-to-cmake/libdouble/CMakeLists.txt
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
add_library (
|
||||||
|
double
|
||||||
|
STATIC
|
||||||
|
double.c
|
||||||
|
)
|
||||||
|
|
||||||
|
install (TARGETS double DESTINATION .)
|
||||||
3
rust-to-cmake/libdouble/double.c
Normal file
3
rust-to-cmake/libdouble/double.c
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
int double_input(int input) {
|
||||||
|
return input * 2;
|
||||||
|
}
|
||||||
11
rust-to-cmake/src/main.rs
Normal file
11
rust-to-cmake/src/main.rs
Normal 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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user