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

Add Wasm support (in progress) #79

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/wasm_example/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@rules_ll//ll:defs.bzl", "ll_binary")

ll_binary(
name = "wasm_example",
srcs = ["wasm_example.cpp"],
compilation_mode = "wasm",
compile_flags = ["-std=c++20"],
visibility = ["@//:__pkg__"],
)
3 changes: 3 additions & 0 deletions examples/wasm_example/wasm_example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extern "C" int add(int a, int b) {
return a + b;
}
9 changes: 9 additions & 0 deletions ll/args.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ def compile_object_args(
format = "--rocm-device-lib-path=%s",
)

if ctx.attr.compilation_mode == "wasm":
args.add("--target=wasm32-unknown-unknown")
# args.add("-emit-llvm-bc")

# Write compilation database.
args.add("-Xarch_host")
args.add(cdf, format = "-MJ%s")
Expand Down Expand Up @@ -520,6 +524,11 @@ def link_executable_args(ctx, in_files, out_file, mode):
format = "-rpath=$ORIGIN/%s",
)

if ctx.attr.compilation_mode == "wasm":
pass
# args.add("--no-entry")
# args.add("--export-all") # This must be changed (similar to cppm)

# Additional system libraries.
args.add("-lm") # Math.
args.add("-ldl") # Dynamic linking.
Expand Down
8 changes: 8 additions & 0 deletions ll/attributes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ DEFAULT_ATTRS = {
"cuda_nvptx",
"hip_amdgpu",
"hip_nvptx",
"wasm",
"bootstrap",
],
),
Expand Down Expand Up @@ -309,6 +310,13 @@ LL_TOOLCHAIN_ATTRS = {
cfg = transition_to_bootstrap,
default = "@llvm-project//llvm:llvm-link",
),
"wasm_linker": attr.label(
doc = "The linker for WebAssembly",
executable = True,
allow_single_file = True,
cfg = transition_to_bootstrap,
default = "@llvm-project//lld:wasm-ld",
),
"builtin_includes": attr.label(
doc = "Clang's built-in header files.",
cfg = "target",
Expand Down
10 changes: 10 additions & 0 deletions ll/environment.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ def compile_object_environment(ctx):
toolchain.linker_executable.dirname,
]),
}
elif config in ["wasm"]:
return {
"LINK": toolchain.bitcode_linker.path,
"LLD": toolchain.wasm_linker.path,
"LLVM_SYMBOLIZER_PATH": toolchain.symbolizer.path,
"PATH": ":".join([
toolchain.linker.dirname,
toolchain.linker_executable.dirname,
]),
}
elif config in ["cuda_nvptx", "hip_amdgpu", "hip_nvptx"]:
return {
"CLANG_OFFLOAD_BUNDLER": toolchain.offload_bundler.path,
Expand Down
6 changes: 3 additions & 3 deletions ll/inputs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def compile_object_inputs(
toolchain.compiler_runtime
)

if config == "cpp":
if config in ["cpp", "wasm"]:
pass
elif config == "omp_cpu":
direct += toolchain.omp_header
Expand Down Expand Up @@ -135,7 +135,7 @@ def link_executable_inputs(ctx, in_files):
if ctx.attr.depends_on_llvm:
direct += toolchain.llvm_project_artifacts

if config == "cpp":
if config in ["cpp", "wasm"]:
pass
elif config == "omp_cpu":
direct += toolchain.libomp
Expand Down Expand Up @@ -185,7 +185,7 @@ def link_shared_object_inputs(ctx, in_files):
toolchain.compiler_runtime
)

if config == "cpp":
if config == ["cpp", "wasm"]:
pass
elif config == "cuda_nvptx":
pass
Expand Down
1 change: 1 addition & 0 deletions ll/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def _ll_toolchain_impl(ctx):
linker = lld_alias,
linker_executable = ctx.executable.linker,
linker_wrapper = ctx.executable.linker_wrapper,
wasm_linker = ctx.executable.wasm_linker,
address_sanitizer = ctx.files.address_sanitizer,
leak_sanitizer = ctx.files.leak_sanitizer,
memory_sanitizer = ctx.files.memory_sanitizer,
Expand Down
2 changes: 1 addition & 1 deletion ll/tools.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def compile_object_tools(ctx):
toolchain.opt,
]

if config in ["cpp", "omp_cpu"]:
if config in ["cpp", "omp_cpu", "wasm"]:
return tools

if config in ["cuda_nvptx", "hip_nvptx", "hip_amdgpu"]:
Expand Down
1 change: 1 addition & 0 deletions ll/transitions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ COMPILATION_MODES = [
"cuda_nvptx",
"hip_amdgpu",
"hip_nvptx",
"wasm",
]

def _ll_transition_impl(
Expand Down