-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests for building WebAssembly binaries.
- Loading branch information
Showing
6 changed files
with
157 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
_SYSROOT_BUILD = """ | ||
filegroup( | ||
name = {name}, | ||
srcs = glob(["include/**/*", "lib/**/*", "share/**/*"], allow_empty=True), | ||
visibility = ["//visibility:public"], | ||
) | ||
""" | ||
|
||
_WASI_SDK_ABIS = [ | ||
"wasm32-wasi", | ||
"wasm32-wasip1", | ||
"wasm32-wasip1-threads", | ||
"wasm32-wasip2", | ||
"wasm32-wasi-threads", | ||
] | ||
|
||
def _wasi_sdk_sysroots(ctx): | ||
ctx.download_and_extract( | ||
integrity = "sha256-NRcvfSeZSFsVpGsdh/UKWF2RXsZiCA8AXZkVOlCIjwg=", | ||
stripPrefix = "wasi-sysroot-24.0", | ||
url = ["https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-24/wasi-sysroot-24.0.tar.gz"], | ||
) | ||
|
||
ctx.file("empty/BUILD.bazel", _SYSROOT_BUILD.format( | ||
name = repr("empty"), | ||
)) | ||
|
||
for abi in _WASI_SDK_ABIS: | ||
ctx.file("%s/BUILD.bazel" % (abi,), _SYSROOT_BUILD.format( | ||
name = repr(abi), | ||
)) | ||
ctx.execute(["mv", "include/" + abi, "%s/include" % (abi,)]) | ||
ctx.execute(["mv", "lib/" + abi, "%s/lib" % (abi,)]) | ||
ctx.execute(["mv", "share/" + abi, "%s/share" % (abi,)]) | ||
|
||
wasi_sdk_sysroots = repository_rule(_wasi_sdk_sysroots) | ||
|
||
def _libclang_rt_wasm32(ctx): | ||
ctx.file("BUILD.bazel", """ | ||
exports_files(glob(["*.a"])) | ||
""") | ||
|
||
ctx.download_and_extract( | ||
integrity = "sha256-fjPA33WLkEabHePKFY4tCn9xk01YhFJbpqNy3gs7Dsc=", | ||
stripPrefix = "libclang_rt.builtins-wasm32-wasi-24.0", | ||
url = ["https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-24/libclang_rt.builtins-wasm32-wasi-24.0.tar.gz"], | ||
) | ||
|
||
libclang_rt_wasm32 = repository_rule(_libclang_rt_wasm32) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <stdint.h> | ||
#include <string.h> | ||
|
||
__attribute__((export_name("strlen"))) | ||
uint32_t wasm_strlen(char *s) { | ||
return strlen(s); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
__attribute__((export_name("strlen"))) | ||
unsigned long wasm_strlen(char *s) { | ||
unsigned long len = 0; | ||
for (; *s; len++) {} | ||
return len; | ||
} |