blob: bd35cd85f181b71b5c4eada483c9d9f91e395362 [file]
module(
name = "rules_wasm",
version = "2.3.0",
# Since some external repositories use patches,
# we need to specify `7.2.1` as the minimum compatible Bazel version.
# https://github.com/bazelbuild/bazel-central-registry/blob/310e56d7b185c997d5a862775ce30116206b9ad1/tools/bcr_validation.py#L668-L669
bazel_compatibility = [">=7.2.1"],
)
bazel_dep(name = "buildifier_prebuilt", version = "8.2.1.2", dev_dependency = True, repo_name = "buildtools")
bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "gazelle", version = "0.47.0")
bazel_dep(name = "jq.bzl", version = "0.6.1")
bazel_dep(name = "package_metadata", version = "0.0.7")
bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "rules_cc", version = "0.2.17")
bazel_dep(name = "rules_go", version = "0.60.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_rust", version = "0.69.0")
bazel_dep(name = "rules_shell", version = "0.6.1")
# The example module (which contains basic tests)
# is itself referenced by tests in the main module,
# which verify that some example tests are running properly.
bazel_dep(name = "example", dev_dependency = True)
local_path_override(
module_name = "example",
path = "example",
)
# Supported execution platforms for pre-built binaries.
# TODO: Figure out how to dedupe this list with `private.bzl`.
execution_platforms = [
"aarch64-linux",
"aarch64-macos",
"x86_64-linux",
"x86_64-macos",
]
# https://github.com/WebAssembly/binaryen/releases
binaryen_version = "127"
# https://pkg.go.dev/go.bytecodealliance.org/cm?tab=versions
go_cm_version = "0.3.0"
# https://github.com/tinygo-org/tinygo/releases
tinygo_version = "0.40.1"
# https://github.com/bytecodealliance/wac/releases
wac_version = "0.9.0"
# ATTOW TinyGo only supports version `0.2.0`:
# https://github.com/WebAssembly/WASI/releases
wasi_version = "0.2.0"
# https://github.com/WebAssembly/wasi-sdk/releases
wasi_sdk_version = "30"
# https://github.com/bytecodealliance/wasmtime/releases
wasmtime_version = "42.0.1"
# https://github.com/bytecodealliance/wasm-tools/releases
wasm_tools_version = "1.245.1"
# https://github.com/bytecodealliance/wit-bindgen/releases
wit_bindgen_version = "0.53.1"
# https://github.com/bytecodealliance/go-modules/releases
wit_bindgen_go_version = "0.7.0"
jq = use_extension("@jq.bzl//jq:extensions.bzl", "toolchains")
use_repo(jq, "jq_toolchains")
# Rust setup: wit-bindgen-generated Rust files depend on the wit-bindgen crate.
crate = use_extension("@rules_rust//crate_universe:extension.bzl", "crate")
crate.spec(
package = "wit-bindgen",
version = wit_bindgen_version,
)
crate.from_specs(
name = "rules-wasm-crates",
# Hardcode all supported Rust toolchains to make Cargo splicing more efficient.
# https://github.com/bazelbuild/rules_rust/discussions/2259
supported_platform_triples = [
"aarch64-unknown-linux-gnu",
"aarch64-apple-darwin",
"wasm32-wasip2",
"x86_64-unknown-linux-gnu",
"x86_64-apple-darwin",
],
)
use_repo(crate, "rules-wasm-crates")
# Manually download prebuilt binaries for various dependencies:
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
[http_archive(
name = "binaryen.{}".format(exe_platform),
build_file_content = """
alias(
name = "wasm-opt",
actual = "binaryen-version_{version}/bin/wasm-opt",
visibility = ["//visibility:public"],
)
""".format(version = binaryen_version),
integrity = {
"aarch64-linux": "sha384-SUScfMm0dfJpWO75n+rj6WSZybCGXH57EiHHjjaQ5V6aPP0X0694tK820O6K5Jis",
"aarch64-macos": "sha384-21yvYg4vOzHKSQ5uC/XTRBLn1ksTL0o8hKnECL4zTZdk+Lo3ooFwWuAHtMdpM0kl",
"x86_64-linux": "sha384-8E/4EPQNhvWqe54v6onnEqxM0jbmtIm9p0M9R3osvhQGBehCwtfDpSrxh3iVRMgI",
"x86_64-macos": "sha384-3r3pTjoBQuUEoQEU2YsH7TAE6rlt0ARmpqx1M2StjCBB3l+wbMeD0/BXERQmEUXp",
}[exe_platform],
url = "https://github.com/WebAssembly/binaryen/releases/download/version_{version}/binaryen-version_{version}-{platform}.tar.gz".format(
platform = {
"aarch64-linux": "aarch64-linux",
"aarch64-macos": "arm64-macos",
"x86_64-linux": "x86_64-linux",
"x86_64-macos": "x86_64-macos",
}[exe_platform],
version = binaryen_version,
),
) for exe_platform in execution_platforms]
wac_platforms = {
"aarch64-linux": "aarch64-unknown-linux-musl",
"aarch64-macos": "aarch64-apple-darwin",
"x86_64-linux": "x86_64-unknown-linux-musl",
"x86_64-macos": "x86_64-apple-darwin",
}
[http_file(
name = "wac.{}".format(exe_platform),
executable = True,
integrity = {
"aarch64-linux": "sha384-+TtQSg+/zAioaEIrCssDeYUCGGHdLpte8I+jdSyIdF/r6psPbF5KQyYqXUiXHGFJ",
"aarch64-macos": "sha384-Dyu/2G4OThVCOuyL+aahZThRk2njNVLu+RWPspy8tP0uW320sa8vjL9CZVljhBRv",
"x86_64-linux": "sha384-7gORhZkigfWoLbC9raKk2+e2red56CGFPrKr+Ckblef4+aHa1C5ogXa8plVkal4l",
"x86_64-macos": "sha384-PrlmSSF0gJ+X116/ylwW/Za/JtVbC76X9U6EHmPxWrbQG31fmUy+3xVgGGJw9ENw",
}[exe_platform],
url = "https://github.com/bytecodealliance/wac/releases/download/v{version}/wac-cli-{platform}".format(
# WAC uses non-canonical platform strings in the URLs:
platform = wac_platforms[exe_platform],
version = wac_version,
),
) for exe_platform in execution_platforms]
http_archive(
name = "wasi",
build_file_content = """
load(":wasm.bzl", "wasi_packages")
[filegroup(
name = package,
srcs = glob(["WASI-{version}/preview2/" + package + "/*.wit"]),
visibility = ["//visibility:public"],
) for package in wasi_packages.keys()]
""".format(version = wasi_version),
integrity = "sha384-k5+dIIcSf9AtW/dpJ4wHglf9GCs0OZw5I90Lkd74RZ/X8PMv0Cx9WKFPsTFPCV9H",
# Ideally there would be something like `remote_file_urls` for local files
# so we can eliminate this redundant patch file
# and instead just copy `wasm.bzl` into the remote repo:
# https://github.com/bazelbuild/bazel/issues/24499.
patches = ["//wasm:wasi.patch"],
url = "https://github.com/WebAssembly/WASI/archive/refs/tags/v{version}.tar.gz".format(version = wasi_version),
)
wasi_sdk_platforms = {
"aarch64-linux": "arm64-linux",
"aarch64-macos": "arm64-macos",
"x86_64-linux": "x86_64-linux",
"x86_64-macos": "x86_64-macos",
}
[http_archive(
name = "wasi-sdk.{}".format(exe_platform),
# Note: these are symlinks within the HTTP archive:
# - clang -> clang-19
# - ar -> llvm-ar
# - nm -> llvm-nm
# - objdump -> llvm-objdump
# - strip -> llvm-objcopy
build_file_content = """
load("@bazel_skylib//rules/directory:directory.bzl", "directory")
load("@bazel_skylib//rules/directory:subdirectory.bzl", "subdirectory")
package(default_visibility=["//visibility:public"])
alias(name = "clang", actual = "wasi-sdk-{version}.0-{platform}/bin/clang")
alias(name = "wasm-component-ld", actual = "wasi-sdk-{version}.0-{platform}/bin/wasm-component-ld")
alias(name = "ar", actual = "wasi-sdk-{version}.0-{platform}/bin/ar")
alias(name = "nm", actual = "wasi-sdk-{version}.0-{platform}/bin/nm")
alias(name = "objdump", actual = "wasi-sdk-{version}.0-{platform}/bin/objdump")
alias(name = "strip", actual = "wasi-sdk-{version}.0-{platform}/bin/strip")
directory(
name = "lib",
srcs = glob(["wasi-sdk-{version}.0-{platform}/lib/**"]),
)
subdirectory(
name = "include",
parent = ":lib",
path = "clang/19/include",
)
""".format(
platform = wasi_sdk_platforms[exe_platform],
version = wasi_sdk_version,
),
integrity = {
"aarch64-linux": "sha384-6CBZ8X+TV3KR6kpvF1l7GD8qTJAyVmqHDHdz1e0iFTUqQc3qtakmHVp3iJndbXby",
"aarch64-macos": "sha384-b/Ug1N47MLpJNRGfZTyaxtKNSeIjsX6DZmXIAiJQGdPtDl4ScRNnq8ED66vvIFGD",
"x86_64-linux": "sha384-mRIxiaLEy7rrVpKmnopHuK0GQ1xH5mQyj06cc5TgQeqc6pJJG6Qnljn0+kYxN4gl",
"x86_64-macos": "sha384-DtQ818n6vfmgR7n4t3IncpQQGfUEv5D96arGPjrlXnnvjeGMXi8/Z7BS706tn0EK",
}[exe_platform],
url = "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-{version}/wasi-sdk-{version}.0-{platform}.tar.gz".format(
platform = wasi_sdk_platforms[exe_platform],
version = wasi_sdk_version,
),
) for exe_platform in execution_platforms]
[http_archive(
name = "wasmtime.{}".format(exe_platform),
build_file_content = """
alias(
name = "wasmtime",
actual = "wasmtime-v{version}-{platform}/wasmtime",
visibility = ["//visibility:public"],
)
""".format(
platform = exe_platform,
version = wasmtime_version,
),
integrity = {
"aarch64-linux": "sha384-4QFMGTufNU01agiwnRshcBOmExSqGecfIUCezk7RDXCu7a8t25hubIx4L86JIE1g",
"aarch64-macos": "sha384-1sD6U/3qGGv7Q3+mW0mfSLwpWrkKyGKcjLdaYdqz+gvdytZJlIkEj6nkPnhvYLtd",
"x86_64-linux": "sha384-1/jVf4e0aEaTwe2ZjybxqXDOUg/kLDZXJPzyrCKPBMtNnyRU+j4ZoRhqFXkGu+A9",
"x86_64-macos": "sha384-lnR3TCwuj/aJHgLgWIFWxf5fuzYo0ofrz0b4OAbsbStWWGpZG7eqjB9HCtRfqa/c",
}[exe_platform],
url = "https://github.com/bytecodealliance/wasmtime/releases/download/v{version}/wasmtime-v{version}-{platform}.tar.xz".format(
platform = exe_platform,
version = wasmtime_version,
),
) for exe_platform in execution_platforms]
[http_archive(
name = "wasm-tools.{}".format(exe_platform),
build_file_content = """
alias(
name = "wasm-tools",
actual = "wasm-tools-{version}-{platform}/wasm-tools",
visibility = ["//visibility:public"],
)
""".format(
platform = exe_platform,
version = wasm_tools_version,
),
integrity = {
"aarch64-linux": "sha384-vA9YcL9eBLSkTJnugGHb+35Osp/f2CsrSiLP5k+lPS5CtPGFKfQh8X6TRoegxblB",
"aarch64-macos": "sha384-XwPPGka4C+Mc/klZFlNSkIQW4ktd9aiGYS1LwtL2cipe3G70box2B76JA0M6tQ7h",
"x86_64-linux": "sha384-Qi7fBVQa8c9cwdnMWLIXHIZ2kVl66FMHJz424zFrwnkveKMwbYPfOcceD2f/k5A+",
"x86_64-macos": "sha384-Y+i81ODSGvXOtMoqcCxz1E4cigsVHjGVQ3amB/6DyOmw4uuINwyjPF6OiSUd1oyS",
}[exe_platform],
url = "https://github.com/bytecodealliance/wasm-tools/releases/download/v{version}/wasm-tools-{version}-{platform}.tar.gz".format(
platform = exe_platform,
version = wasm_tools_version,
),
) for exe_platform in execution_platforms]
[http_archive(
name = "wit-bindgen.{}".format(exe_platform),
build_file_content = """
alias(
name = "wit-bindgen",
actual = "wit-bindgen-{version}-{platform}/wit-bindgen",
visibility = ["//visibility:public"],
)
""".format(
platform = exe_platform,
version = wit_bindgen_version,
),
integrity = {
"aarch64-linux": "sha384-C9ibB7vM0Y2gJFBqD1jUZ94kCzJu2HdZfGhne5qZEKxCIZo+uIB7hn1dWP8BRtRV",
"aarch64-macos": "sha384-OohskCVIlMW9WUB3h9FpffNH+qXYdZ+6wmlD7aqDr6MVmRapTggLlFHW/qcGvmGt",
"x86_64-linux": "sha384-ubXl+maRqKzLZjvBHbHuNc32FpJRJvOdBr8LAZyK38AHgArmm2UN2iPZFWM10GII",
"x86_64-macos": "sha384-ZO4aMFUkNvm6Fh3ghl8BnAdUXT9W6C7vwbIpzPS4MfFJM/QnQNS8vNr5gzmKIO/P",
}[exe_platform],
url = "https://github.com/bytecodealliance/wit-bindgen/releases/download/v{version}/wit-bindgen-{version}-{platform}.tar.gz".format(
platform = exe_platform,
version = wit_bindgen_version,
),
) for exe_platform in execution_platforms]
[http_archive(
name = "tinygo.{}".format(exe_platform),
build_file_content = """
alias(
name = "tinygo",
actual = "tinygo/bin/tinygo",
visibility = ["//visibility:public"],
)
""",
integrity = {
"aarch64-linux": "sha384-4oA3DtjBkX5aqRAqhDf7o2Y6svaus4aUHETOTN/vIJgX8j31jA9kcRquACBnWJqv",
"aarch64-macos": "sha384-xGK9sH3W13X2GQm4vZXQToizkw5DJ0UApU+Kemdt32RzVOtuT7O3dcX2r5KO7OP6",
"x86_64-linux": "sha384-BlHCxDpL/Ajw/zXN6yPQupbPopRVKFzgVUf8bCtEXG+CZl15rm6RLh1reZqqEw2Z",
"x86_64-macos": "sha384-sOo63ufRwabSy8pnr0DWHCBymKtb9y2Q4yC7tH8M1InYR2H77CCowoaOCElhTNaC",
}[exe_platform],
url = "https://github.com/tinygo-org/tinygo/releases/download/v{version}/tinygo{version}.{platform}.tar.gz".format(
platform = {
"aarch64-linux": "linux-arm64",
"aarch64-macos": "darwin-arm64",
"x86_64-linux": "linux-amd64",
"x86_64-macos": "darwin-amd64",
}[exe_platform],
version = tinygo_version,
),
) for exe_platform in execution_platforms]
[http_archive(
name = "wit-bindgen-go.{}".format(exe_platform),
build_file_content = """
exports_files(
["wit-bindgen-go"],
visibility = ["//visibility:public"],
)
""",
integrity = {
"aarch64-linux": "sha384-cbNymuUTUpvyb0jVrN+Fy97NgFYmGyJQ+Ml7QyMa98G4KMKAi/Cbp/nRY/xGhvZX",
"aarch64-macos": "sha384-Yn43/bbLp4HKX2oz85ESWZOJgsa0La30Vda+SabuowxtS4604R+9h0ks1n1J0xGV",
"x86_64-linux": "sha384-a5R9jT7HdEHxManvsn8qhyP0Qma/kFousmmPVy4j+QHLat0eDh6aTfyXq1W6KyUd",
"x86_64-macos": "sha384-WmFNc+tWLOCe8zYuYBcQ/99ffOensY/FN1XmijQpVIWSBqz/KSIsPgDitVx2LJJF",
}[exe_platform],
url = "https://github.com/bytecodealliance/go-modules/releases/download/v{version}/wit-bindgen-go-{platform}.tgz".format(
platform = {
"aarch64-linux": "linux-arm64",
"aarch64-macos": "darwin-arm64",
"x86_64-linux": "linux-amd64",
"x86_64-macos": "darwin-amd64",
}[exe_platform],
version = wit_bindgen_go_version,
),
) for exe_platform in execution_platforms]
# Temporary crutch until we can build against wasip2 directly.
http_file(
name = "wasi-snapshot-preview1-reactor",
integrity = "sha384-brQEdKQL+9NcQeUEb/imUUfcLCoP5vCq+IALB/EQ60d1McTv92GOnmlqnH1BxQ5O",
url = "https://github.com/bytecodealliance/wasmtime/releases/download/v{version}/wasi_snapshot_preview1.reactor.wasm".format(version = wasmtime_version),
)
go_repository = use_repo_rule("@gazelle//:deps.bzl", "go_repository")
# The only dependency for generated Go bindings.
go_repository(
name = "go-component-model-utility",
importpath = "go.bytecodealliance.org/cm",
# The patch expose the `go.mod` file
# as well as the Gazelle-generated package info.
patches = ["//go:cm.patch"],
sum = "h1:VhV+4vjZPUGCozCg9+up+FNL3YU6XR+XKghk7kQ0vFc=",
version = "v{}".format(go_cm_version),
)
register_toolchains("//:wasm32-wasi-toolchain")