Skip to content

Add basic rust integration test. NFC #22964

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ commands:
- run:
name: pip install
command: << parameters.python >> -m pip install -r requirements-dev.txt
install-rust:
steps:
- run:
name: install rust
command: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#YOLO

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the official way to install rust apparently.. so its actually good that we use this method here I think.

export PATH=${HOME}/.cargo/bin:${PATH}
rustup target add wasm32-unknown-emscripten
echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" >> $BASH_ENV
install-node-version:
description: "install a specific version of node"
parameters:
Expand Down Expand Up @@ -788,8 +797,10 @@ jobs:
executor: bionic
environment:
EMTEST_SKIP_NODE_CANARY: "1"
EMTEST_SKIP_RUST: "1"
EMTEST_SKIP_WASM64: "1"
steps:
- install-rust
- run: apt-get install -q -y ninja-build scons ccache
- run-tests-linux:
# some native-dependent tests fail because of the lack of native
Expand Down Expand Up @@ -905,6 +916,7 @@ jobs:
EMTEST_SKIP_WASM64: "1"
EMTEST_SKIP_SIMD: "1"
EMTEST_SKIP_SCONS: "1"
EMTEST_SKIP_RUST: "1"
EMTEST_SKIP_NODE_CANARY: "1"
EMTEST_BROWSER: "0"
steps:
Expand Down Expand Up @@ -940,6 +952,7 @@ jobs:
EMTEST_SKIP_EH: "1"
EMTEST_SKIP_WASM64: "1"
EMTEST_SKIP_SCONS: "1"
EMTEST_SKIP_RUST: "1"
# Some native clang tests assume x86 clang (e.g. -sse2)
EMTEST_LACKS_NATIVE_CLANG: "1"
EMCC_SKIP_SANITY_CHECK: "1"
Expand Down
6 changes: 6 additions & 0 deletions test/rust/basics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "basics"
edition = "2021"

[lib]
crate-type = ["staticlib"]
4 changes: 4 additions & 0 deletions test/rust/basics/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[no_mangle]
pub extern "C" fn say_hello() {
println!("Hello from rust!");
}
20 changes: 20 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ def requires_scons(func):
return requires_tool('scons')(func)


def requires_rust(func):
assert callable(func)
return requires_tool('cargo')(func)


def requires_pkg_config(func):
assert callable(func)

Expand Down Expand Up @@ -15360,3 +15365,18 @@ def test_fp16(self, opts):

def test_embool(self):
self.do_other_test('test_embool.c')

@requires_rust
def test_rust_integration_basics(self):
shutil.copytree(test_file('rust/basics'), 'basics')
self.run_process(['cargo', 'build', '--target=wasm32-unknown-emscripten'], cwd='basics')
lib = 'basics/target/wasm32-unknown-emscripten/debug/libbasics.a'
self.assertExists(lib)

create_file('main.cpp', '''
extern "C" void say_hello();
int main() {
say_hello();
return 0;
}''')
self.do_runf('main.cpp', 'Hello from rust!', emcc_args=[lib])
Loading