Skip to content

Commit ce0f702

Browse files
committed
wasm: Add hello world
Signed-off-by: Ryan Northey <[email protected]>
1 parent 9528fa8 commit ce0f702

File tree

15 files changed

+394
-0
lines changed

15 files changed

+394
-0
lines changed

.bazelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
common --enable_bzlmod=0
2+
common --color=yes
3+
common:ci --noshow_progress
4+
common:ci --noshow_loading_progress
5+
common:ci --test_output=errors

.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6.5.0

.github/workflows/modules.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build modules
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
paths:
9+
release:
10+
types:
11+
released
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
build:
18+
runs-on: ${{ matrix.runs-on }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
include:
23+
- arch: x86_64
24+
runs-on: ubuntu-22.04
25+
- arch: aarch64
26+
runs-on: ubuntu-22.04-arm
27+
steps:
28+
- uses: actions/checkout@v4
29+
- name: Fetch versions
30+
id: deps
31+
run: |
32+
bazel build //wasm/http-hello-world:module
33+
34+
publish:
35+
if: github.event_name == 'release'
36+
runs-on: ubuntu-24.04
37+
needs:
38+
- build
39+
permissions:
40+
contents: write
41+
steps:
42+
- uses: actions/checkout@v4
43+
- name: Download all workflow run artifacts
44+
uses: actions/download-artifact@v4
45+
with:
46+
path: artifacts
47+
- name: Upload release assets
48+
env:
49+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
run: |
51+
for artifact in artifacts/*; do
52+
[[ ! -d "$artifact" ]] && continue
53+
name=$(basename "$artifact")
54+
file=$(ls "$artifact"/*.tar.xz)
55+
echo "Uploading $file as $name.tar.xz"
56+
gh release upload "${{ github.event.release.tag_name }}" \
57+
"$file#$name.tar.xz" \
58+
--clobber
59+
done

BUILD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
licenses(["notice"]) # Apache 2
2+
3+
pkg_tar(
4+
name = "modules",
5+
deps = [
6+
"//wasm:modules",
7+
],
8+
)

WORKSPACE

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
workspace(name = "envoy-modules")
2+
3+
load(":archives.bzl", "load_archives")
4+
load_archives()
5+
6+
load(":deps.bzl", "resolve_dependencies")
7+
resolve_dependencies()
8+
9+
load(":toolchains.bzl", "load_toolchains")
10+
load_toolchains()
11+
12+
load(":packages.bzl", "load_packages")
13+
load_packages()
14+
15+
load("@toolshed_pip3//:requirements.bzl", "install_deps")
16+
install_deps()

archives.bzl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
load("//:versions.bzl", "VERSIONS")
3+
4+
def load_github_archives():
5+
for k, v in VERSIONS.items():
6+
if type(v) == type("") or v.get("type") != "github_archive":
7+
continue
8+
kwargs = dict(name = k, **v)
9+
# Format string values, but not lists
10+
formatted_kwargs = {}
11+
for arg_k, arg_v in kwargs.items():
12+
if arg_k in ["repo", "type", "version"]:
13+
continue
14+
if type(arg_v) == type(""):
15+
formatted_kwargs[arg_k] = arg_v.format(**kwargs)
16+
else:
17+
formatted_kwargs[arg_k] = arg_v
18+
http_archive(**formatted_kwargs)
19+
20+
def load_http_archives():
21+
for k, v in VERSIONS.items():
22+
if type(v) == type("") or v.get("type") != "http_archive":
23+
continue
24+
kwargs = dict(name = k, **v)
25+
# Format string values, but not lists
26+
formatted_kwargs = {}
27+
for arg_k, arg_v in kwargs.items():
28+
if arg_k in ["type", "version"]:
29+
continue
30+
if type(arg_v) == type(""):
31+
formatted_kwargs[arg_k] = arg_v.format(**kwargs)
32+
else:
33+
formatted_kwargs[arg_k] = arg_v
34+
http_archive(**formatted_kwargs)
35+
36+
def load_archives():
37+
load_github_archives()
38+
load_http_archives()

deps.bzl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
2+
load("@rules_perl//perl:deps.bzl", "perl_register_toolchains", "perl_rules_dependencies")
3+
load("@rules_python//python:repositories.bzl", "py_repositories")
4+
load("@toolchains_llvm//toolchain:deps.bzl", "bazel_toolchain_dependencies")
5+
load("@toolchains_llvm//toolchain:rules.bzl", "llvm_toolchain")
6+
load("//:versions.bzl", "VERSIONS")
7+
load("@envoy_toolshed//sysroot:sysroot.bzl", "setup_sysroots")
8+
9+
def resolve_dependencies(
10+
cmake_version=None,
11+
llvm_version=None,
12+
ninja_version=None,
13+
setup_autotools_toolchain=True):
14+
py_repositories()
15+
bazel_toolchain_dependencies()
16+
rules_foreign_cc_dependencies(
17+
register_preinstalled_tools = True,
18+
register_default_tools = True,
19+
cmake_version = cmake_version or VERSIONS["cmake"],
20+
ninja_version = ninja_version or VERSIONS["ninja"],
21+
)
22+
perl_rules_dependencies()
23+
perl_register_toolchains()
24+
setup_sysroots()
25+
llvm_toolchain(
26+
name = "llvm_toolchain",
27+
llvm_version = llvm_version or VERSIONS["llvm"],
28+
sysroot = {
29+
"linux-x86_64": "@sysroot_linux_amd64//:sysroot",
30+
"linux-aarch64": "@sysroot_linux_arm64//:sysroot",
31+
}
32+
)

packages.bzl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("@bazel_features//:deps.bzl", "bazel_features_deps")
2+
load("@rules_python//python:pip.bzl", "pip_parse")
3+
load("//:versions.bzl", "VERSIONS")
4+
5+
def load_packages():
6+
# This is empty - it should be overridden in your repo
7+
pip_parse(
8+
name = "toolshed_pip3",
9+
requirements_lock = "@envoy_toolshed//:requirements.txt",
10+
python_interpreter_target = "@python3_12_host//:python",
11+
)
12+
bazel_features_deps()

toolchains.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains")
2+
load("@rules_python//python:repositories.bzl", "python_register_toolchains")
3+
load("//:versions.bzl", "VERSIONS")
4+
5+
def load_toolchains():
6+
llvm_register_toolchains()
7+
python_register_toolchains(
8+
name = "python%s" % VERSIONS["python"].replace(".", "_"),
9+
python_version = VERSIONS["python"].replace("-", "_"),
10+
)

versions.bzl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2+
VERSIONS = {
3+
"aspect_bazel_lib": {
4+
"type": "github_archive",
5+
"repo": "aspect-build/bazel-lib",
6+
"version": "2.16.0",
7+
"sha256": "092f841dd9ea8e736ea834f304877a25190a762d0f0a6c8edac9f94aac8bbf16",
8+
"strip_prefix": "bazel-lib-{version}",
9+
"url": "https://github.com/{repo}/archive/v{version}.tar.gz",
10+
},
11+
12+
"bazel_skylib": {
13+
"type": "github_archive",
14+
"repo": "bazelbuild/bazel-skylib",
15+
"version": "1.4.2",
16+
"sha256": "66ffd9315665bfaafc96b52278f57c7e2dd09f5ede279ea6d39b2be471e7e3aa",
17+
"url": "https://github.com/{repo}/releases/download/{version}/bazel-skylib-{version}.tar.gz",
18+
},
19+
20+
"envoy": {
21+
"type": "github_archive",
22+
"repo": "envoyproxy/envoy",
23+
"version": "60c29b959217d66ddb54732df78e45ec767df427",
24+
"sha256": "f2b3dec8eb49ab235ca3c60c60a6ea4b1bd58cc4f8ea9302f7bae817eb472d88",
25+
"urls": ["https://github.com/{repo}/archive/{version}.tar.gz"],
26+
"strip_prefix": "envoy-{version}",
27+
},
28+
29+
"envoy_toolshed": {
30+
"type": "github_archive",
31+
"repo": "envoyproxy/toolshed",
32+
"version": "0.3.3",
33+
"sha256": "1ac69d5b1cbc138f779fc3858f06a6777455136260e1144010f0b51880f69814",
34+
"urls": ["https://github.com/{repo}/archive/bazel-v{version}.tar.gz"],
35+
"patch_args": ["-p1"],
36+
"strip_prefix": "toolshed-bazel-v{version}/bazel",
37+
},
38+
39+
"rules_python": {
40+
"type": "github_archive",
41+
"repo": "bazelbuild/rules_python",
42+
"version": "1.4.1",
43+
"sha256": "9f9f3b300a9264e4c77999312ce663be5dee9a56e361a1f6fe7ec60e1beef9a3",
44+
"url": "https://github.com/{repo}/releases/download/{version}/{name}-{version}.tar.gz",
45+
"strip_prefix": "{name}-{version}",
46+
},
47+
48+
"rules_foreign_cc": {
49+
"type": "github_archive",
50+
"repo": "bazelbuild/rules_foreign_cc",
51+
"version": "0.14.0",
52+
"sha256": "e0f0ebb1a2223c99a904a565e62aa285bf1d1a8aeda22d10ea2127591624866c",
53+
"url": "https://github.com/{repo}/releases/download/{version}/{name}-{version}.tar.gz",
54+
"strip_prefix": "{name}-{version}",
55+
},
56+
57+
"toolchains_llvm": {
58+
"type": "github_archive",
59+
"repo": "bazel-contrib/toolchains_llvm",
60+
"version": "1.4.0",
61+
"sha256": "fded02569617d24551a0ad09c0750dc53a3097237157b828a245681f0ae739f8",
62+
"url": "https://github.com/{repo}/releases/download/v{version}/{name}-v{version}.tar.gz",
63+
"strip_prefix": "{name}-v{version}",
64+
},
65+
}

0 commit comments

Comments
 (0)