Skip to content

Commit

Permalink
Bazel: Enable hybrid mode for Bzlmod migration
Browse files Browse the repository at this point in the history
See https://bazel.build/versions/7.4.0/external/migration#hybrid-mode.

PiperOrigin-RevId: 692951204
Change-Id: Idf1680e4db98fa4668f4512e136c928e68514b67
  • Loading branch information
cblichmann authored and copybara-github committed Nov 4, 2024
1 parent a46325a commit bcd2876
Show file tree
Hide file tree
Showing 7 changed files with 3,967 additions and 44 deletions.
5 changes: 3 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Migration to Bzlmod is not ready yet, waiting for Protobuf to release 27.0
common --noenable_bzlmod
# Enable Bazel modules by default. Projects using Sandboxed API may still use
# a regular WORKSPACE ("Hybrid Mode").
common --enable_bzlmod

# Build in C++17 mode without a custom CROSSTOOL
build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
48 changes: 48 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module(
name = "com_google_sandboxed_api",
version = "20241101.0",
bazel_compatibility = [">=7.1.1"],
)

bazel_dep(
name = "abseil-cpp",
version = "20240722.0",
repo_name = "com_google_absl",
)
bazel_dep(
name = "abseil-py",
version = "2.1.0",
repo_name = "com_google_absl_py",
)
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(
name = "google_benchmark",
version = "1.8.5",
repo_name = "com_google_benchmark",
)
bazel_dep(
name = "googletest",
version = "1.15.2",
repo_name = "com_google_googletest",
)
bazel_dep(
name = "protobuf",
version = "28.2",
repo_name = "com_google_protobuf",
)
bazel_dep(name = "rules_proto", version = "6.0.2")
bazel_dep(name = "rules_python", version = "0.37.2")
3,817 changes: 3,817 additions & 0 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Workspace definition used when Bzlmod is disabled
workspace(name = "com_google_sandboxed_api")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
Expand Down
51 changes: 51 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Workspace definition used when Bzlmod is enabled
workspace(name = "com_google_sandboxed_api")

load("@bazel_skylib//lib:versions.bzl", "versions")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//sandboxed_api/bazel:sapi_deps.bzl", "sapi_non_module_deps")

versions.check(minimum_bazel_version = "7.1.1")

sapi_non_module_deps()

load(
"//sandboxed_api/bazel:llvm_config.bzl",
"llvm_disable_optional_support_deps",
)

llvm_disable_optional_support_deps()

# zlib, only needed for examples
http_archive(
name = "net_zlib",
build_file = "//sandboxed_api:bazel/external/zlib.BUILD",
patch_args = ["-p1"],
# This is a patch that removes the "OF" macro that is used in zlib function
# definitions. It is necessary, because libclang, the library used by the
# interface generator to parse C/C++ files contains a bug that manifests
# itself with macros like this.
# We are investigating better ways to avoid this issue. For most "normal"
# C and C++ headers, parsing just works.
patches = ["//sandboxed_api:bazel/external/zlib.patch"],
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1", # 2020-04-23
strip_prefix = "zlib-1.2.11",
urls = [
"https://mirror.bazel.build/zlib.net/zlib-1.2.11.tar.gz",
"https://www.zlib.net/zlib-1.2.11.tar.gz",
],
)
2 changes: 1 addition & 1 deletion sandboxed_api/bazel/proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Generates proto targets in various languages."""

load("@rules_proto//proto:defs.bzl", "proto_library")
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")

def _cc_proto_library_name_from_proto_name(name):
"""Converts proto name to cc_proto_library name.
Expand Down
87 changes: 46 additions & 41 deletions sandboxed_api/bazel/sapi_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,51 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//sandboxed_api/bazel:llvm_config.bzl", "llvm_configure")
load("//sandboxed_api/bazel:repositories.bzl", "autotools_repository")

def sapi_non_module_deps():
"""Loads non-modularized dependencies."""

# libcap
http_archive(
name = "org_kernel_libcap",
build_file = "@com_google_sandboxed_api//sandboxed_api:bazel/external/libcap.BUILD",
sha256 = "260b549c154b07c3cdc16b9ccc93c04633c39f4fb6a4a3b8d1fa5b8a9c3f5fe8", # 2019-04-16
strip_prefix = "libcap-2.27",
urls = ["https://www.kernel.org/pub/linux/libs/security/linux-privs/libcap2/libcap-2.27.tar.gz"],
)

# libffi
autotools_repository(
name = "org_sourceware_libffi",
build_file = "@com_google_sandboxed_api//sandboxed_api:bazel/external/libffi.BUILD",
sha256 = "653ffdfc67fbb865f39c7e5df2a071c0beb17206ebfb0a9ecb18a18f63f6b263", # 2019-11-02
strip_prefix = "libffi-3.3-rc2",
urls = ["https://github.com/libffi/libffi/releases/download/v3.3-rc2/libffi-3.3-rc2.tar.gz"],
)

# libunwind
autotools_repository(
name = "org_gnu_libunwind",
build_file = "@com_google_sandboxed_api//sandboxed_api:bazel/external/libunwind.BUILD",
configure_args = [
"--disable-documentation",
"--disable-minidebuginfo",
"--disable-shared",
"--enable-ptrace",
],
sha256 = "4a6aec666991fb45d0889c44aede8ad6eb108071c3554fcdff671f9c94794976", # 2021-12-01
strip_prefix = "libunwind-1.6.2",
urls = ["https://github.com/libunwind/libunwind/releases/download/v1.6.2/libunwind-1.6.2.tar.gz"],
)

# LLVM/libclang
maybe(
llvm_configure,
name = "llvm-project",
commit = "2c494f094123562275ae688bd9e946ae2a0b4f8b", # 2022-03-31
sha256 = "59b9431ae22f0ea5f2ce880925c0242b32a9e4f1ae8147deb2bb0fc19b53fa0d",
system_libraries = True, # Prefer system libraries
)

def sapi_deps():
"""Loads common dependencies needed to compile Sandboxed API."""

Expand Down Expand Up @@ -77,39 +122,6 @@ def sapi_deps():
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v28.2/protobuf-28.2.tar.gz"],
)

# libcap
http_archive(
name = "org_kernel_libcap",
build_file = "@com_google_sandboxed_api//sandboxed_api:bazel/external/libcap.BUILD",
sha256 = "260b549c154b07c3cdc16b9ccc93c04633c39f4fb6a4a3b8d1fa5b8a9c3f5fe8", # 2019-04-16
strip_prefix = "libcap-2.27",
urls = ["https://www.kernel.org/pub/linux/libs/security/linux-privs/libcap2/libcap-2.27.tar.gz"],
)

# libffi
autotools_repository(
name = "org_sourceware_libffi",
build_file = "@com_google_sandboxed_api//sandboxed_api:bazel/external/libffi.BUILD",
sha256 = "653ffdfc67fbb865f39c7e5df2a071c0beb17206ebfb0a9ecb18a18f63f6b263", # 2019-11-02
strip_prefix = "libffi-3.3-rc2",
urls = ["https://github.com/libffi/libffi/releases/download/v3.3-rc2/libffi-3.3-rc2.tar.gz"],
)

# libunwind
autotools_repository(
name = "org_gnu_libunwind",
build_file = "@com_google_sandboxed_api//sandboxed_api:bazel/external/libunwind.BUILD",
configure_args = [
"--disable-documentation",
"--disable-minidebuginfo",
"--disable-shared",
"--enable-ptrace",
],
sha256 = "4a6aec666991fb45d0889c44aede8ad6eb108071c3554fcdff671f9c94794976", # 2021-12-01
strip_prefix = "libunwind-1.6.2",
urls = ["https://github.com/libunwind/libunwind/releases/download/v1.6.2/libunwind-1.6.2.tar.gz"],
)

# GoogleTest/GoogleMock
maybe(
http_archive,
Expand All @@ -128,11 +140,4 @@ def sapi_deps():
urls = ["https://github.com/google/benchmark/archive/604f6fd3f4b34a84ec4eb4db81d842fa4db829cd.zip"],
)

# LLVM/libclang
maybe(
llvm_configure,
name = "llvm-project",
commit = "2c494f094123562275ae688bd9e946ae2a0b4f8b", # 2022-03-31
sha256 = "59b9431ae22f0ea5f2ce880925c0242b32a9e4f1ae8147deb2bb0fc19b53fa0d",
system_libraries = True, # Prefer system libraries
)
sapi_non_module_deps()

0 comments on commit bcd2876

Please sign in to comment.