Skip to content
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

feat(build) add bazel rules to build ngx-wasm-rs and ngx-rust #392

Closed
wants to merge 3 commits into from

Conversation

fffonion
Copy link

@fffonion fffonion commented Aug 22, 2023

This PR adds Bazel build rules to compile ngx-wasm-rs and ngx-rust that can be imported and used by Kong,
as directly calling cargo might break cross-compilation.

The rules_rust doesn't seem to parse the local redirection of depenendencies in Cargo.toml well so that
I have to manually add those dependencies. And it seems the secondary dependencies will also needs to
be in the top level Cargo.toml to make build happy. Let me know how do you feel about this workaround.

What's missing at present:

  • wat feature (currently not working due to "missing CMAKE_ROOT")
  • readme
  • reusable workflow

build/rust-nightly.bzl Outdated Show resolved Hide resolved
@thibaultcha
Copy link
Member

@fffonion Are you prepared to be responsible for changes in the Bazel structure as development of the module itself continues? I don't feel very good about merging a whole new build system that we aren't comfortable maintaining, so someone has to be prepared to help us maintain it. Are you?

build/README.md Outdated Show resolved Hide resolved
build/rust-nightly.bzl Outdated Show resolved Hide resolved
build/README.md Outdated Show resolved Hide resolved
run: bazel build :ngx_rust :ngx_wasm_rs_static :ngx_wasm_rs_shared --verbose_failures

- name: Display artifacts
run: ls -lh bazel-bin/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, we will need this to be a reusable workflow that we can invoke from ci.yml and ci-large.yml. Please follow the example with job-unit-tests.yml (or any of the job-*.yml reusable workflows we already have).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will leave this as a TODO for this PR once I finish the bazel part of it.

@fffonion
Copy link
Author

@thibaultcha This PR only intended to build the rust part of this project, but not all of the Nginx build system. And it won't replace the default cargo based build when using outside of Kong (CI, vanilla nginx). So it would need minimal maintainance once merged, the most part of work will be at Kong side. I'm happy to setup knowledge sessions with wasm team folks on this : )

@coveralls
Copy link

Pull Request Test Coverage Report for Build 5947539505

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 91.123%

Totals Coverage Status
Change from base Build 5946265600: 0.0%
Covered Lines: 7586
Relevant Lines: 8325

💛 - Coveralls

@@ -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
Copy link
Member

@thibaultcha thibaultcha Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This greps for the path ngx-wasm-rs as it is specified as a path, not a library name, you will have to find another way.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path name doesn't necessarily contain ngx-wasm-rs (for example the rust rule automatically export the file in lib under build dependency https://github.com/Kong/kong-ee/pull/6346/files#diff-5c8ca1cd9c76393e97326f7857dd2be6cd741552bab8e4413dbcad5b652a94ccR29). Well, it's probably not reliable to either test the path or the module name, as it may fasly match some other part in NGX_LD_OPT; how do you feel?

Copy link
Member

@thibaultcha thibaultcha Aug 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path name doesn't necessarily contain ngx-wasm-rs

It does when using the local development environment and when using ./configure with a source release of this module, hence why keeping it that way. For Bazel there will have to be another way of detecting this. Checking for both ngx-wasm-rs and ngx_wasm_rs is good enough too if it works.

@thibaultcha
Copy link
Member

Latest remnants of CI flakiness were fixed in main, so a rebase should get rid of these pesty failures here too! 👍🏼

@thibaultcha
Copy link
Member

thibaultcha commented Aug 28, 2023

Hmmm the PR comes from your fork, it seems we still have to adjust for that use-case. I hope #400 should fix it.

@fffonion
Copy link
Author

Thank you @thibaultcha ! I will make another rebase. I may continue to work on this PR on the TODO items shortly.

@thibaultcha
Copy link
Member

Hmmm that last failure is what I was afraid of, that the ghcr.io tag would also fetch upstream instead of just finding it locally... So that means we have to use a different tag when the GITHUB_TOKEN is missing...

@fffonion
Copy link
Author

@thibaultcha Is there anything I can setup on my fork to fix it? I understand secrets of GHA for fork is such a headache.

@thibaultcha
Copy link
Member

@fffonion Give it another rebase since the last update I put in there yesterday, it should work as I tested it, short of something specific I didn't foresee.

@@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these dependencies duplicated here? Cargo resolves hierarchical dependencies nicely, no need to specify this twice.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the workaround for bazel's rust rule, it doesn't use cargo cli directly and doesn't resolve hierachical dependecies like cargo did 😢 .

@thibaultcha thibaultcha added the pr/needs-rebase PR: Needs a rebase label Nov 16, 2023
@@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 -E -q "ngx_wasm_rs|ngx-wasm-rs"; then

Cargo.lock Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/needs-rebase PR: Needs a rebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants