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

Add bzlmod support files. #999

Merged
merged 4 commits into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .bazelci/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ tasks:
- "//:third_party_examples_linux_tests"
build_targets: *linux_targets
test_targets: *linux_targets
ubuntu2004_examples_bzlmod:
name: Examples (bzlmod)
Copy link
Collaborator

Choose a reason for hiding this comment

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

No MacOS or windows builds?

Copy link
Member Author

Choose a reason for hiding this comment

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

Most of the issues with bzlmod specific issues happen at analysis time; I initially have just left this scoped to linux just for the sake of keeping CI times down as macOS in particular is slow.

platform: ubuntu2004
working_directory: examples
linux_targets: &linux_targets_bzlmod
- "//..."
- "//:third_party_examples_linux_tests"
# gives error '//external:databinding_annotation_processor': target 'databinding_annotation_processor' not declared in package 'external' defined by /workdir/examples/WORKSPACE.bazel (Tip: use `query "//external:*"` to see all the targets in that package) and referenced by '@bazel_tools//tools/android:databinding_annotation_processor'
- "-//cmake_android/..."
build_targets: *linux_targets_bzlmod
test_targets: *linux_targets_bzlmod
build_flags:
- "--enable_bzlmod"
rbe_ubuntu1604_examples:
name: Examples
platform: rbe_ubuntu1604
Expand Down
3 changes: 3 additions & 0 deletions .bcr/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fixedReleaser:
login: jsharpe
email: [email protected]
13 changes: 13 additions & 0 deletions .bcr/metadata.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"homepage": "https://github.com/bazel-contrib/rules_cuda",
jsharpe marked this conversation as resolved.
Show resolved Hide resolved
"maintainers": [
{
"email": "[email protected]",
"github": "jsharpe",
"name": "James Sharpe"
}
],
"repository": ["github:bazel-contrib/rules_cuda"],
"versions": [],
"yanked_versions": {}
}
12 changes: 12 additions & 0 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# We recommend included a bcr test workspace that exercises your ruleset with bzlmod.
# For an example, see https://github.com/aspect-build/bazel-lib/tree/main/e2e/bzlmod.
jsharpe marked this conversation as resolved.
Show resolved Hide resolved
#bcr_test_module:
# module_path: "examples"
# matrix:
# platform: ["debian10", "macos", "ubuntu2004", "windows"]
# tasks:
# run_tests:
# name: "Run test module"
# platform: ${{ platform }}
# test_targets:
# - "//..."
5 changes: 5 additions & 0 deletions .bcr/source.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"integrity": "",
"strip_prefix": "{REPO}-{VERSION}",
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{VERSION}/{REPO}-{TAG}.tar.gz"
}
40 changes: 40 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"bazelbuild/rules_foreign_cc"

module(
name = "rules_foreign_cc",
version = "0.0.0",
compatibility_level = 1,
)

bazel_dep(name = "bazel_skylib", version = "1.1.1")
bazel_dep(name = "platforms", version = "0.0.5")
bazel_dep(name = "rules_python", version = "0.20.0")

tools = use_extension("@rules_foreign_cc//foreign_cc:extensions.bzl", "tools")
use_repo(
tools,
"cmake_3.23.2_toolchains",
"cmake_src",
"gnumake_src",
"ninja_1.11.1_toolchains",
"ninja_build_src",
"pkgconfig_src",
"rules_foreign_cc_framework_toolchain_freebsd",
"rules_foreign_cc_framework_toolchain_linux",
"rules_foreign_cc_framework_toolchain_macos",
"rules_foreign_cc_framework_toolchain_windows",
)

register_toolchains(
"@rules_foreign_cc_framework_toolchain_freebsd//:toolchain",
"@rules_foreign_cc_framework_toolchain_linux//:toolchain",
"@rules_foreign_cc_framework_toolchain_macos//:toolchain",
"@rules_foreign_cc_framework_toolchain_windows//:toolchain",
"@rules_foreign_cc//toolchains:built_make_toolchain",
"@rules_foreign_cc//toolchains:preinstalled_autoconf_toolchain",
"@rules_foreign_cc//toolchains:preinstalled_automake_toolchain",
"@rules_foreign_cc//toolchains:preinstalled_m4_toolchain",
"@rules_foreign_cc//toolchains:preinstalled_pkgconfig_toolchain",
"@cmake_3.23.2_toolchains//:all",
"@ninja_1.11.1_toolchains//:all",
)
20 changes: 20 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
workspace(name = "rules_foreign_cc")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazelci_rules",
sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e",
strip_prefix = "bazelci_rules-1.0.0",
url = "https://github.com/bazelbuild/continuous-integration/releases/download/rules-1.0.0/bazelci_rules-1.0.0.tar.gz",
)

load("@bazelci_rules//:rbe_repo.bzl", "rbe_preconfig")

# Creates a default toolchain config for RBE.
# Use this as is if you are using the rbe_ubuntu16_04 container,
# otherwise refer to RBE docs.
rbe_preconfig(
name = "buildkite_config",
toolchain = "ubuntu1804-bazel-java11",
)
32 changes: 32 additions & 0 deletions examples/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
bazel_dep(name = "rules_foreign_cc", version = "0.0.0")
local_path_override(
module_name = "rules_foreign_cc",
path = "..",
)

tools = use_extension("@rules_foreign_cc//foreign_cc:extensions.bzl", "tools")
tools.cmake(version = "3.23.1")
tools.ninja(version = "1.11.1")

bazel_dep(name = "platforms", version = "0.0.6")
bazel_dep(name = "rules_swift", version = "1.6.0", repo_name = "build_bazel_rules_swift")
bazel_dep(name = "rules_apple", version = "2.1.0", repo_name = "build_bazel_rules_apple")
bazel_dep(name = "apple_support", version = "1.4.1", repo_name = "build_bazel_apple_support")

# bazel_dep(name = "rules_android", version = "0.1.1")
# bazel_dep(name = "rules_jvm_external", version = "5.1")
#
# maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
#
# maven.install(
# name = "maven_deps",
# artifacts = [
# "com.android.support.constraint:constraint-layout:aar:1.1.2",
# "com.android.support:appcompat-v7:aar:26.1.0",
# ],
# repositories = [
# "https://jcenter.bintray.com/",
# "https://maven.google.com",
# "https://repo1.maven.org/maven2",
# ],
# )
12 changes: 10 additions & 2 deletions examples/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

maybe(
http_archive,
name = "rules_cc",
sha256 = "4dccbfd22c0def164c8f47458bd50e0c7148f3d92002cdb459c2a96a68498241",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.1/rules_cc-0.0.1.tar.gz"],
)

load("//deps:repositories.bzl", "repositories")

repositories()
Expand All @@ -38,8 +48,6 @@ load("@rules_foreign_cc_examples_third_party//:setup.bzl", examples_third_party_

examples_third_party_setup()

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazelci_rules",
sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e",
Expand Down
45 changes: 45 additions & 0 deletions examples/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
workspace(name = "rules_foreign_cc_examples")

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()

local_repository(
name = "rules_foreign_cc_examples_third_party",
path = "third_party",
)

load("@rules_foreign_cc_examples_third_party//:repositories.bzl", examples_third_party_repositories = "repositories")

examples_third_party_repositories()

load("@rules_foreign_cc_examples_third_party//:setup.bzl", examples_third_party_setup = "setup")

examples_third_party_setup()

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazelci_rules",
sha256 = "eca21884e6f66a88c358e580fd67a6b148d30ab57b1680f62a96c00f9bc6a07e",
strip_prefix = "bazelci_rules-1.0.0",
url = "https://github.com/bazelbuild/continuous-integration/releases/download/rules-1.0.0/bazelci_rules-1.0.0.tar.gz",
)

load("@bazelci_rules//:rbe_repo.bzl", "rbe_preconfig")

# Creates a default toolchain config for RBE.
# Use this as is if you are using the rbe_ubuntu16_04 container,
# otherwise refer to RBE docs.
rbe_preconfig(
name = "buildkite_config",
toolchain = "ubuntu1804-bazel-java11",
)
7 changes: 0 additions & 7 deletions examples/deps/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
def repositories():
"""Load all repositories needed for the targets of rules_foreign_cc_examples"""

maybe(
http_archive,
name = "rules_cc",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.1/rules_cc-0.0.1.tar.gz"],
sha256 = "4dccbfd22c0def164c8f47458bd50e0c7148f3d92002cdb459c2a96a68498241",
)

maybe(
http_archive,
name = "rules_android",
Expand Down
49 changes: 46 additions & 3 deletions foreign_cc/extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,51 @@
"""Entry point for extensions used by bzlmod."""

load("//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
load("//toolchains:prebuilt_toolchains.bzl", "prebuilt_toolchains")

def _init(_):
rules_foreign_cc_dependencies(register_toolchains = False, register_preinstalled_tools = False)
_DEFAULT_CMAKE_VERSION = "3.23.2"
_DEFAULT_NINJA_VERSION = "1.11.1"

ext = module_extension(implementation = _init)
cmake_toolchain_version = tag_class(attrs = {
"version": attr.string(doc = "The cmake version", default = _DEFAULT_CMAKE_VERSION),
})

ninja_toolchain_version = tag_class(attrs = {
"version": attr.string(doc = "The ninja version", default = _DEFAULT_NINJA_VERSION),
})

def _init(module_ctx):
rules_foreign_cc_dependencies(
register_toolchains = False,
register_built_tools = True,
register_default_tools = False,
register_preinstalled_tools = False,
register_built_pkgconfig_toolchain = True,
)

versions = {
"cmake": _DEFAULT_CMAKE_VERSION,
"ninja": _DEFAULT_NINJA_VERSION,
}

for mod in module_ctx.modules:
if not mod.is_root:
for toolchain in mod.tags.cmake:
versions["cmake"] = toolchain.version

for toolchain in mod.tags.ninja:
versions["ninja"] = toolchain.version

prebuilt_toolchains(
cmake_version = versions["cmake"],
ninja_version = versions["ninja"],
register_toolchains = False,
)

tools = module_extension(
implementation = _init,
tag_classes = {
"cmake": cmake_toolchain_version,
"ninja": ninja_toolchain_version,
},
)