Skip to content

Conversation

@jjmaestro
Copy link
Contributor

  • Add support for targets to meson rule: Meson didn't support the targets attribute in CC_EXTERNAL_RULE_ATTRIBUTES that other rules use. This is useful for running other Meson commands such as meson test or meson introspection.

  • Add a new out_data_files output to be able to capture certain files from commands that don't yield the usual "compilation output".

  • Modify the outputs so that out_data_files can override all other outputs without failing (e.g. while forcing out_lib_dir and out_include_dir to "").

  • Add two simple tests to exercise the meson rule and the new support for Meson targets such as introspect.

@jjmaestro
Copy link
Contributor Author

jjmaestro commented Mar 23, 2025

@jsharpe I'm trying to debug the failure but I can't repro it easily :-/ Do you know if there's a simple way to run the same CI environment locally? e.g. if Buildkite has some CLI that would allow me to point it at the .bazelci config and request one of those "job types" to run in a local Docker container :-?

PS: I see the docker run command but it's full of --volume that I don't have e.g. /etc/passwd for the user and --volume /opt/android-ndk-r15c for the android stuff that ends up breaking when I try to do bazel build in the container:

ERROR: /src/workspace/examples/WORKSPACE.bzlmod:9:13: fetching android_ndk_repository rule
//external:androidndk: java.io.IOException: The repository's path is "/opt/android-ndk-r15c" 
(absolute: "/opt/android-ndk-r15c") but a symlink could not be created for it, because:
/opt/android-ndk-r15c (No such file or directory)

@jjmaestro
Copy link
Contributor Author

OK, I managed to get a Bazel build to work in my docker container commenting out a bunch of stuff in MODULE and adding the ignore_root_user_error:

diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel
index 97512a8..2fdb757 100644
--- a/examples/MODULE.bazel
+++ b/examples/MODULE.bazel
@@ -28,6 +28,7 @@ python.toolchain(
     # Only set when you have mulitple toolchain versions.
     is_default = True,
     python_version = "3.10",
+    ignore_root_user_error = True,
 )
 
 pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
diff --git a/examples/WORKSPACE.bazel b/examples/WORKSPACE.bazel
index e47cec2..355f4cf 100644
--- a/examples/WORKSPACE.bazel
+++ b/examples/WORKSPACE.bazel
@@ -17,10 +17,6 @@ load("//deps:repositories.bzl", "repositories")
 
 repositories()
 
-load("//deps:deps_android.bzl", "deps_android")
-
-deps_android()
-
 load("//deps:deps_jvm_external.bzl", "deps_jvm_external")
 
 deps_jvm_external()
@@ -36,6 +32,7 @@ protobuf_deps()
 python_register_toolchains(
     name = "python_3_10",
     python_version = "3.10",
+    ignore_root_user_error = True,
 )
 
 load("@rules_python//python:pip.bzl", "pip_parse")
diff --git a/examples/WORKSPACE.bzlmod b/examples/WORKSPACE.bzlmod
index 6cdd676..cac7926 100644
--- a/examples/WORKSPACE.bzlmod
+++ b/examples/WORKSPACE.bzlmod
@@ -4,10 +4,6 @@ load("//deps:repositories.bzl", "repositories")
 
 repositories()
 
-load("//deps:deps_android.bzl", "deps_android")
-
-deps_android()
-
 load("//deps:deps_jvm_external.bzl", "deps_jvm_external")
 
 deps_jvm_external()

I think the python root stuff has finally been fixed in the latest rules_python (bazel-contrib/rules_python#2636) but the Android stuff I'm not sure how it could be made optional. Ideally, it should not fail and the tests that depend on anything Android should not run if there's no Android config / volume available.

Anyway, if you have any ideas / know how to do this, please let me know. I'll be happy to work on this!

@jjmaestro jjmaestro force-pushed the feat-meson-additional-targets branch from 7fe5e98 to 8d1c8ec Compare March 23, 2025 11:49
@jsharpe
Copy link
Member

jsharpe commented Mar 31, 2025

@jsharpe I'm trying to debug the failure but I can't repro it easily :-/ Do you know if there's a simple way to run the same CI environment locally? e.g. if Buildkite has some CLI that would allow me to point it at the .bazelci config and request one of those "job types" to run in a local Docker container :-?

PS: I see the docker run command but it's full of --volume that I don't have e.g. /etc/passwd for the user and --volume /opt/android-ndk-r15c for the android stuff that ends up breaking when I try to do bazel build in the container:

ERROR: /src/workspace/examples/WORKSPACE.bzlmod:9:13: fetching android_ndk_repository rule
//external:androidndk: java.io.IOException: The repository's path is "/opt/android-ndk-r15c" 
(absolute: "/opt/android-ndk-r15c") but a symlink could not be created for it, because:
/opt/android-ndk-r15c (No such file or directory)

I don't know if there is a good way to reproduce the CI environment; its all defined in the bazelbuild/continuous-integration repo though if you want to try to reconstruct something locally from the scripts there..

@jsharpe
Copy link
Member

jsharpe commented Mar 31, 2025

OK, I managed to get a Bazel build to work in my docker container commenting out a bunch of stuff in MODULE and adding the ignore_root_user_error:

diff --git a/examples/MODULE.bazel b/examples/MODULE.bazel
index 97512a8..2fdb757 100644
--- a/examples/MODULE.bazel
+++ b/examples/MODULE.bazel
@@ -28,6 +28,7 @@ python.toolchain(
     # Only set when you have mulitple toolchain versions.
     is_default = True,
     python_version = "3.10",
+    ignore_root_user_error = True,
 )
 
 pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
diff --git a/examples/WORKSPACE.bazel b/examples/WORKSPACE.bazel
index e47cec2..355f4cf 100644
--- a/examples/WORKSPACE.bazel
+++ b/examples/WORKSPACE.bazel
@@ -17,10 +17,6 @@ load("//deps:repositories.bzl", "repositories")
 
 repositories()
 
-load("//deps:deps_android.bzl", "deps_android")
-
-deps_android()
-
 load("//deps:deps_jvm_external.bzl", "deps_jvm_external")
 
 deps_jvm_external()
@@ -36,6 +32,7 @@ protobuf_deps()
 python_register_toolchains(
     name = "python_3_10",
     python_version = "3.10",
+    ignore_root_user_error = True,
 )
 
 load("@rules_python//python:pip.bzl", "pip_parse")
diff --git a/examples/WORKSPACE.bzlmod b/examples/WORKSPACE.bzlmod
index 6cdd676..cac7926 100644
--- a/examples/WORKSPACE.bzlmod
+++ b/examples/WORKSPACE.bzlmod
@@ -4,10 +4,6 @@ load("//deps:repositories.bzl", "repositories")
 
 repositories()
 
-load("//deps:deps_android.bzl", "deps_android")
-
-deps_android()
-
 load("//deps:deps_jvm_external.bzl", "deps_jvm_external")
 
 deps_jvm_external()

I think the python root stuff has finally been fixed in the latest rules_python (bazel-contrib/rules_python#2636) but the Android stuff I'm not sure how it could be made optional. Ideally, it should not fail and the tests that depend on anything Android should not run if there's no Android config / volume available.

Anyway, if you have any ideas / know how to do this, please let me know. I'll be happy to work on this!

Yeah the hard fail from android is annoying - it actually never used to do this until I think bazel 5(or maybe 4? I don't recall exactly) came out which introduced that hard fail; I just tend to comment out the deps_android call as you've done to run locally.

@jjmaestro
Copy link
Contributor Author

Yeah the hard fail from android is annoying - it actually never used to do this until I think bazel 5(or maybe 4? I don't recall exactly) came out which introduced that hard fail; I just tend to comment out the deps_android call as you've done to run locally.

Maybe there's a way to gatekeep those and only try to load the dependencies if some flag is set... and then the flag could be just set for CI or something. In any case, commenting it out is a simple fix anyway so no worries.

Let me know what you think of the PR and if you want me to rebase it!

@jsharpe
Copy link
Member

jsharpe commented Apr 1, 2025

Yeah the hard fail from android is annoying - it actually never used to do this until I think bazel 5(or maybe 4? I don't recall exactly) came out which introduced that hard fail; I just tend to comment out the deps_android call as you've done to run locally.

Maybe there's a way to gatekeep those and only try to load the dependencies if some flag is set... and then the flag could be just set for CI or something. In any case, commenting it out is a simple fix anyway so no worries.

Let me know what you think of the PR and if you want me to rebase it!

The obvious way to resolve this is another workspace specifically for testing the android rules and only that one then needs to take the dependency on the android rules.

@jjmaestro jjmaestro force-pushed the feat-meson-additional-targets branch from 8d1c8ec to 9f2d8b9 Compare April 10, 2025 02:23
Meson didn't support the `targets` attribute in
`CC_EXTERNAL_RULE_ATTRIBUTES` that other rules use.

This is useful for running other Meson commands such as `meson test` or
`meson introspection`.
Add a new output to be able to capture certain files from commands that
don't yield the usual "compilation output".

Modify the outputs so that out_data_files can override all other outputs
without failing (e.g. while forcing out_lib_dir and out_include_dir to
"").
@jjmaestro jjmaestro force-pushed the feat-meson-additional-targets branch from 9f2d8b9 to 45f9178 Compare April 10, 2025 02:25
@jjmaestro
Copy link
Contributor Author

@jsharpe I've improved the "API" for the introspect command, so users can use the default args or provide custom introspect args, and provide an introspect filename.

Let me know what you think! Hopefully it's ready to merge :)

@jjmaestro jjmaestro force-pushed the feat-meson-additional-targets branch from 45f9178 to 69e531a Compare April 29, 2025 10:01
@jjmaestro
Copy link
Contributor Author

@jsharpe ping? 😄 could you have a quick look to see if you like the approach in the PR? 🙏 and if not, what should be changed? Thanks!!

Test meson rule and the new support for extra targets such as
introspect.
@jjmaestro jjmaestro force-pushed the feat-meson-additional-targets branch from 69e531a to 57b54f3 Compare April 29, 2025 10:14
@jjmaestro
Copy link
Contributor Author

I made a minor update trying to simplify the example and realized that because of the default values and default output group, it broke the tests. But I fixed that and there's still one CI job broken... it looks like something else broke and not something in the PR :-/

@jsharpe
Copy link
Member

jsharpe commented Apr 29, 2025

Sorry, I haven't forgotten about this, just had very little time recently to dedicate to this. Yeah looks like the CI flake was network related.

@jsharpe jsharpe enabled auto-merge (squash) May 12, 2025 22:30
@jsharpe jsharpe merged commit fcd644e into bazel-contrib:main May 12, 2025
2 checks passed
if args_ and target_name in target_args:
fail("Please migrate '{t}_args' to 'target_args[\"{t}\"]'".format(t = target_name))

target_args[target_name] = args_
Copy link
Contributor

Choose a reason for hiding this comment

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

from my testing, this will override any values I currently have set in target_args

Copy link
Contributor

Choose a reason for hiding this comment

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

created #1444

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right the code is wrong, but see my comments in the PR.

jjmaestro added a commit to monogres/monogres that referenced this pull request Nov 30, 2025
Extend the `pg_build()` rule to generate additional Meson introspection
targets on top of the regular Postgres build.

These targets invoke the [Meson `introspect` command] to emit JSON
metadata about the configuration of the build.

This metadata is useful for analyzing or programmatically extracting
parts of the Postgres build, such as contrib extensions.

NOTE: Bump `rules_foreign_cc` to v0.15.0 which is where [PR#1385] is
included ("feat: meson additional targets").

[Meson `introspect` command]: https://mesonbuild.com/Commands.html#introspect
[PR#1385]: bazel-contrib/rules_foreign_cc#1385
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants