Skip to content

Commit a7c35a0

Browse files
authored
Add Bazel support. (#18)
Signed-off-by: Shikugawa <[email protected]> Signed-off-by: Piotr Sikora <[email protected]>
1 parent 3f46b8f commit a7c35a0

27 files changed

+1169
-1
lines changed

.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Force Bazel to use --target=wasm32-unknown-unknown.
2+
build --platforms=@io_bazel_rules_rust//rust/platform:wasm

.bazelversion

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

.github/workflows/rust.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,42 @@ jobs:
103103

104104
- name: Package (publish)
105105
run: cargo +nightly publish --dry-run --target=wasm32-unknown-unknown
106+
107+
bazel:
108+
runs-on: ubuntu-latest
109+
110+
steps:
111+
- uses: actions/checkout@v2
112+
113+
- name: Cache
114+
uses: actions/cache@v2
115+
with:
116+
path: |
117+
~/.cache/bazel
118+
~/.cache/bazelisk
119+
~/.cargo/.crates.toml
120+
~/.cargo/.crates2.json
121+
~/.cargo/bin
122+
~/.cargo/registry
123+
key: ${{ hashFiles('WORKSPACE', '.bazelrc', '.bazelversion', 'cargo/Cargo.lock') }}
124+
125+
- name: Build
126+
run: |
127+
bazelisk build //...
128+
129+
- name: Format (buildifier)
130+
run: |
131+
GO111MODULE=on go get -u github.com/bazelbuild/buildtools/[email protected]
132+
export PATH=$PATH:$(go env GOPATH)/bin
133+
buildifier -mode=check WORKSPACE
134+
buildifier -mode=check BUILD
135+
buildifier -mode=check examples/BUILD
136+
137+
- name: Format (cargo raze)
138+
run: |
139+
cargo install cargo-raze --version 0.3.8
140+
cp -p cargo/Cargo.lock .
141+
rm -rf cargo/
142+
cargo raze --output=cargo
143+
mv Cargo.lock cargo/
144+
git diff --exit-code

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
/bazel-*
12
/target
2-
Cargo.lock
3+
/Cargo.lock

BUILD

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load("@io_bazel_rules_rust//rust:rust.bzl", "rust_library")
2+
3+
rust_library(
4+
name = "proxy_wasm",
5+
srcs = glob(["src/*.rs"]),
6+
edition = "2018",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//cargo:hashbrown",
10+
"//cargo:log",
11+
"//cargo:wee_alloc",
12+
],
13+
)

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ lto = true
2121
opt-level = 3
2222
panic = "abort"
2323

24+
[raze]
25+
workspace_path = "//cargo"
26+
target = "wasm32-unknown-unknown"
27+
genmode = "Remote"
28+
29+
[raze.crates.log.'0.4.11']
30+
additional_flags = ["--cfg=atomic_cas"]
31+
2432
[[example]]
2533
name = "hello_world"
2634
path = "examples/hello_world.rs"

WORKSPACE

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
workspace(name = "proxy_wasm_rust_sdk")
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
http_archive(
6+
name = "bazel_skylib",
7+
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
8+
urls = [
9+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
10+
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
11+
],
12+
)
13+
14+
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
15+
16+
bazel_skylib_workspace()
17+
18+
http_archive(
19+
name = "io_bazel_rules_rust",
20+
sha256 = "484a2b2b67cd2d1fa1054876de7f8d291c4b203fd256bc8cbea14d749bb864ce",
21+
# Last commit where "out_binary = True" works.
22+
# See: https://github.com/bazelbuild/rules_rust/issues/386
23+
strip_prefix = "rules_rust-fda9a1ce6482973adfda022cadbfa6b300e269c3",
24+
url = "https://github.com/bazelbuild/rules_rust/archive/fda9a1ce6482973adfda022cadbfa6b300e269c3.tar.gz",
25+
)
26+
27+
load("@io_bazel_rules_rust//rust:repositories.bzl", "rust_repositories")
28+
29+
rust_repositories()
30+
31+
load("@io_bazel_rules_rust//:workspace.bzl", "bazel_version")
32+
33+
bazel_version(name = "bazel_version")
34+
35+
load("//cargo:crates.bzl", "raze_fetch_remote_crates")
36+
37+
raze_fetch_remote_crates()

cargo/BUILD

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
cargo-raze workspace build file.
3+
4+
DO NOT EDIT! Replaced on runs of cargo-raze
5+
"""
6+
package(default_visibility = ["//visibility:public"])
7+
8+
licenses([
9+
"notice" # See individual crates for specific licenses
10+
])
11+
alias(
12+
name = "chrono",
13+
actual = "@raze__chrono__0_4_13//:chrono",
14+
tags = ["cargo-raze"],
15+
)
16+
alias(
17+
name = "hashbrown",
18+
actual = "@raze__hashbrown__0_7_2//:hashbrown",
19+
tags = ["cargo-raze"],
20+
)
21+
alias(
22+
name = "log",
23+
actual = "@raze__log__0_4_11//:log",
24+
tags = ["cargo-raze"],
25+
)
26+
alias(
27+
name = "wee_alloc",
28+
actual = "@raze__wee_alloc__0_4_5//:wee_alloc",
29+
tags = ["cargo-raze"],
30+
)

cargo/Cargo.lock

Lines changed: 134 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)