Skip to content

Commit

Permalink
Merge branch 'main' into apple_silicon_ci
Browse files Browse the repository at this point in the history
  • Loading branch information
jsharpe authored Aug 23, 2024
2 parents f80d029 + d9367d2 commit 72cb6a4
Show file tree
Hide file tree
Showing 28 changed files with 510 additions and 57 deletions.
4 changes: 3 additions & 1 deletion .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
matrix:
platform: ["centos7", "debian10", "macos", "ubuntu2004", "windows"]
bazel: ["6.x", "7.x"]

tasks:
verify_targets:
name: "Verify build targets"
platform: ${{ platform }}
bazel: ${{ bazel }}
build_targets:
- "@rules_foreign_cc//toolchains:make_tool"
- "@rules_foreign_cc//toolchains/private:make_tool"
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module(
compatibility_level = 1,
)

bazel_dep(name = "bazel_features", version = "1.15.0")
bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "platforms", version = "0.0.5")
bazel_dep(name = "rules_python", version = "0.23.1")
Expand Down
4 changes: 4 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ local_repository(
path = "examples",
)

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()
Expand Down
4 changes: 4 additions & 0 deletions docs/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_depende

rules_foreign_cc_dependencies()

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

load("//:stardoc_repository.bzl", "stardoc_repository")

stardoc_repository()
Expand Down
6 changes: 2 additions & 4 deletions examples/third_party/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ test_suite(
"//cares:test_c_ares",
"//cares:test_c_ares_ios",
"//curl:curl_test_suite",
# Fails due to linker error in ffi (https://github.com/mesonbuild/meson/issues/12282)
# "//glib:glib_build_test",
"//glib:glib_build_test",
"//gn:gn_launch_test",
"//gperftools:test",
"//iconv:iconv_macos_build_test",
Expand All @@ -96,8 +95,7 @@ test_suite(
"//libpng:test_libpng",
"//libssh2:libssh2_build_test",
"//log4cxx:log4cxx_build_test",
# Fails due to linker argument error (https://github.com/mesonbuild/meson/issues/12282)
# "//mesa:mesa_build_test",
"//mesa:mesa_build_test",
"//openssl:openssl_test_suite",
"//pcre:pcre_build_test",
"//python:python_tests",
Expand Down
6 changes: 3 additions & 3 deletions examples/third_party/glib/glib_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def glib_repositories():
http_archive,
name = "glib",
build_file = Label("//glib:BUILD.glib.bazel"),
strip_prefix = "glib-2.75.0",
sha256 = "6dde8e55cc4a2c83d96797120b08bcffb5f645b2e212164ae22d63c40e0e6360",
url = "https://download.gnome.org/sources/glib/2.75/glib-2.75.0.tar.xz",
strip_prefix = "glib-2.77.0",
sha256 = "1897fd8ad4ebb523c32fabe7508c3b0b039c089661ae1e7917df0956a320ac4d",
url = "https://download.gnome.org/sources/glib/2.77/glib-2.77.0.tar.xz",
)
maybe(
http_archive,
Expand Down
31 changes: 31 additions & 0 deletions examples/third_party/zlib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake", "runnable_binary")

exports_files(
[
Expand All @@ -7,6 +8,15 @@ exports_files(
visibility = ["//visibility:public"],
)

filegroup(
name = "shared_usage_srcs",
srcs = [
"CMakeLists.txt",
"zlib-example.cpp",
],
visibility = ["//visibility:public"],
)

cc_binary(
name = "zlib_usage_example",
srcs = ["zlib-example.cpp"],
Expand All @@ -19,3 +29,24 @@ sh_test(
data = [":zlib_usage_example"],
visibility = ["//:__pkg__"],
)

cmake(
name = "zlib_shared_usage_example",
dynamic_deps = ["@zlib//:zlib_shared"],
lib_source = "shared_usage_srcs",
out_binaries = ["zlib-example"],
deps = ["@zlib//:zlib_static"],
)

runnable_binary(
name = "run-zlib-example",
binary = "zlib-example",
foreign_cc_target = ":zlib_shared_usage_example",
)

sh_test(
name = "test_shared_zlib",
srcs = ["test_shared_zlib.sh"],
data = [":run-zlib-example"],
visibility = ["//:__pkg__"],
)
51 changes: 51 additions & 0 deletions examples/third_party/zlib/BUILD.zlib.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -28,3 +29,53 @@ cmake(
"//conditions:default": ["libz.a"],
}),
)

cc_library(
name = "zlib_static",
srcs = [
"adler32.c",
"compress.c",
"crc32.c",
"deflate.c",
"gzclose.c",
"gzlib.c",
"gzread.c",
"gzwrite.c",
"infback.c",
"inffast.c",
"inflate.c",
"inftrees.c",
"trees.c",
"uncompr.c",
"zutil.c",
],
hdrs = [
"crc32.h",
"deflate.h",
"gzguts.h",
"inffast.h",
"inffixed.h",
"inflate.h",
"inftrees.h",
"trees.h",
"zconf.h",
"zlib.h",
"zutil.h",
],
copts = select({
"@platforms//os:windows": [],
"//conditions:default": [
"-Wno-deprecated-non-prototype",
"-Wno-unused-variable",
"-Wno-implicit-function-declaration",
],
}),
includes = ["."],
linkstatic = True,
)

cc_shared_library(
name = "zlib_shared",
shared_lib_name = "libz.so",
deps = ["zlib_static"],
)
13 changes: 13 additions & 0 deletions examples/third_party/zlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.15)

project(zlib-example)

find_package(ZLIB REQUIRED)

set(SRCS zlib-example.cpp)

add_executable(${PROJECT_NAME} ${SRCS})

target_link_libraries(${PROJECT_NAME} ZLIB::ZLIB)

install(TARGETS ${PROJECT_NAME} DESTINATION bin)
3 changes: 3 additions & 0 deletions examples/third_party/zlib/test_shared_zlib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

$(rlocation rules_foreign_cc/examples/cmake/zlib_shared_usage_example)
25 changes: 22 additions & 3 deletions foreign_cc/built_tools/make_build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ load(
"get_flags_info",
"get_tools_info",
)
load("//foreign_cc/private:detect_xcompile.bzl", "detect_xcompile")
load("//foreign_cc/private/framework:platform.bzl", "os_name")

def _make_tool_impl(ctx):
Expand Down Expand Up @@ -74,6 +75,25 @@ def _make_tool_impl(ctx):
if os_name(ctx) == "macos":
non_sysroot_ldflags += ["-undefined", "error"]

configure_options = [
"--without-guile",
"--with-guile=no",
"--disable-dependency-tracking",
"--prefix=$$INSTALLDIR$$",
]

install_cmd = ["./make install"]

xcompile_options = detect_xcompile(ctx)
if xcompile_options:
configure_options.extend(xcompile_options)

# We can't use make to install make when cross-compiling
install_cmd = [
"mkdir -p $$INSTALLDIR$$/bin",
"cp -p make $$INSTALLDIR$$/bin/make",
]

env.update({
"AR": absolute_ar,
"ARFLAGS": _join_flags_list(ctx.workspace_name, arflags),
Expand All @@ -85,11 +105,10 @@ def _make_tool_impl(ctx):

configure_env = " ".join(["%s=\"%s\"" % (key, value) for key, value in env.items()])
script = [
"%s ./configure --without-guile --with-guile=no --disable-dependency-tracking --prefix=$$INSTALLDIR$$" % configure_env,
"%s ./configure %s" % (configure_env, " ".join(configure_options)),
"cat build.cfg",
"./build.sh",
"./make install",
]
] + install_cmd

return built_tool_rule_impl(
ctx,
Expand Down
12 changes: 11 additions & 1 deletion foreign_cc/built_tools/pkgconfig_build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ load(
"get_flags_info",
"get_tools_info",
)
load("//foreign_cc/private:detect_xcompile.bzl", "detect_xcompile")
load("//foreign_cc/private/framework:platform.bzl", "os_name")
load("//toolchains/native_tools:tool_access.bzl", "get_make_data")

Expand Down Expand Up @@ -61,6 +62,15 @@ def _pkgconfig_tool_impl(ctx):

make_data = get_make_data(ctx)

configure_options = [
"--with-internal-glib",
"--prefix=$$INSTALLDIR$$",
]

xcompile_options = detect_xcompile(ctx)
if xcompile_options:
configure_options.extend(xcompile_options)

env.update({
"AR": absolute_ar,
"ARFLAGS": _join_flags_list(ctx.workspace_name, arflags),
Expand All @@ -73,7 +83,7 @@ def _pkgconfig_tool_impl(ctx):

configure_env = " ".join(["%s=\"%s\"" % (key, value) for key, value in env.items()])
script = [
"%s ./configure --with-internal-glib --prefix=$$INSTALLDIR$$" % configure_env,
"%s ./configure %s" % (configure_env, " ".join(configure_options)),
"%s" % make_data.path,
"%s install" % make_data.path,
]
Expand Down
10 changes: 10 additions & 0 deletions foreign_cc/built_tools/private/built_tools_framework.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ load("//foreign_cc/private:cc_toolchain_util.bzl", "absolutize_path_in_str")
load("//foreign_cc/private:detect_root.bzl", "detect_root")
load("//foreign_cc/private:framework.bzl", "get_env_prelude", "wrap_outputs")
load("//foreign_cc/private/framework:helpers.bzl", "convert_shell_script", "shebang")
load("//foreign_cc/private/framework:platform.bzl", "PLATFORM_CONSTRAINTS_RULE_ATTRIBUTES")

# Common attributes for all built_tool rules
FOREIGN_CC_BUILT_TOOLS_ATTRS = {
"configure_xcompile": attr.bool(
doc = (
"If this is set and an xcompile scenario is detected, pass the necessary autotools flags. (Only applies if autotools is used)"
),
default = False,
),
"env": attr.string_dict(
doc = "Environment variables to set during the build. This attribute is subject to make variable substitution.",
default = {},
Expand All @@ -26,6 +33,9 @@ FOREIGN_CC_BUILT_TOOLS_ATTRS = {
),
}

# this would be cleaner as x | y, but that's not supported in bazel 5.4.0
FOREIGN_CC_BUILT_TOOLS_ATTRS.update(PLATFORM_CONSTRAINTS_RULE_ATTRIBUTES)

# Common fragments for all built_tool rules
FOREIGN_CC_BUILT_TOOLS_FRAGMENTS = [
"apple",
Expand Down
1 change: 1 addition & 0 deletions foreign_cc/cmake.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ def _create_configure_script(configureParameters):

configure_script = create_cmake_script(
workspace_name = ctx.workspace_name,
current_label = ctx.label,
target_os = target_os_name(ctx),
target_arch = target_arch_name(ctx),
host_os = os_name(ctx),
Expand Down
11 changes: 11 additions & 0 deletions foreign_cc/configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ load(
)
load("//foreign_cc/private:configure_script.bzl", "create_configure_script")
load("//foreign_cc/private:detect_root.bzl", "detect_root")
load("//foreign_cc/private:detect_xcompile.bzl", "detect_xcompile")
load(
"//foreign_cc/private:framework.bzl",
"CC_EXTERNAL_RULE_ATTRIBUTES",
Expand Down Expand Up @@ -78,6 +79,10 @@ def _create_configure_script(configureParameters):
configure_prefix = "{} ".format(expand_locations_and_make_variables(ctx, ctx.attr.configure_prefix, "configure_prefix", data)) if ctx.attr.configure_prefix else ""
configure_options = [expand_locations_and_make_variables(ctx, option, "configure_option", data) for option in ctx.attr.configure_options] if ctx.attr.configure_options else []

xcompile_options = detect_xcompile(ctx)
if xcompile_options:
configure_options.extend(xcompile_options)

for target in ctx.attr.targets:
# Configure will have generated sources into `$BUILD_TMPDIR` so make sure we `cd` there
make_commands.append("{prefix}{make} {target} {args}".format(
Expand Down Expand Up @@ -187,6 +192,12 @@ def _attrs():
"configure_prefix": attr.string(
doc = "A prefix for the call to the `configure_command`.",
),
"configure_xcompile": attr.bool(
doc = (
"If this is set and an xcompile scenario is detected, pass the necessary autotools flags."
),
default = False,
),
"install_prefix": attr.string(
doc = (
"Install prefix, i.e. relative path to where to install the result of the build. " +
Expand Down
15 changes: 11 additions & 4 deletions foreign_cc/meson.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ def _create_meson_script(configureParameters):
cxxopts = (ctx.fragments.cpp.copts + ctx.fragments.cpp.cxxopts + getattr(ctx.attr, "copts", [])) or []

if copts:
script.append("##export_var## CFLAGS \"{}\"".format(" ".join(copts).replace("\"", "'")))
script.append("##export_var## CFLAGS \"{} ${{CFLAGS:-}}\"".format(" ".join(copts).replace("\"", "'")))
if cxxopts:
script.append("##export_var## CXXFLAGS \"{}\"".format(" ".join(cxxopts).replace("\"", "'")))
script.append("##export_var## CXXFLAGS \"{} ${{CXXFLAGS:-}}\"".format(" ".join(cxxopts).replace("\"", "'")))

flags = get_flags_info(ctx)
if flags.cxx_linker_executable:
script.append("##export_var## LDFLAGS \"{}\"".format(" ".join(flags.cxx_linker_executable).replace("\"", "'")))
script.append("##export_var## LDFLAGS \"{} ${{LDFLAGS:-}}\"".format(" ".join(flags.cxx_linker_executable).replace("\"", "'")))

script.append("##export_var## CMAKE {}".format(attrs.cmake_path))
script.append("##export_var## NINJA {}".format(attrs.ninja_path))
Expand All @@ -110,10 +110,13 @@ def _create_meson_script(configureParameters):

prefix = "{} ".format(expand_locations_and_make_variables(ctx, attrs.tool_prefix, "tool_prefix", data)) if attrs.tool_prefix else ""

script.append("{prefix}{meson} --prefix={install_dir} {options} {source_dir}".format(
setup_args_str = " ".join(expand_locations_and_make_variables(ctx, ctx.attr.setup_args, "setup_args", data))

script.append("{prefix}{meson} setup --prefix={install_dir} {setup_args} {options} {source_dir}".format(
prefix = prefix,
meson = attrs.meson_path,
install_dir = "$$INSTALLDIR$$",
setup_args = setup_args_str,
options = options_str,
source_dir = "$$EXT_BUILD_ROOT$$/" + root,
))
Expand Down Expand Up @@ -171,6 +174,10 @@ def _attrs():
mandatory = False,
default = {},
),
"setup_args": attr.string_list(
doc = "Arguments for the Meson setup command",
mandatory = False,
),
})
return attrs

Expand Down
Loading

0 comments on commit 72cb6a4

Please sign in to comment.