Skip to content

Commit c0f21cc

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

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

.circleci/config.yml

+25
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ commands:
7070
- run:
7171
name: pip install
7272
command: << parameters.python >> -m pip install -r requirements-dev.txt
73+
install-rust:
74+
steps:
75+
- run:
76+
name: install rust
77+
command: |
78+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
79+
export PATH=${HOME}/.cargo/bin:${PATH}
80+
rustup target add wasm32-unknown-emscripten
81+
echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" >> $BASH_ENV
7382
install-node-version:
7483
description: "install a specific version of node"
7584
parameters:
@@ -721,6 +730,18 @@ jobs:
721730
core0.test_hello_argc
722731
core2.test_demangle_stacks_symbol_map"
723732
- upload-test-results
733+
test-rust:
734+
executor: linux-python
735+
steps:
736+
- install-rust
737+
- checkout
738+
- run:
739+
name: submodule update
740+
command: git submodule update --init
741+
- pip-install
742+
- install-emsdk
743+
- run-tests:
744+
test_targets: "other.test_rust_integration_basics"
724745
test-node-compat:
725746
# We don't use `bionic` here since its too old to run recent node versions:
726747
# `/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found`
@@ -788,6 +809,7 @@ jobs:
788809
executor: bionic
789810
environment:
790811
EMTEST_SKIP_NODE_CANARY: "1"
812+
EMTEST_SKIP_RUST: "1"
791813
EMTEST_SKIP_WASM64: "1"
792814
steps:
793815
- run: apt-get install -q -y ninja-build scons ccache
@@ -905,6 +927,7 @@ jobs:
905927
EMTEST_SKIP_WASM64: "1"
906928
EMTEST_SKIP_SIMD: "1"
907929
EMTEST_SKIP_SCONS: "1"
930+
EMTEST_SKIP_RUST: "1"
908931
EMTEST_SKIP_NODE_CANARY: "1"
909932
EMTEST_BROWSER: "0"
910933
steps:
@@ -940,6 +963,7 @@ jobs:
940963
EMTEST_SKIP_EH: "1"
941964
EMTEST_SKIP_WASM64: "1"
942965
EMTEST_SKIP_SCONS: "1"
966+
EMTEST_SKIP_RUST: "1"
943967
# Some native clang tests assume x86 clang (e.g. -sse2)
944968
EMTEST_LACKS_NATIVE_CLANG: "1"
945969
EMCC_SKIP_SANITY_CHECK: "1"
@@ -1012,3 +1036,4 @@ workflows:
10121036
- test-node-compat
10131037
- test-windows
10141038
- test-mac-arm64
1039+
- test-rust

test/rust/basics/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "basics"
3+
edition = "2021"
4+
5+
[lib]
6+
crate-type = ["staticlib"]

test/rust/basics/src/lib.rs

+4
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

+20
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)