Skip to content

Commit

Permalink
feat(build) add bazel rules to build ngx-wasm-rs and ngx-rust
Browse files Browse the repository at this point in the history
  • Loading branch information
fffonion committed Aug 22, 2023
1 parent db6f6d2 commit 5aa2982
Show file tree
Hide file tree
Showing 19 changed files with 752 additions and 52 deletions.
7 changes: 7 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
build --incompatible_enable_cc_toolchain_resolution

common --color=yes
common --curses=auto

build --show_timestamps
build --worker_verbose
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.1.0
32 changes: 32 additions & 0 deletions .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Bazel build

on:
pull_request:
paths-ignore:
# ignore markdown files (CHANGELOG.md, README.md, etc.)
- '**/*.md'
push:
paths-ignore:
# ignore markdown files (CHANGELOG.md, README.md, etc.)
- '**/*.md'
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
tests:
name: Tests
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}

steps:
- name: Checkout source code
uses: actions/checkout@v3

- name: Build
run: bazel build :ngx_rust :ngx_wasm_rs_static :ngx_wasm_rs_shared --verbose_failures
120 changes: 120 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
load("@rules_rust//rust:defs.bzl", "rust_library")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@ngx_rust_crate_index//:defs.bzl", ngx_rust_aliases = "aliases", ngx_rust_all_crate_deps = "all_crate_deps")
load("@ngx_wasm_rs_crate_index//:defs.bzl", ngx_wasm_rs_aliases = "aliases", ngx_wasm_rs_all_crate_deps = "all_crate_deps")
load("//build:deps.bzl", "normalize_name")
load("//build:rust-nightly.bzl", "rust_shared_library_nightly", "rust_static_library_nightly")

# --//:ngx-wasm-rust-feature-wat=false
bool_flag(
name = "ngx-wasm-rust-feature-wat",
build_setting_default = False,
visibility = ["//visibility:public"],
)

config_setting(
name = "ngx-wasm-rust-feature-wat_flag",
flag_values = {
":ngx-wasm-rust-feature-wat": "true",
},
visibility = ["//visibility:public"],
)

# ngx-rust

filegroup(
name = "ngx_rust_srcs",
srcs = glob(
include = ["lib/ngx-rust/**"],
exclude = ["*.bazel"],
),
)

rust_library(
name = "ngx_rust",
srcs = [":ngx_rust_srcs"],
aliases = ngx_rust_aliases(),
proc_macro_deps = ngx_rust_all_crate_deps(
proc_macro = True,
),
visibility = ["//visibility:public"],
deps = ngx_rust_all_crate_deps(
normal = True,
),
)

# ngx-wasm-rs deps

# crate: the dependencies of the crate
ngx_wasm_rs_deps = {
"backtrace": ["c-api"],
"c-api": [],
"wat": ["c-api"],
}

[filegroup(
name = "ngx_wasm_rs_deps_%s_srcs" % normalize_name(dep),
srcs = glob(
include = ["lib/ngx-wasm-rs/lib/%s/**" % dep],
exclude = ["*.bazel"],
),
) for dep in ngx_wasm_rs_deps]

[rust_library(
name = "ngx_wasm_rs_deps_%s" % normalize_name(dep),
srcs = [":ngx_wasm_rs_deps_%s_srcs" % normalize_name(dep)],
aliases = ngx_wasm_rs_aliases() | {
":ngx_wasm_rs_deps_%s" % normalize_name(d): "ngx_wasm_%s" % normalize_name(d)
for d in ngx_wasm_rs_deps[dep]
},
proc_macro_deps = ngx_wasm_rs_all_crate_deps(
proc_macro = True,
),
deps = ngx_wasm_rs_all_crate_deps(
normal = True,
) + [":ngx_wasm_rs_deps_%s" % normalize_name(d) for d in ngx_wasm_rs_deps[dep]],
) for dep in ngx_wasm_rs_deps]

filegroup(
name = "ngx_wasm_rs_srcs",
srcs = glob(
include = ["lib/ngx-wasm-rs/src/**"],
exclude = ["*.bazel"],
),
)

# ngx-wasm-rs

rust_library_types = {
"static": rust_static_library_nightly,
"shared": rust_shared_library_nightly,
}

[rust_library_types[_type](
name = _type == "static" and "ngx_wasm_rs_" + _type or "ngx_wasm_rs",
srcs = [":ngx_wasm_rs_srcs"],
aliases = ngx_wasm_rs_aliases() | {
":ngx_wasm_rs_deps_backtrace": "ngx_wasm_backtrace",
} | select({
":ngx-wasm-rust-feature-wat_flag": {
":ngx_wasm_rs_deps_wat": "ngx_wasm_wat",
},
"//conditions:default": {},
}),
proc_macro_deps = ngx_wasm_rs_all_crate_deps(
proc_macro = True,
),
visibility = ["//visibility:public"],
deps = ngx_wasm_rs_all_crate_deps(
build = True,
normal = True,
) + [":ngx_wasm_rs_deps_backtrace"] + select({
":ngx-wasm-rust-feature-wat_flag": [":ngx_wasm_rs_deps_wat"],
"//conditions:default": [],
}),
) for _type in rust_library_types]

alias(
name = "ngx_wasm_rs_shared",
actual = ":ngx_wasm_rs",
)
64 changes: 32 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[workspace]
resolver = "2"

members = [
"lib/ngx-rust",
"t/lib/ngx-rust-tests",
Expand Down
13 changes: 13 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
workspace(name = "ngx_wasm_module")

load("//build:repos.bzl", "ngx_wasm_module_repositories")

ngx_wasm_module_repositories()

load("//build:deps.bzl", "ngx_wasm_module_dependencies")

ngx_wasm_module_dependencies(cargo_home_isolated = False) # use system `$CARGO_HOME` to speed up builds

load("//build:crates.bzl", "ngx_wasm_module_crates")

ngx_wasm_module_crates()
1 change: 1 addition & 0 deletions build/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package(default_visibility = ["//visibility:public"])
Loading

0 comments on commit 5aa2982

Please sign in to comment.