Skip to content

Commit

Permalink
Improved bzlmod extension to better control registered toolchains
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Jan 2, 2025
1 parent 92f81ee commit 77a857f
Show file tree
Hide file tree
Showing 27 changed files with 2,241 additions and 1,889 deletions.
49 changes: 22 additions & 27 deletions .bazelci/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,37 @@ tasks:
platform: ubuntu2004
build_targets:
- "//..."
- "@rules_foreign_cc_toolchains//..."
test_targets:
- "//..."
rbe_ubuntu2004:
platform: rbe_ubuntu2004
build_targets:
- "//..."
- "@rules_foreign_cc_toolchains//..."
test_targets:
- "//..."
macos:
platform: macos
build_targets:
- "//..."
- "@rules_foreign_cc_toolchains//..."
test_targets:
- "//..."
windows:
platform: windows
build_targets:
- "//..."
- "@rules_foreign_cc_toolchains//..."
test_targets:
- "//..."
# TODO: https://github.com/bazel-contrib/rules_foreign_cc/issues/495
- "-//test:shell_method_symlink_contents_to_dir_test"
- "-//test:shell_script_inner_fun_test"
build_flags:
- "--noenable_bzlmod"
- "--enable_workspace"
- "--config=no-bzlmod"
test_flags:
- "--noenable_bzlmod"
- "--enable_workspace"
- "--config=no-bzlmod"
ubuntu1804_examples_standalone:
name: Examples (spawn_strategy=standalone)
platform: ubuntu1804
Expand All @@ -54,8 +56,8 @@ tasks:
- "--spawn_strategy=standalone"
- "--noenable_bzlmod"
- "--enable_workspace"
ubuntu2004_examples:
name: Examples
ubuntu2004_examples_no_bzlmod:
name: Examples (No Bzlmod)
platform: ubuntu2004
working_directory: examples
linux_targets: &linux_targets
Expand All @@ -64,13 +66,11 @@ tasks:
build_targets: *linux_targets
test_targets: *linux_targets
build_flags:
- "--noenable_bzlmod"
- "--enable_workspace"
- "--config=no-bzlmod"
test_flags:
- "--noenable_bzlmod"
- "--enable_workspace"
ubuntu2004_examples_bzlmod:
name: Examples (bzlmod)
- "--config=no-bzlmod"
ubuntu2004_examples:
name: Examples
platform: ubuntu2004
working_directory: examples
linux_targets: &linux_targets_bzlmod
Expand All @@ -80,10 +80,7 @@ tasks:
- "-//cmake_android/..."
build_targets: *linux_targets_bzlmod
test_targets: *linux_targets_bzlmod
build_flags:
- "--enable_bzlmod"
rbe_ubuntu2004_examples:
name: Examples
platform: rbe_ubuntu2004
working_directory: examples
rbe_targets: &rbe_targets
Expand All @@ -95,6 +92,10 @@ tasks:
- "-//:requirements_test"
build_targets: *rbe_targets
test_targets: *rbe_targets
build_flags:
- "--config=no-bzlmod"
test_flags:
- "--config=no-bzlmod"
macos_examples_standalone:
name: Examples (spawn_strategy=standalone)
platform: macos
Expand All @@ -112,16 +113,14 @@ tasks:
- "dbg"
- "--spawn_strategy=standalone"
- "--noincompatible_enable_cc_toolchain_resolution"
- "--noenable_bzlmod"
- "--enable_workspace"
- "--config=no-bzlmod"
test_targets: *macos_targets_standalone
test_flags:
- "-c"
- "dbg"
- "--spawn_strategy=standalone"
- "--noincompatible_enable_cc_toolchain_resolution"
- "--noenable_bzlmod"
- "--enable_workspace"
- "--config=no-bzlmod"
macos_examples:
name: Examples
platform: macos
Expand All @@ -136,13 +135,11 @@ tasks:
build_targets: *macos_targets
build_flags:
- "--noincompatible_enable_cc_toolchain_resolution"
- "--noenable_bzlmod"
- "--enable_workspace"
- "--config=no-bzlmod"
test_targets: *macos_targets
test_flags:
- "--noincompatible_enable_cc_toolchain_resolution"
- "--noenable_bzlmod"
- "--enable_workspace"
- "--config=no-bzlmod"
windows_examples:
name: Examples
platform: windows
Expand Down Expand Up @@ -172,11 +169,9 @@ tasks:
build_targets: *windows_targets
test_targets: *windows_targets
build_flags:
- "--noenable_bzlmod"
- "--enable_workspace"
- "--config=no-bzlmod"
test_flags:
- "--noenable_bzlmod"
- "--enable_workspace"
- "--config=no-bzlmod"
rbe_ubuntu2004_flags:
name: Flags
platform: rbe_ubuntu2004
Expand Down
54 changes: 54 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
###############################################################################
## Bazel Configuration Flags
##
## `.bazelrc` is a Bazel configuration file.
## https://bazel.build/docs/best-practices#bazelrc-file
###############################################################################

# https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config
common --enable_platform_specific_config

# Enable the only currently supported report type
# https://bazel.build/reference/command-line-reference#flag--combined_report
coverage --combined_report=lcov

# Avoid fully cached builds reporting no coverage and failing CI
# https://bazel.build/reference/command-line-reference#flag--experimental_fetch_all_coverage_outputs
coverage --experimental_fetch_all_coverage_outputs

# Required for some of the tests
# https://bazel.build/reference/command-line-reference#flag--experimental_cc_shared_library
common --experimental_cc_shared_library

###############################################################################
## Incompatibility flags
###############################################################################

# https://github.com/bazelbuild/bazel/issues/8195
build --incompatible_disallow_empty_glob=true

# https://github.com/bazelbuild/bazel/issues/12821
build --nolegacy_external_runfiles

# Required for cargo_build_script support before Bazel 7
build --incompatible_merge_fixed_and_default_shell_env

###############################################################################
## Bzlmod
###############################################################################

# A configuration for disabling bzlmod.
common:no-bzlmod --noenable_bzlmod --enable_workspace

# Disable the bzlmod lockfile, so we don't accidentally commit MODULE.bazel.lock
common --lockfile_mode=off

###############################################################################
## Custom user flags
##
## This should always be the last thing in the `.bazelrc` file to ensure
## consistent behavior when setting flags in that file as `.bazelrc` files are
## evaluated top to bottom.
###############################################################################

try-import %workspace%/user.bazelrc
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ bazelci.py
#####
# Ignore all bazel-* symlinks. There is no full list since this can change
# based on the name of the directory bazel is cloned into.
user.bazelrc
/bazel-*
/docs/bazel-*
/examples/bazel-*
Expand Down
21 changes: 5 additions & 16 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"bazel-contrib/rules_foreign_cc"
"""bazel-contrib/rules_foreign_cc"""

module(
name = "rules_foreign_cc",
Expand Down Expand Up @@ -26,26 +26,15 @@ python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(python_version = "3.9")
use_repo(python, "python_3_9")

tools = use_extension("@rules_foreign_cc//foreign_cc:extensions.bzl", "tools")
foreign_cc = use_extension("@rules_foreign_cc//foreign_cc:extensions.bzl", "foreign_cc")
use_repo(
tools,
"cmake_3.23.2_toolchains",
"cmake_src",
"gettext_runtime",
"glib_dev",
"glib_src",
"gnumake_src",
"meson_src",
"ninja_1.12.1_toolchains",
"ninja_build_src",
"pkgconfig_src",
foreign_cc,
"rules_foreign_cc_framework_toolchains",
"rules_foreign_cc_toolchains",
)

register_toolchains(
"@rules_foreign_cc_framework_toolchains//:all",
"@cmake_3.23.2_toolchains//:all",
"@ninja_1.12.1_toolchains//:all",
"@rules_foreign_cc_toolchains//:all",
"@python_3_9//:all",
"@rules_foreign_cc//toolchains:all",
)
8 changes: 8 additions & 0 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,21 @@ stardoc(
deps = ["@rules_foreign_cc//foreign_cc:providers"],
)

stardoc(
name = "extensions_docs",
out = "src/extensions.md",
input = "@rules_foreign_cc//foreign_cc:extensions.bzl",
deps = ["@rules_foreign_cc//foreign_cc:extensions"],
)

DOCS_TARGETS = [
":cmake_docs",
":ninja_docs",
":make_docs",
":configure_make_docs",
":meson_docs",
":providers_docs",
":extensions_docs",
]

build_test(
Expand Down
Loading

0 comments on commit 77a857f

Please sign in to comment.