Skip to content

Publish [email protected] #4780

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
388 changes: 388 additions & 0 deletions modules/rules_wasm/2.0.1/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,388 @@
module(
name = "rules_wasm",
version = "2.0.1",
)

bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "gazelle", version = "0.43.0")
bazel_dep(name = "platforms", version = "0.0.11")
bazel_dep(name = "rules_cc", version = "0.1.1")
bazel_dep(name = "rules_go", version = "0.54.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_rust", version = "0.61.0")
bazel_dep(name = "rules_shell", version = "0.4.1")

bazel_dep(name = "buildifier_prebuilt", version = "8.0.3", dev_dependency = True, repo_name = "buildtools")

# 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 = "123"

binaryen_integrity = {
"aarch64-linux": "sha384-gRHcVA3ixZu857DlrGkamJbWE73ec4mrq+e3SxF/EjV7wI7WRzHlSPEN3adzCb11",
"aarch64-macos": "sha384-BNHNaw4V4C7VD9VW6+77+lgzns0LjZBEtMb/HpoH67xmZf7muEwXWgGUzDFMPKbk",
"x86_64-linux": "sha384-ChUj3KQRLPlMFzI4go6A43jQMp1Db7RiV3EH1aHO9MxPI3rXxIzl8ieHBlpIAF30",
"x86_64-macos": "sha384-+jVPAGdgH1mZhGKbIQl3a5NFXNA952mWanfW07ysUUC7uqYMACz7D0dGIJ9TGAYf",
}

# https://pkg.go.dev/go.bytecodealliance.org/cm?tab=versions
go_cm_version = "0.2.2"

go_cm_integrity = "h1:M9iHS6qs884mbQbIjtLX1OifgyPG9DuMs2iwz8G4WQA="

# https://github.com/tinygo-org/tinygo/releases
tinygo_version = "0.37.0"

tinygo_integrity = {
"aarch64-linux": "sha384-hYPKBCmCOy1oi5qXLKXWevXrEs5y4Zo6UBSKAgd683pS9PZA1TTth4ncs2PPr0mc",
"aarch64-macos": "sha384-Wp+X+zpEQYouBrHXgbP9KRNO0q4P7rkhNAyIYzg9EvDhJmZN3WWHBzX5l8Uwlrmt",
"x86_64-linux": "sha384-mXvibb7zoGzU5lBnMPo8bb7FpZEMBTL9K55AdUlkfcmx+38FacG+dx2pciZcim7O",
"x86_64-macos": "sha384-fosbaDMTRkeIdEf5QJIL45SwutsjmaYFf8N5jeaJeABrw+Dc0/EjCPbVAAIPPj/H",
}

# https://github.com/bytecodealliance/wac/releases
wac_version = "0.6.1"

wac_integrity = {
"aarch64-linux": "sha384-a/w+0nesiZRqMqid2W9mrjBA4S/qU4iGXRgHZjA+3Ydq7/efLT3XE41mGBNNqkeC",
"aarch64-macos": "sha384-cEtDDp4io01CLGUuZVZu9LPbk3/Ib7yYn88Q0XG785OltXG81NibGfZVSD9C/+n/",
"x86_64-linux": "sha384-90D0wJeI35nuWmkZMHrOd79pVequX7kbAWHqpcmsG6ZKJdwmfLZVTSGyuvPhjlpo",
"x86_64-macos": "sha384-+hH0YcJEeLeih4NULigzzFgJ3pCKnKq70oB5hEJGKC0E+xU4Hd/kH6NUV9BX/IV+",
}

# https://github.com/WebAssembly/WASI/releases
wasi_version = "0.2.0"

wasi_integrity = "sha384-k5+dIIcSf9AtW/dpJ4wHglf9GCs0OZw5I90Lkd74RZ/X8PMv0Cx9WKFPsTFPCV9H"

# https://github.com/WebAssembly/wasi-sdk/releases
wasi_sdk_version = "25"

wasi_sdk_integrity = {
"aarch64-linux": "sha384-5bnm2bABYAmVF0KeEgz3SAbo4qKRQJkByW9eQZ6KIqV+BF2KiZEEjKI4+ELdJPqH",
"aarch64-macos": "sha384-T6tTh2QN9bfrKptJ80vGCNoyvRbcXHEkzP805V9THXkSFsQD/fwHYkOWD7VOf61f",
"x86_64-linux": "sha384-2hliAV3H1pxMMROU9BarleLEH0dng/XdvfpSsGJKbvRvyy98K59WD8fN5RrvaCML",
"x86_64-macos": "sha384-zVs1lhkofsVL6pWDsKlFEPjWeMxmH19tQX3a4jhfO1XbLlga7Rw/pYQvfReiY7AU",
}

# https://github.com/bytecodealliance/wasmtime/releases
wasmtime_version = "32.0.0"

wasmtime_integrity = {
"aarch64-linux": "sha384-jhCvPSYHkojD5XyvVuwXaD136hyWM2/V31sZknMB3Z16RONTLKtwq6DV7Eh60AK+",
"aarch64-macos": "sha384-115sOmlrX/IYEKqaFz4lCkS2vqXb//VOFKGvvv5D2jIndBmWpq8EKy5Gw94XZyyo",
"x86_64-linux": "sha384-slP9eXTtflJuvRbT/wRghPZLJhnKctC7fB+SxOhCKVh6RH7Ob90V/fpE7NR2xFnG",
"x86_64-macos": "sha384-dTypdNfpzWD64J9GqEmrIhCQRAh6pUAkzGvCk1Q0+TbmATzSH/IZitJW3Tp1j1jj",
}

# https://github.com/bytecodealliance/wasm-tools/releases
wasm_tools_version = "1.230.0"

wasm_tools_integrity = {
"aarch64-linux": "sha384-+2E/AYYSSOan2HKXlF1lJSNuejN5mm6YXDjHRIb9YoZmfBEy675Y/JdqQkbHW7xJ",
"aarch64-macos": "sha384-JQf9Wiid1s0IppD8TRV/zZ46YLoIWgTwRen3zdXF91kUw5FViVZYcdhGEfZ3wA6b",
"x86_64-linux": "sha384-E0Lz7FAPj9mzXPX3ZVNjBgADSi3UmKg5+UFlycqz4LT1sPSUr1ooChfGgWntc/rC",
"x86_64-macos": "sha384-ky5XbMoq0BGgSMV4oWV1fwMA2L4P0Gmn86EQvbRH93m8A4l8OiUIuYE7C52IctFA",
}

# https://github.com/bytecodealliance/wit-bindgen/releases
wit_bindgen_version = "0.41.0"

wit_bindgen_integrity = {
"aarch64-linux": "sha384-ExGOh/2RLlk/I75mDDYD8LIxLZ6SRnt+9lk9S+k1bBFIHdBxS7Plcyg8VkY7fsJy",
"aarch64-macos": "sha384-WMeFa5DYF5lX2HoXiTJFe1IecGffhzvSCi3YlgkuoTmJ786zGmwzmQ5XpOt8jYAn",
"x86_64-linux": "sha384-5871z2F7+yak9d9LYq1folGMCwpEOWJbuvIhFVyheAxFMATuySeVKKt0j41tqAAd",
"x86_64-macos": "sha384-4MVCqJYFsvcBKXUysSKtBnzUcN2DJyyHsmE35grfpuL8HbQJLigh3IfmVsPRgSoo",
}

# https://github.com/bytecodealliance/go-modules/releases
wit_bindgen_go_version = "0.7.0"

wit_bindgen_go_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",
}

# 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",
# TODO: Updgrade to wasip2 when there's an available platform
# (`@platforms//os:wasi` is only supported by wasip1).
"wasm32-wasip1",
"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-" + exe_platform,
build_file_content = """
alias(
name = "wasm-opt",
actual = "binaryen-version_{version}/bin/wasm-opt",
visibility = ["//visibility:public"],
)
""".format(version = binaryen_version),
integrity = binaryen_integrity[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-" + exe_platform,
executable = True,
integrity = wac_integrity[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 = wasi_integrity,
# 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-" + 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 = wasi_sdk_integrity[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-" + 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 = wasmtime_integrity[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-" + 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 = wasm_tools_integrity[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-" + 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 = wit_bindgen_integrity[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-" + exe_platform,
build_file_content = """
alias(
name = "tinygo",
actual = "tinygo/bin/tinygo",
visibility = ["//visibility:public"],
)
""",
integrity = tinygo_integrity[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-" + exe_platform,
build_file_content = """
exports_files(
["wit-bindgen-go"],
visibility = ["//visibility:public"],
)
""",
integrity = wit_bindgen_go_integrity[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]

# Needed to build Rust components.
http_file(
name = "libwit-bindgen-cabi-realloc",
integrity = "sha384-sle1RnmoH6vtWvvF2s5anuN/JaQA56HE6ZCS6MwXmmNNkyLcsYG///amLrQ7HNSI",
url = "https://github.com/bytecodealliance/wit-bindgen/raw/v{version}/crates/guest-rust/rt/src/libwit_bindgen_cabi_realloc.a".format(version = wit_bindgen_version),
)

# Temporary crutch until we can build against wasip2 directly.
http_file(
name = "wasi-snapshot-preview1-reactor",
integrity = "sha384-4FOmdnn8LlRkm8UtB4AaRmNqi6Enr+76+WQENRiFfeoSEfzObl55LuUi1EMWDXVn",
url = "https://github.com/bytecodealliance/wasmtime/releases/download/v{version}/wasi_snapshot_preview1.reactor.wasm".format(version = wasmtime_version),
)

go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
use_repo(go_sdk, "go_default_sdk")

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 = go_cm_integrity,
version = "v{}".format(go_cm_version),
)

register_toolchains("//:wasm32-wasi-toolchain")
Loading
Loading