From 8c6345fcef9535476123bb2515e5b5b2b961517d Mon Sep 17 00:00:00 2001 From: Wangchong Zhou Date: Wed, 2 Aug 2023 22:28:36 -0700 Subject: [PATCH] feat(build) add bazel rules to build ngx-wasm-rs and ngx-rust --- .bazelrc | 7 + .bazelversion | 1 + .github/workflows/bazel.yml | 35 ++++ BUILD.bazel | 145 +++++++++++++++ Cargo.toml | 1 + WORKSPACE | 13 ++ build/BUILD.bazel | 1 + build/README.md | 55 ++++++ build/crates.bzl | 8 + build/deps.bzl | 52 ++++++ build/platform/BUILD.bazel | 8 + build/repos.bzl | 19 ++ build/toolchain/BUILD | 97 ++++++++++ build/toolchain/cc_toolchain_config.bzl | 227 ++++++++++++++++++++++++ config | 2 +- lib/ngx-rust/Cargo.lock | 1 + lib/ngx-wasm-rs/Cargo.lock | 18 +- lib/ngx-wasm-rs/Cargo.toml | 4 + 18 files changed, 685 insertions(+), 9 deletions(-) create mode 100644 .bazelrc create mode 100644 .bazelversion create mode 100644 .github/workflows/bazel.yml create mode 100644 BUILD.bazel create mode 100644 WORKSPACE create mode 100644 build/BUILD.bazel create mode 100644 build/README.md create mode 100644 build/crates.bzl create mode 100644 build/deps.bzl create mode 100644 build/platform/BUILD.bazel create mode 100644 build/repos.bzl create mode 100644 build/toolchain/BUILD create mode 100644 build/toolchain/cc_toolchain_config.bzl diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 000000000..1830fba09 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,7 @@ +build --incompatible_enable_cc_toolchain_resolution + +common --color=yes +common --curses=auto + +build --show_timestamps +build --worker_verbose diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 000000000..dfda3e0b4 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +6.1.0 diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml new file mode 100644 index 000000000..5a7be08de --- /dev/null +++ b/.github/workflows/bazel.yml @@ -0,0 +1,35 @@ +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 + + - name: Display artifacts + run: ls -lh bazel-bin/ diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 000000000..aeeaad546 --- /dev/null +++ b/BUILD.bazel @@ -0,0 +1,145 @@ +load("@rules_rust//rust:defs.bzl", "rust_library", "rust_shared_library", "rust_static_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") + +filegroup( + name = "nginx_module_srcs", + srcs = glob(["src/**"]), + visibility = ["//visibility:public"], +) + +filegroup( + name = "lua_libs", + srcs = glob(["lib/resty/**"]), + visibility = ["//visibility:public"], +) + +filegroup( + name = "v8bridge_srcs", + srcs = glob(["lib/v8bridge/**"]), + visibility = ["//visibility:public"], +) + +filegroup( + name = "ngx_wasm_rs_headers", + srcs = glob(["lib/ngx-wasm-rs/include/**"]), + visibility = ["//visibility:public"], +) + +# --//: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, + "shared": rust_shared_library, +} + +[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": {}, + }), + crate_name = "ngx_wasm_rs", # force output filename to be libngx_wasm_rs.{a,so} + 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", + visibility = ["//visibility:public"], +) diff --git a/Cargo.toml b/Cargo.toml index e005eb0ec..446d4384b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] + members = [ "lib/ngx-rust", "t/lib/ngx-rust-tests", diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 000000000..51a564ecd --- /dev/null +++ b/WORKSPACE @@ -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() diff --git a/build/BUILD.bazel b/build/BUILD.bazel new file mode 100644 index 000000000..ffd0fb0cd --- /dev/null +++ b/build/BUILD.bazel @@ -0,0 +1 @@ +package(default_visibility = ["//visibility:public"]) diff --git a/build/README.md b/build/README.md new file mode 100644 index 000000000..335cc12dc --- /dev/null +++ b/build/README.md @@ -0,0 +1,55 @@ +# Bazel project for ngx_wasm_module Rust crates + +Note that you only need to import this rule when using either `wasmer` or `v8` runtime, which +requires the `ngx_wasm_rs` library. This rule is not required for `wasmtime` runtime. + +## Integration + +To use in other Bazel projects, add the following to your WORKSPACE file: + +```python + +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") + +git_repository( + name = "ngx_wasm_module", + branch = "some-tag", + remote = "https://github.com/Kong/ngx_wasm_module", +) + +load("@ngx_wasm_module//build:repos.bzl", "ngx_wasm_module_repositories") + +ngx_wasm_module_repositories() + +load("@ngx_wasm_module//build:deps.bzl", "ngx_wasm_module_dependencies") + +ngx_wasm_module_dependencies(cargo_home_isolated = False) # use system `$CARGO_HOME` to speed up builds + +load("@ngx_wasm_module//build:crates.bzl", "ngx_wasm_module_crates") + +ngx_wasm_module_crates() + +``` + +The following example shows how to build OpenResty with ngx_wasm_module with `wasmer` as runtime and link dynamically +to the `ngx_wasm_rs` library: + +```python +configure_make( + name = "openresty", + env = { + "NGX_WASM_RUNTIME": "wasmer", + "NGX_WASM_CARGO": "0", + } + configure_options = [ + "--with-cc-opt=\"-I$$EXT_BUILD_DEPS$$/ngx_wasm_rs/include\"", + "--with-ld-opt=\"-L$$EXT_BUILD_DEPS$$/ngx_wasm_rs/lib\"", + ], + # ... + deps = [ + "@ngx_wasm_module//:ngx_wasm_rs", + ], +) +``` + +When building this library in Bazel, use the `-c opt` flag to ensure optimal performance. The default fastbuild mode produces a less performant binary. diff --git a/build/crates.bzl b/build/crates.bzl new file mode 100644 index 000000000..5eb5b30e7 --- /dev/null +++ b/build/crates.bzl @@ -0,0 +1,8 @@ +"""Setup Crates repostories """ + +load("@ngx_rust_crate_index//:defs.bzl", ngx_rust_crate_repositories = "crate_repositories") +load("@ngx_wasm_rs_crate_index//:defs.bzl", ngx_wasm_rs_crate_repositories = "crate_repositories") + +def ngx_wasm_module_crates(): + ngx_rust_crate_repositories() + ngx_wasm_rs_crate_repositories() diff --git a/build/deps.bzl b/build/deps.bzl new file mode 100644 index 000000000..b9351870b --- /dev/null +++ b/build/deps.bzl @@ -0,0 +1,52 @@ +"""Setup dependencies after repostories are downloaded.""" + +load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains", "rust_repository_set") +load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies") +load("@rules_rust//crate_universe:defs.bzl", "crates_repository") + +def ngx_wasm_module_dependencies(cargo_home_isolated = True): + """ + ngx_wasm_module_dependencies setup rust toolchain and cargo dependency repositories. + + Args: + cargo_home_isolated (bool): cargo_home_isolated to False to reuse system CARGO_HOME + for faster builds. cargo_home_isolated is default False and will use isolated + Cargo home, which takes about 2 minutes to bootstrap. + """ + rules_rust_dependencies() + + rust_register_toolchains( + edition = "2018", + extra_target_triples = ["aarch64-unknown-linux-gnu"], + ) + + rust_repository_set( + name = "rust_linux_arm64_linux_tuple", + edition = "2018", + exec_triple = "x86_64-unknown-linux-gnu", + extra_target_triples = ["aarch64-unknown-linux-gnu"], + versions = ["stable"], + ) + + crate_universe_dependencies() + + crates_repository( + name = "ngx_rust_crate_index", + cargo_lockfile = "@ngx_wasm_module//:lib/ngx-rust/Cargo.lock", + manifests = [ + "@ngx_wasm_module//:lib/ngx-rust/Cargo.toml", + ], + isolated = cargo_home_isolated, + ) + + crates_repository( + name = "ngx_wasm_rs_crate_index", + cargo_lockfile = "@ngx_wasm_module//:lib/ngx-wasm-rs/Cargo.lock", + manifests = [ + "@ngx_wasm_module//:lib/ngx-wasm-rs/Cargo.toml", + ], + isolated = cargo_home_isolated, + ) + +def normalize_name(n): + return n.replace("-", "_") diff --git a/build/platform/BUILD.bazel b/build/platform/BUILD.bazel new file mode 100644 index 000000000..fe7b7b6b3 --- /dev/null +++ b/build/platform/BUILD.bazel @@ -0,0 +1,8 @@ +platform( + name = "linux-aarch64", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:arm64", + ], + visibility = ["//visibility:public"], +) diff --git a/build/repos.bzl b/build/repos.bzl new file mode 100644 index 000000000..1bcb399bb --- /dev/null +++ b/build/repos.bzl @@ -0,0 +1,19 @@ +"""Setup repostories.""" + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def ngx_wasm_module_repositories(): + http_archive( + name = "bazel_skylib", + sha256 = "66ffd9315665bfaafc96b52278f57c7e2dd09f5ede279ea6d39b2be471e7e3aa", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz", + ], + ) + + http_archive( + name = "rules_rust", + sha256 = "9d04e658878d23f4b00163a72da3db03ddb451273eb347df7d7c50838d698f49", + urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.26.0/rules_rust-v0.26.0.tar.gz"], + ) diff --git a/build/toolchain/BUILD b/build/toolchain/BUILD new file mode 100644 index 000000000..80430c738 --- /dev/null +++ b/build/toolchain/BUILD @@ -0,0 +1,97 @@ +load(":cc_toolchain_config.bzl", "cc_toolchain_config") + +package(default_visibility = ["//visibility:public"]) + +filegroup(name = "empty") + +################### +# aarch64-linux-gnu (installed with system) + +toolchain( + name = "gcc_cross_arm64_toolchain", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], + target_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:arm64", + ], + toolchain = ":gcc_cross_arm64_cc_toolchain", + toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", +) + +cc_toolchain_config( + name = "gcc_cross_arm64_cc_toolchain_config", + compiler_configuration = {}, + target_cpu = "aarch64", + toolchain_path_prefix = "/usr/aarch64-linux-gnu/", # is this required? + tools_path_prefix = "/usr/bin/aarch64-linux-gnu-", +) + +cc_toolchain( + name = "gcc_cross_arm64_cc_toolchain", + all_files = ":empty", + compiler_files = ":empty", + dwp_files = ":empty", + linker_files = ":empty", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 0, + toolchain_config = ":gcc_cross_arm64_cc_toolchain_config", + toolchain_identifier = "gcc_cross_arm64-toolchain", +) + +################### +# x86_64-linux-musl (downloaded by bazel) + +toolchain( + name = "gcc_cross_musl_x86_64_toolchain", + exec_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + ], + target_compatible_with = [ + "@platforms//os:linux", + "@platforms//cpu:x86_64", + "//:musl", + ], + toolchain = ":gcc_cross_musl_x86_64_cc_toolchain", + toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", +) + +cc_toolchain_config( + name = "gcc_cross_musl_x86_64_cc_toolchain_config", + target_cpu = "x86_64", + target_libc = "musl", + toolchain_path_prefix = "gcc-11-x86_64-linux-musl-wrappers/", # is this required? + tools_path_prefix = "gcc-11-x86_64-linux-musl-wrappers/x86_64-linux-musl-", +) + +filegroup( + name = "wrappers", + srcs = glob([ + "gcc-11-x86_64-linux-musl-wrappers/**", + ]), +) + +filegroup( + name = "musl_toolchain_files", + srcs = [ + ":wrappers", + "@gcc-11-x86_64-linux-musl-cross//:toolchain", + ], +) + +cc_toolchain( + name = "gcc_cross_musl_x86_64_cc_toolchain", + all_files = ":musl_toolchain_files", + compiler_files = ":musl_toolchain_files", + dwp_files = ":empty", + linker_files = ":musl_toolchain_files", + objcopy_files = ":empty", + strip_files = ":empty", + supports_param_files = 0, + toolchain_config = ":gcc_cross_musl_x86_64_cc_toolchain_config", + toolchain_identifier = "gcc_cross_musl_x86_64-toolchain", +) diff --git a/build/toolchain/cc_toolchain_config.bzl b/build/toolchain/cc_toolchain_config.bzl new file mode 100644 index 000000000..a1be00a85 --- /dev/null +++ b/build/toolchain/cc_toolchain_config.bzl @@ -0,0 +1,227 @@ +# Copyright 2021 The Bazel Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +load( + "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", + "action_config", + "tool", + "tool_path", +) +load( + "@bazel_tools//tools/build_defs/cc:action_names.bzl", + "CPP_LINK_EXECUTABLE_ACTION_NAME", +) + +# Bazel 4.* doesn't support nested starlark functions, so we cannot simplify +#_fmt_flags() by defining it as a nested function. +def _fmt_flags(flags, toolchain_path_prefix): + return [f.format(toolchain_path_prefix = toolchain_path_prefix) for f in flags] + +# Macro for calling cc_toolchain_config from @bazel_tools with setting the +# right paths and flags for the tools. +def _impl(ctx): + target_cpu = ctx.attr.target_cpu + toolchain_path_prefix = ctx.attr.toolchain_path_prefix + tools_path_prefix = ctx.attr.tools_path_prefix + compiler_configuration = ctx.attr.compiler_configuration + + # Unfiltered compiler flags; these are placed at the end of the command + # line, so take precendence over any user supplied flags through --copts or + # such. + unfiltered_compile_flags = [ + # Do not resolve our symlinked resource prefixes to real paths. + "-no-canonical-prefixes", + # Reproducibility + "-Wno-builtin-macro-redefined", + "-D__DATE__=\"redacted\"", + "-D__TIMESTAMP__=\"redacted\"", + "-D__TIME__=\"redacted\"", + "-fdebug-prefix-map={}=__bazel_toolchain__/".format(toolchain_path_prefix), + ] + + # Default compiler flags: + compile_flags = [ + # "--target=" + target_system_name, + # Security + "-U_FORTIFY_SOURCE", # https://github.com/google/sanitizers/issues/247 + "-fstack-protector", + "-fno-omit-frame-pointer", + # Diagnostics + "-fcolor-diagnostics", + "-Wall", + "-Wthread-safety", + "-Wself-assign", + ] + + dbg_compile_flags = ["-g", "-fstandalone-debug"] + + opt_compile_flags = [ + "-g0", + "-O2", + "-D_FORTIFY_SOURCE=1", + "-DNDEBUG", + "-ffunction-sections", + "-fdata-sections", + ] + + link_flags = [ + # "--target=" + target_system_name, + "-lm", + "-no-canonical-prefixes", + ] + + # Similar to link_flags, but placed later in the command line such that + # unused symbols are not stripped. + link_libs = [] + + # Note that for xcompiling from darwin to linux, the native ld64 is + # not an option because it is not a cross-linker, so lld is the + # only option. + + link_flags.extend([ + "-fuse-ld=lld", + "-Wl,--build-id=md5", + "-Wl,--hash-style=gnu", + "-Wl,-z,relro,-z,now", + ]) + + opt_link_flags = ["-Wl,--gc-sections"] + + # Coverage flags: + coverage_compile_flags = ["-fprofile-instr-generate", "-fcoverage-mapping"] + coverage_link_flags = ["-fprofile-instr-generate"] + + ## NOTE: framework paths is missing here; unix_cc_toolchain_config + ## doesn't seem to have a feature for this. + + # C++ built-in include directories: + cxx_builtin_include_directories = [ + "/usr/" + target_cpu + "-linux-gnu/include", + "/usr/lib/gcc-cross/" + target_cpu + "-linux-gnu/11/include", + ] + + # sysroot_path = compiler_configuration["sysroot_path"] + # sysroot_prefix = "" + # if sysroot_path: + # sysroot_prefix = "%sysroot%" + + # cxx_builtin_include_directories.extend([ + # sysroot_prefix + "/include", + # sysroot_prefix + "/usr/include", + # sysroot_prefix + "/usr/local/include", + # ]) + + if "additional_include_dirs" in compiler_configuration: + cxx_builtin_include_directories.extend(compiler_configuration["additional_include_dirs"]) + + ## NOTE: make variables are missing here; unix_cc_toolchain_config doesn't + ## pass these to `create_cc_toolchain_config_info`. + + # The tool names come from [here](https://github.com/bazelbuild/bazel/blob/c7e58e6ce0a78fdaff2d716b4864a5ace8917626/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java#L76-L90): + # NOTE: Ensure these are listed in toolchain_tools in toolchain/internal/common.bzl. + tool_paths = [ + tool_path( + name = "ar", + path = tools_path_prefix + "ar", + ), + tool_path( + name = "cpp", + path = tools_path_prefix + "g++", + ), + tool_path( + name = "gcc", + path = tools_path_prefix + "gcc", + ), + tool_path( + name = "gcov", + path = tools_path_prefix + "gcov", + ), + tool_path( + name = "ld", + path = tools_path_prefix + "lld", + ), + tool_path( + name = "nm", + path = tools_path_prefix + "nm", + ), + tool_path( + name = "objcopy", + path = tools_path_prefix + "objcopy", + ), + tool_path( + name = "objdump", + path = tools_path_prefix + "objdump", + ), + tool_path( + name = "strip", + path = tools_path_prefix + "strip", + ), + ] + + cxx_flags = [] + + # Replace flags with any user-provided overrides. + if "compile_flags" in compiler_configuration: + compile_flags = _fmt_flags(compiler_configuration["compile_flags"], toolchain_path_prefix) + if "cxx_flags" in compiler_configuration: + cxx_flags = _fmt_flags(compiler_configuration["cxx_flags"], toolchain_path_prefix) + if "link_flags" in compiler_configuration: + link_flags = _fmt_flags(compiler_configuration["link_flags"], toolchain_path_prefix) + if "link_libs" in compiler_configuration: + link_libs = _fmt_flags(compiler_configuration["link_libs"], toolchain_path_prefix) + if "opt_compile_flags" in compiler_configuration: + opt_compile_flags = _fmt_flags(compiler_configuration["opt_compile_flags"], toolchain_path_prefix) + if "opt_link_flags" in compiler_configuration: + opt_link_flags = _fmt_flags(compiler_configuration["opt_link_flags"], toolchain_path_prefix) + if "dbg_compile_flags" in compiler_configuration: + dbg_compile_flags = _fmt_flags(compiler_configuration["dbg_compile_flags"], toolchain_path_prefix) + if "coverage_compile_flags" in compiler_configuration: + coverage_compile_flags = _fmt_flags(compiler_configuration["coverage_compile_flags"], toolchain_path_prefix) + if "coverage_link_flags" in compiler_configuration: + coverage_link_flags = _fmt_flags(compiler_configuration["coverage_link_flags"], toolchain_path_prefix) + if "unfiltered_compile_flags" in compiler_configuration: + unfiltered_compile_flags = _fmt_flags(compiler_configuration["unfiltered_compile_flags"], toolchain_path_prefix) + + return cc_common.create_cc_toolchain_config_info( + ctx = ctx, + compiler = "gcc", + toolchain_identifier = target_cpu + "-linux-gnu", + host_system_name = "local", + target_cpu = target_cpu, + target_system_name = target_cpu + "-linux-gnu", + target_libc = ctx.attr.target_libc, + # abi_version = "unknown", + # abi_libc_version = "unknown", + cxx_builtin_include_directories = cxx_builtin_include_directories, + tool_paths = tool_paths, + action_configs = [ + action_config( + action_name = CPP_LINK_EXECUTABLE_ACTION_NAME, + enabled = True, + tools = [tool(path = tools_path_prefix + "lld")], + ), + ], + ) + +cc_toolchain_config = rule( + implementation = _impl, + attrs = { + "target_cpu": attr.string(), + "toolchain_path_prefix": attr.string(), + "tools_path_prefix": attr.string(), + "compiler_configuration": attr.string_list_dict(allow_empty = True, default = {}), + "target_libc": attr.string(default = "gnu"), + }, + provides = [CcToolchainConfigInfo], +) diff --git a/config b/config index dd13bc15d..f3ba07c52 100644 --- a/config +++ b/config @@ -102,7 +102,7 @@ if [ "$ngx_wasm_cargo_lib_name" = ngx_wasm_rs ]; then fi fi - if echo -n "$ngx_wasm_runtime_libs\n$NGX_LD_OPT" | grep -q "ngx-wasm-rs"; then + if echo -n "$ngx_wasm_runtime_libs\n$NGX_LD_OPT" | grep -q "ngx_wasm_rs"; then for d in $ngx_wasm_cargo_defines; do have=$d value=1 . auto/define done diff --git a/lib/ngx-rust/Cargo.lock b/lib/ngx-rust/Cargo.lock index 95aaa3e05..5b85dda52 100644 --- a/lib/ngx-rust/Cargo.lock +++ b/lib/ngx-rust/Cargo.lock @@ -1,5 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. + [[package]] name = "ngx" version = "0.1.0" diff --git a/lib/ngx-wasm-rs/Cargo.lock b/lib/ngx-wasm-rs/Cargo.lock index 24b235ed6..94c4bfd4a 100644 --- a/lib/ngx-wasm-rs/Cargo.lock +++ b/lib/ngx-wasm-rs/Cargo.lock @@ -96,9 +96,9 @@ checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "memchr" -version = "2.6.1" +version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f478948fd84d9f8e86967bf432640e46adfb5a4bd4f14ef7e864ab38220534ae" +checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" [[package]] name = "ngx-wasm" @@ -106,6 +106,8 @@ version = "0.1.0" dependencies = [ "ngx-wasm-backtrace", "ngx-wasm-wat", + "rustc-demangle", + "wasmparser", ] [[package]] @@ -159,9 +161,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.9.4" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29" +checksum = "697061221ea1b4a94a624f67d0ae2bfe4e22b8a17b6a192afb11046542cc8c47" dependencies = [ "aho-corasick", "memchr", @@ -171,9 +173,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629" +checksum = "c2f401f4955220693b56f8ec66ee9c78abffd8d1c4f23dc41a23839eb88f0795" dependencies = [ "aho-corasick", "memchr", @@ -231,9 +233,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.29" +version = "2.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" +checksum = "718fa2415bcb8d8bd775917a1bf12a7931b6dfa890753378538118181e0cb398" dependencies = [ "proc-macro2", "quote", diff --git a/lib/ngx-wasm-rs/Cargo.toml b/lib/ngx-wasm-rs/Cargo.toml index 70a027956..598f4c83f 100644 --- a/lib/ngx-wasm-rs/Cargo.toml +++ b/lib/ngx-wasm-rs/Cargo.toml @@ -8,6 +8,10 @@ edition = "2018" ngx-wasm-wat = { path = "lib/wat", optional = true } ngx-wasm-backtrace = { path = "lib/backtrace" } +# from backtrace +wasmparser = "0.102" +rustc-demangle = "0.1" + [features] wat = ["dep:ngx-wasm-wat"]