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

Conversation

Projects
None yet
2 participants
@bnoordhuis
Member

bnoordhuis commented Jun 10, 2018

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);
}
support `--target-arch wasm32`
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

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@andrewrk

This comment has been minimized.

Member

andrewrk commented Jun 10, 2018

beautiful

@andrewrk

This comment has been minimized.

Member

andrewrk commented Jun 10, 2018

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

This comment has been minimized.

Member

bnoordhuis commented Jun 10, 2018

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 bnoordhuis:wasm branch Jun 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment