-
-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support WebAssembly target platforms
wasm{32,64}-unknown-unknown
(#405
- Loading branch information
Showing
20 changed files
with
325 additions
and
17 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
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
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,44 @@ | ||
load("@bazel_skylib//rules:build_test.bzl", "build_test") | ||
load("@rules_cc//cc:defs.bzl", "cc_binary") | ||
load("//:transitions.bzl", "transition_binary_to_platform") | ||
|
||
build_test( | ||
name = "wasm_targets_test", | ||
targets = [ | ||
":wasm32_strlen", | ||
":wasm32_strlen_nolibc", | ||
":wasm64_strlen_nolibc", | ||
], | ||
) | ||
|
||
cc_binary( | ||
name = "wasm_strlen", | ||
srcs = ["wasm_strlen.c"], | ||
linkopts = ["-Wl,--no-entry"], | ||
tags = ["manual"], | ||
) | ||
|
||
transition_binary_to_platform( | ||
name = "wasm32_strlen", | ||
bin = ":wasm_strlen", | ||
platform = "@toolchains_llvm//platforms:wasm32", | ||
) | ||
|
||
cc_binary( | ||
name = "wasm_strlen_nolibc", | ||
srcs = ["wasm_strlen_nolibc.c"], | ||
linkopts = ["-Wl,--no-entry"], | ||
tags = ["manual"], | ||
) | ||
|
||
transition_binary_to_platform( | ||
name = "wasm32_strlen_nolibc", | ||
bin = ":wasm_strlen_nolibc", | ||
platform = "@toolchains_llvm//platforms:wasm32", | ||
) | ||
|
||
transition_binary_to_platform( | ||
name = "wasm64_strlen_nolibc", | ||
bin = ":wasm_strlen_nolibc", | ||
platform = "@toolchains_llvm//platforms:wasm64", | ||
) |
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; | ||
} |
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 |
---|---|---|
|
@@ -41,6 +41,7 @@ filegroup( | |
srcs = [ | ||
"bin/ld.lld", | ||
"bin/ld64.lld", | ||
"bin/wasm-ld", | ||
], | ||
) | ||
|
||
|
Oops, something went wrong.