Skip to content

Commit f56ee36

Browse files
authored
Add basic rust integration test. NFC (#22964)
1 parent f967a5e commit f56ee36

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

.circleci/config.yml

Lines changed: 13 additions & 0 deletions
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:
@@ -788,8 +797,10 @@ jobs:
788797
executor: bionic
789798
environment:
790799
EMTEST_SKIP_NODE_CANARY: "1"
800+
EMTEST_SKIP_RUST: "1"
791801
EMTEST_SKIP_WASM64: "1"
792802
steps:
803+
- install-rust
793804
- run: apt-get install -q -y ninja-build scons ccache
794805
- run-tests-linux:
795806
# some native-dependent tests fail because of the lack of native
@@ -905,6 +916,7 @@ jobs:
905916
EMTEST_SKIP_WASM64: "1"
906917
EMTEST_SKIP_SIMD: "1"
907918
EMTEST_SKIP_SCONS: "1"
919+
EMTEST_SKIP_RUST: "1"
908920
EMTEST_SKIP_NODE_CANARY: "1"
909921
EMTEST_BROWSER: "0"
910922
steps:
@@ -940,6 +952,7 @@ jobs:
940952
EMTEST_SKIP_EH: "1"
941953
EMTEST_SKIP_WASM64: "1"
942954
EMTEST_SKIP_SCONS: "1"
955+
EMTEST_SKIP_RUST: "1"
943956
# Some native clang tests assume x86 clang (e.g. -sse2)
944957
EMTEST_LACKS_NATIVE_CLANG: "1"
945958
EMCC_SKIP_SANITY_CHECK: "1"

test/rust/basics/Cargo.toml

Lines changed: 6 additions & 0 deletions
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

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

@@ -15360,3 +15365,18 @@ def test_fp16(self, opts):
1536015365

1536115366
def test_embool(self):
1536215367
self.do_other_test('test_embool.c')
15368+
15369+
@requires_rust
15370+
def test_rust_integration_basics(self):
15371+
shutil.copytree(test_file('rust/basics'), 'basics')
15372+
self.run_process(['cargo', 'build', '--target=wasm32-unknown-emscripten'], cwd='basics')
15373+
lib = 'basics/target/wasm32-unknown-emscripten/debug/libbasics.a'
15374+
self.assertExists(lib)
15375+
15376+
create_file('main.cpp', '''
15377+
extern "C" void say_hello();
15378+
int main() {
15379+
say_hello();
15380+
return 0;
15381+
}''')
15382+
self.do_runf('main.cpp', 'Hello from rust!', emcc_args=[lib])

0 commit comments

Comments
 (0)