Skip to content

Commit 7cb85cc

Browse files
committed
Add basic rust integration test. NFC
1 parent 299be0b commit 7cb85cc

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

.circleci/config.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,18 @@ jobs:
721721
core0.test_hello_argc
722722
core2.test_demangle_stacks_symbol_map"
723723
- upload-test-results
724+
test-rust:
725+
docker:
726+
- image: cimg/rust:1.82.0-node
727+
steps:
728+
- checkout
729+
- run:
730+
name: submodule update
731+
command: git submodule update --init
732+
- pip-install
733+
- install-emsdk
734+
- run-tests:
735+
test_targets: "other.test_rust_integration_basics"
724736
test-node-compat:
725737
# We don't use `bionic` here since its too old to run recent node versions:
726738
# `/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found`
@@ -788,6 +800,7 @@ jobs:
788800
executor: bionic
789801
environment:
790802
EMTEST_SKIP_NODE_CANARY: "1"
803+
EMTEST_SKIP_RUST: "1"
791804
EMTEST_SKIP_WASM64: "1"
792805
steps:
793806
- run: apt-get install -q -y ninja-build scons ccache
@@ -905,6 +918,7 @@ jobs:
905918
EMTEST_SKIP_WASM64: "1"
906919
EMTEST_SKIP_SIMD: "1"
907920
EMTEST_SKIP_SCONS: "1"
921+
EMTEST_SKIP_RUST: "1"
908922
EMTEST_SKIP_NODE_CANARY: "1"
909923
EMTEST_BROWSER: "0"
910924
steps:
@@ -940,6 +954,7 @@ jobs:
940954
EMTEST_SKIP_EH: "1"
941955
EMTEST_SKIP_WASM64: "1"
942956
EMTEST_SKIP_SCONS: "1"
957+
EMTEST_SKIP_RUST: "1"
943958
# Some native clang tests assume x86 clang (e.g. -sse2)
944959
EMTEST_LACKS_NATIVE_CLANG: "1"
945960
EMCC_SKIP_SANITY_CHECK: "1"
@@ -1012,3 +1027,4 @@ workflows:
10121027
- test-node-compat
10131028
- test-windows
10141029
- test-mac-arm64
1030+
- test-rust

test/rust/basics/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[package]
2+
name = "basics"
3+
4+
[lib]
5+
crate-type = ["staticlib"]

test/rust/basics/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[no_mangle]
2+
pub extern "C" fn say_hello() {
3+
println!("Hello from rust!");
4+
}

test/test_other.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ def requires_scons(func):
172172
return requires_tool('scons')(func)
173173

174174

175+
def requires_rust(func):
176+
assert callable(func)
177+
return requires_tool('cargo')(func)
178+
179+
175180
def requires_pkg_config(func):
176181
assert callable(func)
177182

@@ -15329,3 +15334,18 @@ def test_fp16(self, opts):
1532915334

1533015335
def test_embool(self):
1533115336
self.do_other_test('test_embool.c')
15337+
15338+
@requires_rust
15339+
def test_rust_integration_basics(self):
15340+
shutil.copytree(test_file('rust/basics'), 'basics')
15341+
self.run_process(['cargo', 'build', '--target=wasm32-unknown-emscripten'], cwd='basics')
15342+
lib = 'basics/target/wasm32-unknown-emscripten/debug/libbasics.a'
15343+
self.assertExists(lib)
15344+
15345+
create_file('main.cpp', '''
15346+
extern "C" void say_hello();
15347+
int main() {
15348+
say_hello();
15349+
return 0;
15350+
}''')
15351+
self.do_runf('main.cpp', 'Hello from rust!', emcc_args=[lib])

0 commit comments

Comments
 (0)