module( name = "rules_wasm", version = "2.1.1", # 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.1", 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 = "package_metadata", version = "0.0.7") bazel_dep(name = "platforms", version = "1.0.0") bazel_dep(name = "rules_cc", version = "0.2.16") bazel_dep(name = "rules_go", version = "0.59.0", repo_name = "io_bazel_rules_go") bazel_dep(name = "rules_license", version = "1.0.0") bazel_dep(name = "rules_rust", version = "0.68.1") 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 = "125" # 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.8.1" # 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 = "29" # https://github.com/bytecodealliance/wasmtime/releases wasmtime_version = "41.0.0" # https://github.com/bytecodealliance/wasm-tools/releases wasm_tools_version = "1.244.0" # https://github.com/bytecodealliance/wit-bindgen/releases wit_bindgen_version = "0.51.0" # https://github.com/bytecodealliance/go-modules/releases wit_bindgen_go_version = "0.7.0" # 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-hr2gnlEqLM2lXYeCJCPepHUFu944rceDINqlD2Mp8czhIng56SKwNgDt7OO/Okhq", "aarch64-macos": "sha384-/VyGEnbNCfuWhQdgk0jUZZ5BR6X/jFgUAp9UE704z/1z8TF4Q9TO80RdLwUVYW1C", "x86_64-linux": "sha384-610rBOCcTE/qoOsS9ghQdTaN6z+TIbyjAeEQGuBJN6Xx9d2+pnZtvJiSSxW6UCov", "x86_64-macos": "sha384-j1OKGc5CF6tcBJn0anAijAapE4eGtdMH75jcDXEqzaLFz/obRgkmr9agFRnUVY+D", }[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-IXwdLWoq0jax4B/k6Q3iU1iJCZdAuN1FYL/n3zfpjyIE3gjk7+8pEY9DuwcCegiM", "aarch64-macos": "sha384-xSbymKgHE+ELSmprYedYF5Ak4L6ThqEZF3kllpNqKYXxxpLcNWtzlwdaGtBIk0SB", "x86_64-linux": "sha384-KYJhbk+OszFP0FeoPUd6hH9KQmIIgZ6jmtfYT5CgcwEJOUTdXTAfzTQac/qdpqyb", "x86_64-macos": "sha384-UAjGFeHo77fqwwykTWjOTn8//a3e183bAkGAuc55wTpN10uiNfZLTnK5Xm9OVVZ8", }[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-0/4ZdpmJp6vgPzQTym6YAZXBXOXmIOaqPhntzKKkGqAsqjaV6Y4ykA/ga6Ox3i98", "aarch64-macos": "sha384-ntXb6D5Je2Co93QjlxoCO2cRvU/vGUXsYeJVJL5ZMAI6FcZqK3hWVZefmFAFnX1q", "x86_64-linux": "sha384-pn0lgY+yOddbNJzDHvvEVCJF+ZU/d8J31HF8Jo80mbhZNXa33qegs3ejsrwRJ9OC", "x86_64-macos": "sha384-HBmQLk9vm5d3AMxQb0Awwn6ylOA/uySWd84xGhTlpgSHXb6k/Lk0iIWGg3Q7LkHm", }[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-g9KkcIY/LbnVfQA4R7ndXkiPEkdKAWIfRHVRrg2iS5Pc8+2xOIudfcECVWJ4ncBq", "aarch64-macos": "sha384-EzQwsox89bnSHgFAs4Xuls7FQYmbtgUuRFoa+m0qkNpEJ3RtJssJYrjWMnRlAhDp", "x86_64-linux": "sha384-IZDeMtdL7PRJxzALijurh70rBvrZxOqqgXp9C9AvSVkUX6dKle0lF8zNOXUMbZ7z", "x86_64-macos": "sha384-ORo320TWgLzZ5rzfVT7Rif1CPntWGsPBv3Wj2+aagPQwAL8oEwuPar2yLKirp0ZR", }[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-ykfI6bmn9TjrH0LJpz2sODTcYXrgJi+GWa1NrHK2jw9QQI5rY3vaORite8PqG+ws", "aarch64-macos": "sha384-odriRm3YZ5/J7GOej7jyPYKBrDSsHECW+PSHsoD2BCzc0cC61D3/ycT9A8DP7DV/", "x86_64-linux": "sha384-AAQWOCQYyFk/CK/tG3TCLoaiWjP5Rm1GUun9jYebwwDuw+eDETsprAFSxWx2vWnC", "x86_64-macos": "sha384-MgupJo/k1kTCqpnbflmfkneHwkI4un4qn2tJzApNRAf0UYZfemVYyJA8cB2SntIq", }[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-HhKzRgMm11IUeY2VEUJ4rOpdITXmI2kRtGMey345ZvPueTTB/nCpVYxY+Z0UvFMB", "aarch64-macos": "sha384-svr3bOAxJqaJRraAo24T8RJOUKKnAczMqYhQoplF+g4Ll681VRHI68IZO+wFZ0ew", "x86_64-linux": "sha384-4VA5uF8xzr4AVCAdowd842HPdFa4UhWBW7tmXSwT4sR19c/wFqB6yvleYxyc+V9B", "x86_64-macos": "sha384-oA7BVSqO7wSEUkUjPgF4NK0iFClIVHb4fFLYBWgoFW4aq8hcj9NxRN/tsKLeSk5f", }[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-x2E3+xi08275MNsEF+u7a/bAU4fQKL3G5N6sKbqa/kIIJXT3tVaQFMsBirYAwFZc", 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")