Skip to content

Commit

Permalink
test import shared memory
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfettes committed Dec 25, 2024
1 parent e782d35 commit 59485a2
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
.mooncakes/
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# username/hello
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn hello() -> String {
"Hello, world!"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test "hello" {
if @lib.hello() != "Hello, world!" {
fail!("hello() != \"Hello, world!\"")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main {
println(@lib.hello())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"is-main": true,
"import": [
"username/hello/lib"
],
"link": {
"wasm": {
"heap-start-address": 65536,
"import-memory": {
"module": "xxx",
"name": "yyy"
},
"memory-limits": {
"min": 1,
"max": 65536
},
"shared-memory": true
},
"wasm-gc": {
"import-memory": {
"module": "xxx",
"name": "yyy"
},
"memory-limits": {
"min": 1,
"max": 65536
},
"shared-memory": true
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "username/hello",
"version": "0.1.0",
"readme": "README.md",
"repository": "",
"license": "",
"keywords": [],
"description": ""
}
43 changes: 43 additions & 0 deletions crates/moon/tests/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5388,6 +5388,49 @@ fn test_import_memory_and_heap_start() {
);
}

#[test]
fn test_import_shared_memory() {
let dir = TestDir::new("import_shared_memory.in");
check(
get_stdout(
&dir,
[
"build",
"--target",
"wasm",
"--dry-run",
"--sort-input",
"--nostd",
],
),
expect![[r#"
moonc build-package ./lib/hello.mbt -o ./target/wasm/release/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./lib -target wasm
moonc build-package ./main/main.mbt -o ./target/wasm/release/build/main/main.core -pkg username/hello/main -is-main -i ./target/wasm/release/build/lib/lib.mi:lib -pkg-sources username/hello/main:./main -target wasm
moonc link-core ./target/wasm/release/build/lib/lib.core ./target/wasm/release/build/main/main.core -main username/hello/main -o ./target/wasm/release/build/main/main.wasm -pkg-config-path ./main/moon.pkg.json -pkg-sources username/hello/lib:./lib -pkg-sources username/hello/main:./main -target wasm -import-memory-module xxx -import-memory-name yyy -memory-limits-min 1 -memory-limits-max 65536 -shared-memory -heap-start-address 65536
"#]],
);

let dir = TestDir::new("import_shared_memory.in");
check(
get_stdout(
&dir,
[
"build",
"--target",
"wasm-gc",
"--dry-run",
"--sort-input",
"--nostd",
],
),
expect![[r#"
moonc build-package ./lib/hello.mbt -o ./target/wasm-gc/release/build/lib/lib.core -pkg username/hello/lib -pkg-sources username/hello/lib:./lib -target wasm-gc
moonc build-package ./main/main.mbt -o ./target/wasm-gc/release/build/main/main.core -pkg username/hello/main -is-main -i ./target/wasm-gc/release/build/lib/lib.mi:lib -pkg-sources username/hello/main:./main -target wasm-gc
moonc link-core ./target/wasm-gc/release/build/lib/lib.core ./target/wasm-gc/release/build/main/main.core -main username/hello/main -o ./target/wasm-gc/release/build/main/main.wasm -pkg-config-path ./main/moon.pkg.json -pkg-sources username/hello/lib:./lib -pkg-sources username/hello/main:./main -target wasm-gc -import-memory-module xxx -import-memory-name yyy -memory-limits-min 1 -memory-limits-max 65536 -shared-memory
"#]],
);
}

#[test]
fn test_many_targets() {
let dir = TestDir::new("test_many_targets.in");
Expand Down

0 comments on commit 59485a2

Please sign in to comment.