-
Notifications
You must be signed in to change notification settings - Fork 259
feat: meson additional targets #1385
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
Merged
jsharpe
merged 6 commits into
bazel-contrib:main
from
jjmaestro:feat-meson-additional-targets
May 12, 2025
+269
−46
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
05fe8e1
feat[meson]: add support for targets
jjmaestro 3319c23
feat: add out_data_files output attribute
jjmaestro 57e6892
feat[meson]: introspect args helper
jjmaestro 57b54f3
test: add meson_simple test
jjmaestro 13ccdce
Merge branch 'main' into feat-meson-additional-targets
d6744e9
Merge branch 'main' into feat-meson-additional-targets
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| load("@rules_cc//cc:defs.bzl", "cc_test") | ||
| load("@rules_foreign_cc//foreign_cc:defs.bzl", "meson") | ||
| load("@rules_shell//shell:sh_test.bzl", "sh_test") | ||
|
|
||
| meson( | ||
| name = "meson_lib", | ||
| build_data = ["//meson_simple/code:clang_wrapper.sh"], | ||
| env = select({ | ||
| "//:windows": { | ||
| "CLANG_WRAPPER": "$(execpath //meson_simple/code:clang_wrapper.sh)", | ||
| "CXX_FLAGS": "/MD", | ||
| }, | ||
| "//conditions:default": { | ||
| "CLANG_WRAPPER": "$(execpath //meson_simple/code:clang_wrapper.sh)", | ||
| "CXX_FLAGS": "-fPIC", | ||
| }, | ||
| }), | ||
| lib_source = "//meson_simple/code:srcs", | ||
| out_static_libs = ["liba.a"], | ||
| ) | ||
|
|
||
| cc_test( | ||
| name = "test_lib", | ||
| srcs = [ | ||
| "test_libb.cpp", | ||
| ], | ||
| deps = [ | ||
| ":meson_lib", | ||
| ], | ||
| ) | ||
|
|
||
| meson( | ||
| name = "meson_lib-introspect", | ||
| lib_source = "//meson_simple/code:srcs", | ||
| out_data_files = ["introspect.json"], | ||
| out_include_dir = "", | ||
| targets = ["introspect"], | ||
| ) | ||
|
|
||
| sh_test( | ||
| name = "test_introspect", | ||
| srcs = ["test_introspect.sh"], | ||
| args = ["$(location meson_lib-introspect)"], | ||
| data = [":meson_lib-introspect"], | ||
| deps = ["@bazel_tools//tools/bash/runfiles"], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| exports_files(["clang_wrapper.sh"]) | ||
|
|
||
| filegroup( | ||
| name = "srcs", | ||
| srcs = [ | ||
| "liba.cpp", | ||
| "liba.h", | ||
| "meson.build", | ||
| ], | ||
| visibility = ["//meson_simple:__subpackages__"], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
|
|
||
| if [[ $(uname) == *"NT"* ]]; then | ||
| # If Windows | ||
| exec clang-cl "$@" | ||
| else | ||
| exec clang "$@" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #include "liba.h" | ||
|
|
||
| std::string hello_liba(void) { return "Hello from LIBA!"; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #ifndef LIBA_H_ | ||
| #define LIBA_H_ (1) | ||
|
|
||
| #include <stdio.h> | ||
|
|
||
| #include <string> | ||
|
|
||
| std::string hello_liba(void); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| project('liba', 'cpp') | ||
|
|
||
| builddir = 'rules_foreign_cc_build' | ||
|
|
||
| cxx = meson.get_compiler('cpp') | ||
|
|
||
| liba = static_library( | ||
| 'a', | ||
| 'liba.cpp', | ||
| cpp_args: cxx.get_supported_arguments(), | ||
| include_directories: include_directories('.'), | ||
| install: true, | ||
| install_dir: join_paths(get_option('prefix'), 'lib'), | ||
| ) | ||
|
|
||
| install_headers('liba.h', subdir: 'include') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # --- begin runfiles.bash initialization --- | ||
| # The runfiles library itself defines rlocation which you would need to look | ||
| # up the library's runtime location, thus we have a chicken-and-egg problem. | ||
| # | ||
| # Copy-pasted from Bazel's Bash runfiles library (tools/bash/runfiles/runfiles.bash). | ||
| set -euo pipefail | ||
| if [[ ! -d "${RUNFILES_DIR:-/dev/null}" && ! -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then | ||
| if [[ -f "$0.runfiles_manifest" ]]; then | ||
| export RUNFILES_MANIFEST_FILE="$0.runfiles_manifest" | ||
| elif [[ -f "$0.runfiles/MANIFEST" ]]; then | ||
| export RUNFILES_MANIFEST_FILE="$0.runfiles/MANIFEST" | ||
| elif [[ -f "$0.runfiles/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then | ||
| export RUNFILES_DIR="$0.runfiles" | ||
| fi | ||
| fi | ||
| if [[ -f "${RUNFILES_DIR:-/dev/null}/bazel_tools/tools/bash/runfiles/runfiles.bash" ]]; then | ||
| source "${RUNFILES_DIR}/bazel_tools/tools/bash/runfiles/runfiles.bash" | ||
| elif [[ -f "${RUNFILES_MANIFEST_FILE:-/dev/null}" ]]; then | ||
| source "$(grep -m1 "^bazel_tools/tools/bash/runfiles/runfiles.bash " \ | ||
| "$RUNFILES_MANIFEST_FILE" | cut -d ' ' -f 2-)" | ||
| else | ||
| echo >&2 "ERROR: cannot find @bazel_tools//tools/bash/runfiles:runfiles.bash" | ||
| exit 1 | ||
| fi | ||
| # --- end runfiles.bash initialization --- | ||
|
|
||
| [[ -f $(rlocation $TEST_WORKSPACE/$1) ]] && exit 0 | ||
| exit 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #include <iostream> | ||
| #include <stdexcept> | ||
| #include <string> | ||
|
|
||
| #include "include/liba.h" | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
| std::string result = hello_liba(); | ||
| if (result != "Hello from LIBA!") { | ||
| throw std::runtime_error("Wrong result: " + result); | ||
| } | ||
| std::cout << "Everything's fine!"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_argsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created #1444
There was a problem hiding this comment.
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.