Skip to content

Commit d67ce86

Browse files
chore: initial boilerplate
Signed-off-by: Henry <mail@henrygressmann.de>
1 parent f328442 commit d67ce86

8 files changed

Lines changed: 1066 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ examples/*/out/*
44
examples/*/target
55
examples/*/Cargo.lock
66
examples/doom/upstream/
7+
crates/c-api/dist
78
*.wad
89
*.WAD
910
examples/wast/*

Cargo.lock

Lines changed: 4 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ tinywasm-parser={version="0.9.0-alpha.1", path="crates/parser", default-features
88
tinywasm-types={version="0.9.0-alpha.1", path="crates/types", default-features=false}
99
tinywasm-cli={version="0.9.0-alpha.1", path="crates/cli", default-features=false}
1010
tinywasm={version="0.9.0-alpha.1", path="crates/tinywasm", default-features=false}
11+
tinywasm-c-api={version="0.9.0-alpha.1", path="crates/c-api", default-features=false}
1112

1213
criterion={version="0.8", default-features=false, features=["cargo_bench_support", "rayon"]}
1314
eyre="0.6"

crates/c-api/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name="tinywasm-c-api"
3+
version.workspace=true
4+
description="C API bindings for TinyWasm"
5+
edition.workspace=true
6+
license.workspace=true
7+
authors.workspace=true
8+
repository.workspace=true
9+
rust-version.workspace=true
10+
keywords.workspace=true
11+
categories.workspace=true
12+
readme="README.md"
13+
14+
[lib]
15+
name="tinywasm_c_api"
16+
path="src/lib.rs"
17+
crate-type=["rlib", "staticlib", "cdylib"]

crates/c-api/Makefile

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
PACKAGE := tinywasm-c-api
2+
LIB_BASENAME := tinywasm_c_api
3+
RUST_TARGET ?= $(shell rustc -vV | sed -n 's/^host: //p')
4+
5+
DIST_DIR := dist/$(RUST_TARGET)
6+
DIST_INCLUDE_DIR := $(DIST_DIR)/include
7+
DIST_LIB_DIR := $(DIST_DIR)/lib
8+
CARGO_BUILD_ARGS := -p $(PACKAGE) --release --target $(RUST_TARGET)
9+
TARGET_DIR := ../../target/$(RUST_TARGET)/release
10+
11+
ifneq (,$(findstring windows,$(RUST_TARGET)))
12+
STATIC_SRC := $(LIB_BASENAME).lib
13+
STATIC_DST := tinywasm.lib
14+
DYNAMIC_SRC := $(LIB_BASENAME).dll
15+
DYNAMIC_DST := tinywasm.dll
16+
else ifneq (,$(findstring apple,$(RUST_TARGET)))
17+
STATIC_SRC := lib$(LIB_BASENAME).a
18+
STATIC_DST := libtinywasm.a
19+
DYNAMIC_SRC := lib$(LIB_BASENAME).dylib
20+
DYNAMIC_DST := libtinywasm.dylib
21+
else
22+
STATIC_SRC := lib$(LIB_BASENAME).a
23+
STATIC_DST := libtinywasm.a
24+
DYNAMIC_SRC := lib$(LIB_BASENAME).so
25+
DYNAMIC_DST := libtinywasm.so
26+
endif
27+
28+
.PHONY: all header static dynamic clean update-header
29+
30+
all: header static dynamic
31+
32+
header:
33+
@mkdir -p "$(DIST_INCLUDE_DIR)"
34+
cp include/wasm.h "$(DIST_INCLUDE_DIR)/wasm.h"
35+
36+
static:
37+
cargo build $(CARGO_BUILD_ARGS)
38+
@mkdir -p "$(DIST_LIB_DIR)"
39+
cp "$(TARGET_DIR)/$(STATIC_SRC)" "$(DIST_LIB_DIR)/$(STATIC_DST)"
40+
41+
dynamic:
42+
cargo build $(CARGO_BUILD_ARGS)
43+
@mkdir -p "$(DIST_LIB_DIR)"
44+
cp "$(TARGET_DIR)/$(DYNAMIC_SRC)" "$(DIST_LIB_DIR)/$(DYNAMIC_DST)"
45+
46+
clean:
47+
rm -rf "$(DIST_DIR)"

crates/c-api/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# `tinywasm-c-api`
2+
3+
This crate will expose the C API surface for TinyWasm.
4+
5+
It is currently a placeholder crate that exists to reserve the package name and workspace layout.
6+
7+
## Artifacts
8+
9+
For now, this crate only provides boilerplate packaging for future C consumers:
10+
11+
- a vendored upstream-compatible public header at `include/wasm.h`
12+
- a `Makefile` that builds the Rust crate and stages C-facing artifacts in `dist/`
13+
14+
Build the staged artifacts with the host Rust target:
15+
16+
```sh
17+
make -C crates/c-api
18+
```
19+
20+
Artifacts are staged under `dist/<target>/`.
21+
22+
Override the target triple when needed:
23+
24+
```sh
25+
make -C crates/c-api RUST_TARGET=aarch64-apple-darwin
26+
```

0 commit comments

Comments
 (0)