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

support --target-arch wasm32 #1094

Merged
merged 1 commit into from Jun 10, 2018
Merged

support --target-arch wasm32 #1094

merged 1 commit into from Jun 10, 2018

Conversation

bnoordhuis
Copy link
Contributor

Add wasm32 support to the build-obj, build-exe and build-lib commands
of the stage 1 compiler. Wasm64 should work transparently once it's
supported in upstream LLVM.

To export a function:

// lib.zig - for exposition, not necessary for this example
pub use @import("add.zig");

// add.zig
export fn add(a: i32, b: i32) i32 {
    return a + b;
}

To import a function:

// cube.zig
extern fn square(x: i32) i32;

export fn cube(x: i32) i32 {
    return x * square(x);
}

Add wasm32 support to the build-obj, build-exe and build-lib commands
of the stage 1 compiler.  Wasm64 should work transparently once it's
supported in upstream LLVM.

To export a function:

    // lib.zig - for exposition, not necessary for this example
    pub use @import("add.zig");

    // add.zig
    export fn add(a: i32, b: i32) i32 {
        return a + b;
    }

To import a function:

    // cube.zig
    extern fn square(x: i32) i32;

    export fn cube(x: i32) i32 {
        return x * square(x);
    }
@andrewrk andrewrk merged commit d464b25 into ziglang:master Jun 10, 2018
@andrewrk
Copy link
Member

beautiful

@andrewrk
Copy link
Member

I wonder if we can get tests running for this arch. There's gotta be a way to execute wasm for the purposes of unit tests.

@bnoordhuis
Copy link
Contributor Author

I thought about that. It'd be easy if we can assume (or check for) the presence of node since it supports wasm out of the box.

The alternative is to write a skeleton loader+vm in zig but even the simplest wasm file is still fairly complex so it'd be a pretty big undertaking. That PR would be many times the size of this PR.

(I might still do that one day just for the fun of it, though.)

@bnoordhuis bnoordhuis deleted the wasm branch June 10, 2018 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants