Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Wasi run tests #3730

Merged
merged 7 commits into from
Nov 25, 2019
Merged

Wasi run tests #3730

merged 7 commits into from
Nov 25, 2019

Conversation

fengb
Copy link
Contributor

@fengb fengb commented Nov 20, 2019

This patches in some missing functionality into std.os.wasi to get tests compiling and running.

$ zig test prototypes/wavesynth/src/main.zig -target wasm32-wasi --test-cmd wasmtime --test-cmd-bin
1/3 test "Note.parse"...OK
2/3 test "Note.toFreq"...OK
3/3 test "Note.format"...OK
All tests passed.

@@ -33,7 +33,7 @@ fn cShrink(self: *Allocator, old_mem: []u8, old_align: u29, new_size: usize, new

/// This allocator makes a syscall directly for every allocation and free.
/// Thread-safe and lock-free.
pub const direct_allocator = &direct_allocator_state;
pub const direct_allocator = if (builtin.arch == .wasm32) wasm_allocator else &direct_allocator_state;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this be better done on the DirectAllocator type itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure. Since the wasm allocator has global state, we need to ensure that direct_allocator and wasm_allocator refer to the same instance.

@daurnimator daurnimator added arch-wasm 32-bit and 64-bit WebAssembly standard library This issue involves writing Zig code for the standard library. labels Nov 20, 2019
@fengb
Copy link
Contributor Author

fengb commented Nov 20, 2019

I put wasmtime in build.zig because it was slightly easier to slap in the CLI args than the alternative (wasmtime test.zig vs wasmer run test.zig).

@syrusakbary
Copy link

syrusakbary commented Nov 20, 2019

I put wasmtime in build.zig because it was slightly easier to slap in the CLI args than the alternative (wasmtime test.zig vs wasmer run test.zig).

We are thinking on enabling wasmer test.zig soon, so hopefully that's will be not an issue and we can use Wasmer here! :)

@@ -649,6 +650,13 @@ pub const Target = union(enum) {
}
}

if (self.isWasm()) {
switch (self.getArchPtrBitWidth()) {
32 => return Executor{ .wasmtime = "wasmtime" },

Choose a reason for hiding this comment

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

I'm curious... have you tried this and it didn't worked? @fengb

                32 => return Executor{ .wasi = "wasmer run" },

Copy link
Contributor Author

@fengb fengb Nov 20, 2019

Choose a reason for hiding this comment

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

Zig build args are generated separately --test-cmd wasmer --test-cmd run so I'd have to update the plumbing to support multiple args.

Choose a reason for hiding this comment

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

That make sense! Thanks for the info.

To support this use case, we are working now on allowing to pass a file as first argument without being explicit with run (so you can do wasmer myfile.wasm).
I'll post an update here once it's ready to be used (which should be very soon!)

Choose a reason for hiding this comment

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

We just added support for running wasm files directly without the run argument.
wasmerio/wasmer#990

We will publish a release soon :)

@syrusakbary
Copy link

@fengb we just released Wasmer 0.11. With it, you can run wasmer myfile.wasm directly.
So everything should be good to go to use wasmer in this PR :)

Thanks for your feedback, without it we wouldn't have improve the Wasmer CLI to make it a bit easier to use!

@andrewrk
Copy link
Member

@syrusakbary thanks for your help! Another question for you if you don't mind. We run CI tests in the following environments:

  • x86_64 Microsoft Windows 10
  • x86_64 macOS 10.14
  • x86_64 Ubuntu 18.04
  • x86_64 and aarch64 Alpine Linux (edge from 1 month ago)
  • x86_64 FreeBSD 12

Can you advise on the best way to obtain Wasmer 0.11 in these environments (or at least a subset)? I'm guessing it won't be in, for example, apt-get for Ubuntu 18.04.

@syrusakbary
Copy link

x86_64 Microsoft Windows 10

I can provide a powershell script if needed, otherwise just install Wasmer from here: https://github.com/wasmerio/wasmer/releases/download/0.11.0/wasmer-windows.exe

x86_64 macOS 10.14

curl https://get.wasmer.io -sSfL | sh

x86_64 Ubuntu 18.04

curl https://get.wasmer.io -sSfL | sh

x86_64 and aarch64 Alpine Linux (edge from 1 month ago)

We haven't tested on Alpine, but this should work in both architectures (x86_64 and aarch64) (let me know if it doesn't and we will fix it!)

curl https://get.wasmer.io -sSfL | sh

x86_64 FreeBSD 12

I think we don't currently support FreeBSD, but hopefully should not very hard to add.
Let me know if that's a requirement for you and we will prioritize it.

@andrewrk andrewrk closed this in 80f79cc Nov 25, 2019
@andrewrk andrewrk merged commit 0f0d01a into ziglang:master Nov 25, 2019
@andrewrk
Copy link
Member

@syrusakbary thanks for the info! I made a follow-up issue for this here: #3775

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-wasm 32-bit and 64-bit WebAssembly standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants