Skip to content

Commit af29606

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

File tree

4 files changed

+52
-56
lines changed

4 files changed

+52
-56
lines changed

.circleci/config.yml

Lines changed: 23 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ 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: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
7378
install-node-version:
7479
description: "install a specific version of node"
7580
parameters:
@@ -721,6 +726,20 @@ jobs:
721726
core0.test_hello_argc
722727
core2.test_demangle_stacks_symbol_map"
723728
- upload-test-results
729+
test-rust:
730+
executor: linux-python
731+
#docker:
732+
# - image: cimg/rust:1.82.0-node
733+
steps:
734+
- install-rust
735+
- checkout
736+
- run:
737+
name: submodule update
738+
command: git submodule update --init
739+
- pip-install
740+
- install-emsdk
741+
- run-tests:
742+
test_targets: "other.test_rust_integration_basics"
724743
test-node-compat:
725744
# We don't use `bionic` here since its too old to run recent node versions:
726745
# `/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found`
@@ -788,6 +807,7 @@ jobs:
788807
executor: bionic
789808
environment:
790809
EMTEST_SKIP_NODE_CANARY: "1"
810+
EMTEST_SKIP_RUST: "1"
791811
EMTEST_SKIP_WASM64: "1"
792812
steps:
793813
- run: apt-get install -q -y ninja-build scons ccache
@@ -905,6 +925,7 @@ jobs:
905925
EMTEST_SKIP_WASM64: "1"
906926
EMTEST_SKIP_SIMD: "1"
907927
EMTEST_SKIP_SCONS: "1"
928+
EMTEST_SKIP_RUST: "1"
908929
EMTEST_SKIP_NODE_CANARY: "1"
909930
EMTEST_BROWSER: "0"
910931
steps:
@@ -940,6 +961,7 @@ jobs:
940961
EMTEST_SKIP_EH: "1"
941962
EMTEST_SKIP_WASM64: "1"
942963
EMTEST_SKIP_SCONS: "1"
964+
EMTEST_SKIP_RUST: "1"
943965
# Some native clang tests assume x86 clang (e.g. -sse2)
944966
EMTEST_LACKS_NATIVE_CLANG: "1"
945967
EMCC_SKIP_SANITY_CHECK: "1"
@@ -956,59 +978,4 @@ jobs:
956978
workflows:
957979
build-test:
958980
jobs:
959-
- flake8
960-
- mypy
961-
- eslint
962-
- build-docs
963-
- build-linux
964-
- test-sanity:
965-
requires:
966-
- build-linux
967-
- test-posixtest:
968-
requires:
969-
- build-linux
970-
- test-core0:
971-
requires:
972-
- build-linux
973-
- test-core2:
974-
requires:
975-
- build-linux
976-
- test-core3:
977-
requires:
978-
- build-linux
979-
- test-wasm64:
980-
requires:
981-
- build-linux
982-
- test-wasm64-4gb:
983-
requires:
984-
- build-linux
985-
- test-wasm2js1:
986-
requires:
987-
- build-linux
988-
- test-other:
989-
requires:
990-
- build-linux
991-
- test-browser-chrome:
992-
requires:
993-
- build-linux
994-
- test-browser-chrome-2gb:
995-
requires:
996-
- build-linux
997-
- test-browser-chrome-wasm64:
998-
requires:
999-
- build-linux
1000-
- test-browser-chrome-wasm64-4gb:
1001-
requires:
1002-
- build-linux
1003-
- test-browser-firefox:
1004-
requires:
1005-
- build-linux
1006-
- test-browser-firefox-wasm64
1007-
- test-sockets-chrome:
1008-
requires:
1009-
- build-linux
1010-
- test-jsc
1011-
- test-spidermonkey
1012-
- test-node-compat
1013-
- test-windows
1014-
- test-mac-arm64
981+
- 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)