Skip to content

Commit ec6565c

Browse files
committed
Initial commit
0 parents  commit ec6565c

File tree

6 files changed

+53
-0
lines changed

6 files changed

+53
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
**/*.rs.bk

Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "wasm-crate-with-c"
3+
version = "0.1.0"
4+
authors = ["Max Brunsfeld <maxbrunsfeld@gmail.com>"]
5+
edition = "2018"
6+
7+
[lib]
8+
name = "wasm_lib_with_c"
9+
path = "src/lib.rs"
10+
crate-type = ["staticlib"]
11+
12+
[build-dependencies]
13+
cc = "1.0"

build.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extern crate cc;
2+
3+
fn main() {
4+
let mut config = cc::Build::new();
5+
config
6+
.file("src/lib.c")
7+
.compile("wasm-lib-with-c");
8+
}

src/lib.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <stdint.h>
2+
3+
uint32_t increment_in_c(uint32_t i) {
4+
return i + 1;
5+
}

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extern "C" {
2+
#[no_mangle]
3+
fn increment_in_c(i: u32) -> u32;
4+
}
5+
6+
#[no_mangle]
7+
extern "C" fn increment_in_rust(i: u32) -> u32 {
8+
unsafe { increment_in_c(i) }
9+
}

0 commit comments

Comments
 (0)