mirror of https://github.com/bazelbuild/rules_cc
Fix buildifier warnings in @rules_cc
Fixes: * Enabled buildifier on the Bazel CI again * Added Skydocs where missing * Moved public files out of .../private/... (e.g. cc_toolchain_config_lib.bzl) * Reformatted * Removed unused loads * Using relative labels for cc_configure related files * Added development dependency on rules_proto * they're not in the federation yet, so hand rolling in rules_cc's WORKSPACE file * Added development dependency on rules_python (from federation) * Cleaned up copybara (notable change - not using @rules_cc in labels inside rules_cc repo) * Made cc_flags_supplier usable internally * Moved load statements to the top of the bzl file * Moved runfiles to the tools directory * Unified toolchain_utils.bzl and find_cc_toolchain.bzl RELNOTES: None. PiperOrigin-RevId: 276479521 Change-Id: I3196896061fa2ee61a3efb130c214d288782066a
This commit is contained in:
parent
0e66ef31d6
commit
262ebec3c2
|
@ -1,4 +1,7 @@
|
||||||
---
|
---
|
||||||
|
buildifier:
|
||||||
|
version: latest
|
||||||
|
warnings: "all"
|
||||||
platforms:
|
platforms:
|
||||||
ubuntu1604:
|
ubuntu1604:
|
||||||
run_targets:
|
run_targets:
|
||||||
|
|
22
WORKSPACE
22
WORKSPACE
|
@ -4,25 +4,29 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
name = "bazel_federation",
|
name = "bazel_federation",
|
||||||
url = "https://github.com/bazelbuild/bazel-federation/archive/f0e5eda7f0cbfe67f126ef4dacb18c89039b0506.zip", # 2019-09-30
|
|
||||||
sha256 = "33222ab7bcc430f1ff1db8788c2e0118b749319dd572476c4fd02322d7d15792",
|
sha256 = "33222ab7bcc430f1ff1db8788c2e0118b749319dd572476c4fd02322d7d15792",
|
||||||
strip_prefix = "bazel-federation-f0e5eda7f0cbfe67f126ef4dacb18c89039b0506",
|
strip_prefix = "bazel-federation-f0e5eda7f0cbfe67f126ef4dacb18c89039b0506",
|
||||||
type = "zip",
|
type = "zip",
|
||||||
|
url = "https://github.com/bazelbuild/bazel-federation/archive/f0e5eda7f0cbfe67f126ef4dacb18c89039b0506.zip", # 2019-09-30
|
||||||
)
|
)
|
||||||
|
|
||||||
load("@bazel_federation//:repositories.bzl", "rules_cc_deps")
|
load("@bazel_federation//:repositories.bzl", "rules_cc_deps")
|
||||||
|
|
||||||
rules_cc_deps()
|
rules_cc_deps()
|
||||||
|
|
||||||
load("@bazel_federation//setup:rules_cc.bzl", "rules_cc_setup")
|
load("@bazel_federation//setup:rules_cc.bzl", "rules_cc_setup")
|
||||||
|
|
||||||
rules_cc_setup()
|
rules_cc_setup()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Dependencies for development of rules_cc itself.
|
# Dependencies for development of rules_cc itself.
|
||||||
#
|
#
|
||||||
load("//:internal_deps.bzl", "rules_cc_internal_deps")
|
load("//:internal_deps.bzl", "rules_cc_internal_deps")
|
||||||
|
|
||||||
rules_cc_internal_deps()
|
rules_cc_internal_deps()
|
||||||
|
|
||||||
load("//:internal_setup.bzl", "rules_cc_internal_setup")
|
load("//:internal_setup.bzl", "rules_cc_internal_setup")
|
||||||
|
|
||||||
rules_cc_internal_setup()
|
rules_cc_internal_setup()
|
||||||
|
|
||||||
http_archive(
|
http_archive(
|
||||||
|
@ -34,3 +38,19 @@ http_archive(
|
||||||
"https://github.com/google/googletest/archive/release-1.10.0.tar.gz",
|
"https://github.com/google/googletest/archive/release-1.10.0.tar.gz",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
http_archive(
|
||||||
|
name = "rules_proto",
|
||||||
|
sha256 = "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
|
||||||
|
strip_prefix = "rules_proto-97d8af4dc474595af3900dd85cb3a29ad28cc313",
|
||||||
|
urls = [
|
||||||
|
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
|
||||||
|
"https://github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
|
||||||
|
|
||||||
|
rules_proto_dependencies()
|
||||||
|
|
||||||
|
rules_proto_toolchains()
|
||||||
|
|
6
cc/BUILD
6
cc/BUILD
|
@ -55,3 +55,9 @@ filegroup(
|
||||||
"//distro:__pkg__",
|
"//distro:__pkg__",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
cc_toolchain_alias(name = "current_cc_toolchain")
|
||||||
|
|
||||||
|
cc_host_toolchain_alias(name = "current_cc_host_toolchain")
|
||||||
|
|
||||||
|
cc_libc_top_alias(name = "current_libc_top")
|
||||||
|
|
26
cc/defs.bzl
26
cc/defs.bzl
|
@ -14,8 +14,8 @@
|
||||||
|
|
||||||
"""Starlark rules for building C++ projects."""
|
"""Starlark rules for building C++ projects."""
|
||||||
|
|
||||||
load("@rules_cc//cc/private/rules_impl:cc_flags_supplier.bzl", _cc_flags_supplier = "cc_flags_supplier")
|
load("//cc/private/rules_impl:cc_flags_supplier.bzl", _cc_flags_supplier = "cc_flags_supplier")
|
||||||
load("@rules_cc//cc/private/rules_impl:compiler_flag.bzl", _compiler_flag = "compiler_flag")
|
load("//cc/private/rules_impl:compiler_flag.bzl", _compiler_flag = "compiler_flag")
|
||||||
|
|
||||||
_MIGRATION_TAG = "__CC_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__"
|
_MIGRATION_TAG = "__CC_RULES_MIGRATION_DO_NOT_USE_WILL_BREAK__"
|
||||||
|
|
||||||
|
@ -34,6 +34,8 @@ def cc_binary(**attrs):
|
||||||
Args:
|
Args:
|
||||||
**attrs: Rule attributes
|
**attrs: Rule attributes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# buildifier: disable=native-cc
|
||||||
native.cc_binary(**_add_tags(attrs))
|
native.cc_binary(**_add_tags(attrs))
|
||||||
|
|
||||||
def cc_test(**attrs):
|
def cc_test(**attrs):
|
||||||
|
@ -44,6 +46,8 @@ def cc_test(**attrs):
|
||||||
Args:
|
Args:
|
||||||
**attrs: Rule attributes
|
**attrs: Rule attributes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# buildifier: disable=native-cc
|
||||||
native.cc_test(**_add_tags(attrs))
|
native.cc_test(**_add_tags(attrs))
|
||||||
|
|
||||||
def cc_library(**attrs):
|
def cc_library(**attrs):
|
||||||
|
@ -54,6 +58,8 @@ def cc_library(**attrs):
|
||||||
Args:
|
Args:
|
||||||
**attrs: Rule attributes
|
**attrs: Rule attributes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# buildifier: disable=native-cc
|
||||||
native.cc_library(**_add_tags(attrs))
|
native.cc_library(**_add_tags(attrs))
|
||||||
|
|
||||||
def cc_import(**attrs):
|
def cc_import(**attrs):
|
||||||
|
@ -64,6 +70,8 @@ def cc_import(**attrs):
|
||||||
Args:
|
Args:
|
||||||
**attrs: Rule attributes
|
**attrs: Rule attributes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# buildifier: disable=native-cc
|
||||||
native.cc_import(**_add_tags(attrs))
|
native.cc_import(**_add_tags(attrs))
|
||||||
|
|
||||||
def cc_proto_library(**attrs):
|
def cc_proto_library(**attrs):
|
||||||
|
@ -74,6 +82,8 @@ def cc_proto_library(**attrs):
|
||||||
Args:
|
Args:
|
||||||
**attrs: Rule attributes
|
**attrs: Rule attributes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# buildifier: disable=native-cc
|
||||||
native.cc_proto_library(**_add_tags(attrs))
|
native.cc_proto_library(**_add_tags(attrs))
|
||||||
|
|
||||||
def fdo_prefetch_hints(**attrs):
|
def fdo_prefetch_hints(**attrs):
|
||||||
|
@ -84,6 +94,8 @@ def fdo_prefetch_hints(**attrs):
|
||||||
Args:
|
Args:
|
||||||
**attrs: Rule attributes
|
**attrs: Rule attributes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# buildifier: disable=native-cc
|
||||||
native.fdo_prefetch_hints(**_add_tags(attrs))
|
native.fdo_prefetch_hints(**_add_tags(attrs))
|
||||||
|
|
||||||
def fdo_profile(**attrs):
|
def fdo_profile(**attrs):
|
||||||
|
@ -94,6 +106,8 @@ def fdo_profile(**attrs):
|
||||||
Args:
|
Args:
|
||||||
**attrs: Rule attributes
|
**attrs: Rule attributes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# buildifier: disable=native-cc
|
||||||
native.fdo_profile(**_add_tags(attrs))
|
native.fdo_profile(**_add_tags(attrs))
|
||||||
|
|
||||||
def cc_toolchain(**attrs):
|
def cc_toolchain(**attrs):
|
||||||
|
@ -104,6 +118,8 @@ def cc_toolchain(**attrs):
|
||||||
Args:
|
Args:
|
||||||
**attrs: Rule attributes
|
**attrs: Rule attributes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# buildifier: disable=native-cc
|
||||||
native.cc_toolchain(**_add_tags(attrs))
|
native.cc_toolchain(**_add_tags(attrs))
|
||||||
|
|
||||||
def cc_toolchain_suite(**attrs):
|
def cc_toolchain_suite(**attrs):
|
||||||
|
@ -114,6 +130,8 @@ def cc_toolchain_suite(**attrs):
|
||||||
Args:
|
Args:
|
||||||
**attrs: Rule attributes
|
**attrs: Rule attributes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# buildifier: disable=native-cc
|
||||||
native.cc_toolchain_suite(**_add_tags(attrs))
|
native.cc_toolchain_suite(**_add_tags(attrs))
|
||||||
|
|
||||||
def objc_library(**attrs):
|
def objc_library(**attrs):
|
||||||
|
@ -124,6 +142,8 @@ def objc_library(**attrs):
|
||||||
Args:
|
Args:
|
||||||
**attrs: Rule attributes
|
**attrs: Rule attributes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# buildifier: disable=native-cc
|
||||||
native.objc_library(**_add_tags(attrs))
|
native.objc_library(**_add_tags(attrs))
|
||||||
|
|
||||||
def objc_import(**attrs):
|
def objc_import(**attrs):
|
||||||
|
@ -134,6 +154,8 @@ def objc_import(**attrs):
|
||||||
Args:
|
Args:
|
||||||
**attrs: Rule attributes
|
**attrs: Rule attributes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# buildifier: disable=native-cc
|
||||||
native.objc_import(**_add_tags(attrs))
|
native.objc_import(**_add_tags(attrs))
|
||||||
|
|
||||||
def cc_flags_supplier(**attrs):
|
def cc_flags_supplier(**attrs):
|
||||||
|
|
|
@ -21,12 +21,17 @@ Returns the current `CcToolchainInfo`.
|
||||||
`--cpu`, `--compiler`). For that to work the rule needs to declare an
|
`--cpu`, `--compiler`). For that to work the rule needs to declare an
|
||||||
`_cc_toolchain` attribute, e.g.
|
`_cc_toolchain` attribute, e.g.
|
||||||
|
|
||||||
foo = rule(
|
foo = rule(
|
||||||
implementation = _foo_impl,
|
implementation = _foo_impl,
|
||||||
attrs = {
|
attrs = {
|
||||||
"_cc_toolchain": attr.label(default = Label("@rules_cc//cc/private/toolchain:current_cc_toolchain")),
|
"_cc_toolchain": attr.label(
|
||||||
|
default = Label(
|
||||||
|
"@rules_cc//cc/:current_cc_toolchain", # copybara-use-repo-external-label
|
||||||
|
),
|
||||||
|
),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
* When https://github.com/bazelbuild/bazel/issues/7260 **is** flipped, current
|
* When https://github.com/bazelbuild/bazel/issues/7260 **is** flipped, current
|
||||||
C++ toolchain is selected using the toolchain resolution mechanism
|
C++ toolchain is selected using the toolchain resolution mechanism
|
||||||
(`--platforms`). For that to work the rule needs to declare a dependency on
|
(`--platforms`). For that to work the rule needs to declare a dependency on
|
||||||
|
@ -34,14 +39,15 @@ foo = rule(
|
||||||
|
|
||||||
foo = rule(
|
foo = rule(
|
||||||
implementation = _foo_impl,
|
implementation = _foo_impl,
|
||||||
toolchains = ["@rules_cc//cc:toolchain_type"],
|
toolchains = [
|
||||||
|
"@rules_cc//cc:toolchain_type", # copybara-use-repo-external-label
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
We advise to depend on both `_cc_toolchain` attr and
|
We advise to depend on both `_cc_toolchain` attr and on the toolchain type for
|
||||||
`@rules_cc//cc:toolchain_type` for the duration of the migration. After
|
the duration of the migration. After
|
||||||
https://github.com/bazelbuild/bazel/issues/7260 is flipped (and support for old
|
https://github.com/bazelbuild/bazel/issues/7260 is flipped (and support for old
|
||||||
Bazel version is not needed), it's enough to only keep the
|
Bazel version is not needed), it's enough to only keep the toolchain type.
|
||||||
`@rules_cc//cc:toolchain_type`.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def find_cc_toolchain(ctx):
|
def find_cc_toolchain(ctx):
|
||||||
|
@ -57,13 +63,24 @@ Returns the current `CcToolchainInfo`.
|
||||||
|
|
||||||
# Check the incompatible flag for toolchain resolution.
|
# Check the incompatible flag for toolchain resolution.
|
||||||
if hasattr(cc_common, "is_cc_toolchain_resolution_enabled_do_not_use") and cc_common.is_cc_toolchain_resolution_enabled_do_not_use(ctx = ctx):
|
if hasattr(cc_common, "is_cc_toolchain_resolution_enabled_do_not_use") and cc_common.is_cc_toolchain_resolution_enabled_do_not_use(ctx = ctx):
|
||||||
if "@rules_cc//cc:toolchain_type" in ctx.toolchains:
|
if "//cc:toolchain_type" in ctx.toolchains:
|
||||||
return ctx.toolchains["@rules_cc//cc:toolchain_type"]
|
return ctx.toolchains["//cc:toolchain_type"]
|
||||||
fail("In order to use find_cc_toolchain, you must include the '@rules_cc//cc:toolchain_type' in the toolchains argument to your rule.")
|
fail("In order to use find_cc_toolchain, your rule has to depend on C++ toolchain. See find_cc_toolchain.bzl docs for details.")
|
||||||
|
|
||||||
# Fall back to the legacy implicit attribute lookup.
|
# Fall back to the legacy implicit attribute lookup.
|
||||||
if hasattr(ctx.attr, "_cc_toolchain"):
|
if hasattr(ctx.attr, "_cc_toolchain"):
|
||||||
return ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]
|
return ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]
|
||||||
|
|
||||||
# We didn't find anything.
|
# We didn't find anything.
|
||||||
fail("In order to use find_ccc_toolchain, you must define the '_cc_toolchain' attribute on your rule or aspect.")
|
fail("In order to use find_cc_toolchain, your rule has to depend on C++ toolchain. See find_cc_toolchain.bzl docs for details.")
|
||||||
|
|
||||||
|
def find_cpp_toolchain(ctx):
|
||||||
|
"""Deprecated, use `find_cc_toolchain` instead.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
ctx: See `find_cc_toolchain`.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
A CcToolchainInfo.
|
||||||
|
"""
|
||||||
|
return find_cc_toolchain(ctx)
|
||||||
|
|
|
@ -14,11 +14,11 @@
|
||||||
"""Rule that provides the CC_FLAGS Make variable."""
|
"""Rule that provides the CC_FLAGS Make variable."""
|
||||||
|
|
||||||
load("//cc:action_names.bzl", "CC_FLAGS_MAKE_VARIABLE_ACTION_NAME")
|
load("//cc:action_names.bzl", "CC_FLAGS_MAKE_VARIABLE_ACTION_NAME")
|
||||||
|
load("//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
|
||||||
load("//cc/private/rules_impl:cc_flags_supplier_lib.bzl", "build_cc_flags")
|
load("//cc/private/rules_impl:cc_flags_supplier_lib.bzl", "build_cc_flags")
|
||||||
load("//cc:toolchain_utils.bzl", "find_cpp_toolchain")
|
|
||||||
|
|
||||||
def _cc_flags_supplier_impl(ctx):
|
def _cc_flags_supplier_impl(ctx):
|
||||||
cc_toolchain = find_cpp_toolchain(ctx)
|
cc_toolchain = find_cc_toolchain(ctx)
|
||||||
cc_flags = build_cc_flags(ctx, cc_toolchain, CC_FLAGS_MAKE_VARIABLE_ACTION_NAME)
|
cc_flags = build_cc_flags(ctx, cc_toolchain, CC_FLAGS_MAKE_VARIABLE_ACTION_NAME)
|
||||||
variables = platform_common.TemplateVariableInfo({
|
variables = platform_common.TemplateVariableInfo({
|
||||||
"CC_FLAGS": cc_flags,
|
"CC_FLAGS": cc_flags,
|
||||||
|
@ -28,7 +28,7 @@ def _cc_flags_supplier_impl(ctx):
|
||||||
cc_flags_supplier = rule(
|
cc_flags_supplier = rule(
|
||||||
implementation = _cc_flags_supplier_impl,
|
implementation = _cc_flags_supplier_impl,
|
||||||
attrs = {
|
attrs = {
|
||||||
"_cc_toolchain": attr.label(default = Label("@rules_cc//cc/private/toolchain:current_cc_toolchain")),
|
"_cc_toolchain": attr.label(default = Label("@rules_cc//cc:current_cc_toolchain")),
|
||||||
},
|
},
|
||||||
toolchains = ["@rules_cc//cc:toolchain_type"],
|
toolchains = ["@rules_cc//cc:toolchain_type"],
|
||||||
fragments = ["cpp"],
|
fragments = ["cpp"],
|
||||||
|
|
|
@ -15,7 +15,15 @@
|
||||||
|
|
||||||
# This should match the logic in CcCommon.computeCcFlags:
|
# This should match the logic in CcCommon.computeCcFlags:
|
||||||
def build_cc_flags(ctx, cc_toolchain, action_name):
|
def build_cc_flags(ctx, cc_toolchain, action_name):
|
||||||
"""Determine the value for CC_FLAGS based on the given toolchain."""
|
"""Determine the value for CC_FLAGS based on the given toolchain.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
ctx: The rule context.
|
||||||
|
cc_toolchain: CcToolchainInfo instance.
|
||||||
|
action_name: Name of the action.
|
||||||
|
Returns:
|
||||||
|
string containing flags separated by a space.
|
||||||
|
"""
|
||||||
|
|
||||||
# Get default cc flags from toolchain's make_variables.
|
# Get default cc flags from toolchain's make_variables.
|
||||||
legacy_cc_flags = cc_common.legacy_cc_flags_make_variable_do_not_use(
|
legacy_cc_flags = cc_common.legacy_cc_flags_make_variable_do_not_use(
|
||||||
|
|
|
@ -14,16 +14,16 @@
|
||||||
|
|
||||||
"""Rule that allows select() to differentiate between compilers."""
|
"""Rule that allows select() to differentiate between compilers."""
|
||||||
|
|
||||||
load("@rules_cc//cc:toolchain_utils.bzl", "find_cpp_toolchain")
|
load("//cc:find_cc_toolchain.bzl", "find_cc_toolchain")
|
||||||
|
|
||||||
def _compiler_flag_impl(ctx):
|
def _compiler_flag_impl(ctx):
|
||||||
toolchain = find_cpp_toolchain(ctx)
|
toolchain = find_cc_toolchain(ctx)
|
||||||
return [config_common.FeatureFlagInfo(value = toolchain.compiler)]
|
return [config_common.FeatureFlagInfo(value = toolchain.compiler)]
|
||||||
|
|
||||||
compiler_flag = rule(
|
compiler_flag = rule(
|
||||||
implementation = _compiler_flag_impl,
|
implementation = _compiler_flag_impl,
|
||||||
attrs = {
|
attrs = {
|
||||||
"_cc_toolchain": attr.label(default = Label("@rules_cc//cc/private/toolchain:current_cc_toolchain")),
|
"_cc_toolchain": attr.label(default = Label("//cc:current_cc_toolchain")),
|
||||||
},
|
},
|
||||||
toolchains = ["@rules_cc//cc:toolchain_type"],
|
toolchains = ["//cc:toolchain_type"],
|
||||||
)
|
)
|
||||||
|
|
|
@ -51,12 +51,6 @@ constraint_value(
|
||||||
constraint_setting = ":cc_compiler",
|
constraint_setting = ":cc_compiler",
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_toolchain_alias(name = "current_cc_toolchain")
|
|
||||||
|
|
||||||
cc_host_toolchain_alias(name = "current_cc_host_toolchain")
|
|
||||||
|
|
||||||
cc_libc_top_alias(name = "current_libc_top")
|
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "malloc",
|
name = "malloc",
|
||||||
)
|
)
|
||||||
|
@ -86,17 +80,7 @@ alias(
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
name = "srcs",
|
name = "srcs",
|
||||||
srcs = glob(["**"]) + [
|
srcs = glob(["**"])
|
||||||
"//cc/private/toolchain/runfiles:srcs",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "embedded_tools",
|
|
||||||
srcs = glob(["**"]) + [
|
|
||||||
"//cc:action_names.bzl",
|
|
||||||
"//cc/private/toolchain/runfiles:embedded_tools",
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_toolchain", "cc_toolchain_suite")
|
||||||
|
|
||||||
package(default_visibility = ["//visibility:public"])
|
package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
load(":cc_toolchain_config.bzl", "cc_toolchain_config")
|
load(":cc_toolchain_config.bzl", "cc_toolchain_config")
|
||||||
|
@ -28,15 +30,13 @@ filegroup(
|
||||||
cc_toolchain_suite(
|
cc_toolchain_suite(
|
||||||
name = "toolchain",
|
name = "toolchain",
|
||||||
toolchains = {
|
toolchains = {
|
||||||
"local|local": ":local",
|
|
||||||
"local": ":local",
|
"local": ":local",
|
||||||
|
"local|local": ":local",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_toolchain(
|
cc_toolchain(
|
||||||
name = "local",
|
name = "local",
|
||||||
toolchain_identifier = "local",
|
|
||||||
toolchain_config = ":local_config",
|
|
||||||
all_files = ":empty",
|
all_files = ":empty",
|
||||||
ar_files = ":empty",
|
ar_files = ":empty",
|
||||||
as_files = ":empty",
|
as_files = ":empty",
|
||||||
|
@ -45,6 +45,8 @@ cc_toolchain(
|
||||||
linker_files = ":empty",
|
linker_files = ":empty",
|
||||||
objcopy_files = ":empty",
|
objcopy_files = ":empty",
|
||||||
strip_files = ":empty",
|
strip_files = ":empty",
|
||||||
|
toolchain_config = ":local_config",
|
||||||
|
toolchain_identifier = "local",
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_toolchain_config(name = "local_config")
|
cc_toolchain_config(name = "local_config")
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
|
|
||||||
package(default_visibility = ["//visibility:public"])
|
package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
|
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_toolchain", "cc_toolchain_suite")
|
||||||
load(":cc_toolchain_config.bzl", "cc_toolchain_config")
|
load(":cc_toolchain_config.bzl", "cc_toolchain_config")
|
||||||
load("@rules_cc//cc:defs.bzl", "cc_toolchain_suite", "cc_toolchain", "cc_library")
|
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "malloc",
|
name = "malloc",
|
||||||
|
@ -32,17 +32,15 @@ filegroup(
|
||||||
cc_toolchain_suite(
|
cc_toolchain_suite(
|
||||||
name = "toolchain",
|
name = "toolchain",
|
||||||
toolchains = {
|
toolchains = {
|
||||||
"armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a",
|
|
||||||
"freebsd|compiler": ":cc-compiler-freebsd",
|
|
||||||
"armeabi-v7a": ":cc-compiler-armeabi-v7a",
|
"armeabi-v7a": ":cc-compiler-armeabi-v7a",
|
||||||
|
"armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a",
|
||||||
"freebsd": ":cc-compiler-freebsd",
|
"freebsd": ":cc-compiler-freebsd",
|
||||||
|
"freebsd|compiler": ":cc-compiler-freebsd",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_toolchain(
|
cc_toolchain(
|
||||||
name = "cc-compiler-freebsd",
|
name = "cc-compiler-freebsd",
|
||||||
toolchain_identifier = "local_freebsd",
|
|
||||||
toolchain_config = ":local_freebsd",
|
|
||||||
all_files = ":empty",
|
all_files = ":empty",
|
||||||
ar_files = ":empty",
|
ar_files = ":empty",
|
||||||
as_files = ":empty",
|
as_files = ":empty",
|
||||||
|
@ -52,6 +50,8 @@ cc_toolchain(
|
||||||
objcopy_files = ":empty",
|
objcopy_files = ":empty",
|
||||||
strip_files = ":empty",
|
strip_files = ":empty",
|
||||||
supports_param_files = 0,
|
supports_param_files = 0,
|
||||||
|
toolchain_config = ":local_freebsd",
|
||||||
|
toolchain_identifier = "local_freebsd",
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_toolchain_config(
|
cc_toolchain_config(
|
||||||
|
@ -75,8 +75,6 @@ toolchain(
|
||||||
|
|
||||||
cc_toolchain(
|
cc_toolchain(
|
||||||
name = "cc-compiler-armeabi-v7a",
|
name = "cc-compiler-armeabi-v7a",
|
||||||
toolchain_identifier = "stub_armeabi-v7a",
|
|
||||||
toolchain_config = ":stub_armeabi-v7a",
|
|
||||||
all_files = ":empty",
|
all_files = ":empty",
|
||||||
ar_files = ":empty",
|
ar_files = ":empty",
|
||||||
as_files = ":empty",
|
as_files = ":empty",
|
||||||
|
@ -86,6 +84,8 @@ cc_toolchain(
|
||||||
objcopy_files = ":empty",
|
objcopy_files = ":empty",
|
||||||
strip_files = ":empty",
|
strip_files = ":empty",
|
||||||
supports_param_files = 0,
|
supports_param_files = 0,
|
||||||
|
toolchain_config = ":stub_armeabi-v7a",
|
||||||
|
toolchain_identifier = "stub_armeabi-v7a",
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_toolchain_config(
|
cc_toolchain_config(
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS")
|
load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS")
|
||||||
|
|
||||||
toolchain(
|
toolchain(
|
||||||
name = "cc-toolchain-%{name}",
|
name = "cc-toolchain-%{name}",
|
||||||
exec_compatible_with = HOST_CONSTRAINTS,
|
exec_compatible_with = HOST_CONSTRAINTS,
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
"""A Starlark cc_toolchain configuration rule"""
|
"""A Starlark cc_toolchain configuration rule"""
|
||||||
|
|
||||||
load(
|
load(
|
||||||
"@rules_cc//cc/private/toolchain:cc_toolchain_config_lib.bzl",
|
"@rules_cc//cc:cc_toolchain_config_lib.bzl",
|
||||||
"feature",
|
"feature",
|
||||||
"tool_path",
|
"tool_path",
|
||||||
)
|
)
|
||||||
|
|
|
@ -13,15 +13,15 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
"""Rules for configuring the C++ toolchain (experimental)."""
|
"""Rules for configuring the C++ toolchain (experimental)."""
|
||||||
|
|
||||||
load("@rules_cc//cc/private/toolchain:windows_cc_configure.bzl", "configure_windows_toolchain")
|
load("@bazel_tools//tools/osx:xcode_configure.bzl", "run_xcode_locator")
|
||||||
load("@rules_cc//cc/private/toolchain:osx_cc_configure.bzl", "configure_osx_toolchain")
|
|
||||||
load("@rules_cc//cc/private/toolchain:unix_cc_configure.bzl", "configure_unix_toolchain")
|
|
||||||
load(
|
load(
|
||||||
"@rules_cc//cc/private/toolchain:lib_cc_configure.bzl",
|
":lib_cc_configure.bzl",
|
||||||
"get_cpu_value",
|
"get_cpu_value",
|
||||||
"resolve_labels",
|
"resolve_labels",
|
||||||
)
|
)
|
||||||
load("@bazel_tools//tools/osx:xcode_configure.bzl", "run_xcode_locator")
|
load(":osx_cc_configure.bzl", "configure_osx_toolchain")
|
||||||
|
load(":unix_cc_configure.bzl", "configure_unix_toolchain")
|
||||||
|
load(":windows_cc_configure.bzl", "configure_windows_toolchain")
|
||||||
|
|
||||||
def _generate_cpp_only_build_file(repository_ctx, cpu_value, paths):
|
def _generate_cpp_only_build_file(repository_ctx, cpu_value, paths):
|
||||||
repository_ctx.template(
|
repository_ctx.template(
|
||||||
|
|
|
@ -14,16 +14,6 @@
|
||||||
|
|
||||||
"""A Starlark cc_toolchain configuration rule"""
|
"""A Starlark cc_toolchain configuration rule"""
|
||||||
|
|
||||||
load(
|
|
||||||
"@rules_cc//cc/private/toolchain:cc_toolchain_config_lib.bzl",
|
|
||||||
"action_config",
|
|
||||||
"feature",
|
|
||||||
"flag_group",
|
|
||||||
"flag_set",
|
|
||||||
"tool",
|
|
||||||
"tool_path",
|
|
||||||
"with_feature_set",
|
|
||||||
)
|
|
||||||
load(
|
load(
|
||||||
"@rules_cc//cc:action_names.bzl",
|
"@rules_cc//cc:action_names.bzl",
|
||||||
_ASSEMBLE_ACTION_NAME = "ASSEMBLE_ACTION_NAME",
|
_ASSEMBLE_ACTION_NAME = "ASSEMBLE_ACTION_NAME",
|
||||||
|
@ -40,6 +30,16 @@ load(
|
||||||
_LTO_BACKEND_ACTION_NAME = "LTO_BACKEND_ACTION_NAME",
|
_LTO_BACKEND_ACTION_NAME = "LTO_BACKEND_ACTION_NAME",
|
||||||
_PREPROCESS_ASSEMBLE_ACTION_NAME = "PREPROCESS_ASSEMBLE_ACTION_NAME",
|
_PREPROCESS_ASSEMBLE_ACTION_NAME = "PREPROCESS_ASSEMBLE_ACTION_NAME",
|
||||||
)
|
)
|
||||||
|
load(
|
||||||
|
"@rules_cc//cc:cc_toolchain_config_lib.bzl",
|
||||||
|
"action_config",
|
||||||
|
"feature",
|
||||||
|
"flag_group",
|
||||||
|
"flag_set",
|
||||||
|
"tool",
|
||||||
|
"tool_path",
|
||||||
|
"with_feature_set",
|
||||||
|
)
|
||||||
|
|
||||||
all_compile_actions = [
|
all_compile_actions = [
|
||||||
_C_COMPILE_ACTION_NAME,
|
_C_COMPILE_ACTION_NAME,
|
||||||
|
@ -209,6 +209,7 @@ def _impl(ctx):
|
||||||
|
|
||||||
builtin_sysroot = None
|
builtin_sysroot = None
|
||||||
|
|
||||||
|
objcopy_embed_data_action = None
|
||||||
if (ctx.attr.cpu == "darwin" or
|
if (ctx.attr.cpu == "darwin" or
|
||||||
ctx.attr.cpu == "freebsd" or
|
ctx.attr.cpu == "freebsd" or
|
||||||
ctx.attr.cpu == "local"):
|
ctx.attr.cpu == "local"):
|
||||||
|
@ -323,6 +324,7 @@ def _impl(ctx):
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
default_link_flags_feature = None
|
||||||
if (ctx.attr.cpu == "local"):
|
if (ctx.attr.cpu == "local"):
|
||||||
default_link_flags_feature = feature(
|
default_link_flags_feature = feature(
|
||||||
name = "default_link_flags",
|
name = "default_link_flags",
|
||||||
|
@ -416,6 +418,7 @@ def _impl(ctx):
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
unfiltered_compile_flags_feature = None
|
||||||
if (ctx.attr.cpu == "darwin" or
|
if (ctx.attr.cpu == "darwin" or
|
||||||
ctx.attr.cpu == "freebsd"):
|
ctx.attr.cpu == "freebsd"):
|
||||||
unfiltered_compile_flags_feature = feature(
|
unfiltered_compile_flags_feature = feature(
|
||||||
|
@ -509,6 +512,7 @@ def _impl(ctx):
|
||||||
|
|
||||||
supports_pic_feature = feature(name = "supports_pic", enabled = True)
|
supports_pic_feature = feature(name = "supports_pic", enabled = True)
|
||||||
|
|
||||||
|
default_compile_flags_feature = None
|
||||||
if (ctx.attr.cpu == "darwin"):
|
if (ctx.attr.cpu == "darwin"):
|
||||||
default_compile_flags_feature = feature(
|
default_compile_flags_feature = feature(
|
||||||
name = "default_compile_flags",
|
name = "default_compile_flags",
|
||||||
|
@ -939,6 +943,7 @@ def _impl(ctx):
|
||||||
|
|
||||||
dbg_feature = feature(name = "dbg")
|
dbg_feature = feature(name = "dbg")
|
||||||
|
|
||||||
|
user_compile_flags_feature = None
|
||||||
if (ctx.attr.cpu == "darwin" or
|
if (ctx.attr.cpu == "darwin" or
|
||||||
ctx.attr.cpu == "freebsd" or
|
ctx.attr.cpu == "freebsd" or
|
||||||
ctx.attr.cpu == "local"):
|
ctx.attr.cpu == "local"):
|
||||||
|
@ -994,6 +999,7 @@ def _impl(ctx):
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
sysroot_feature = None
|
||||||
if (ctx.attr.cpu == "darwin" or
|
if (ctx.attr.cpu == "darwin" or
|
||||||
ctx.attr.cpu == "freebsd" or
|
ctx.attr.cpu == "freebsd" or
|
||||||
ctx.attr.cpu == "local"):
|
ctx.attr.cpu == "local"):
|
||||||
|
@ -1131,6 +1137,7 @@ def _impl(ctx):
|
||||||
|
|
||||||
fastbuild_feature = feature(name = "fastbuild")
|
fastbuild_feature = feature(name = "fastbuild")
|
||||||
|
|
||||||
|
features = None
|
||||||
if (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64"):
|
if (ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "windows_msys64"):
|
||||||
features = [
|
features = [
|
||||||
default_compile_flags_feature,
|
default_compile_flags_feature,
|
||||||
|
@ -1475,8 +1482,8 @@ def _impl(ctx):
|
||||||
cc_toolchain_config = rule(
|
cc_toolchain_config = rule(
|
||||||
implementation = _impl,
|
implementation = _impl,
|
||||||
attrs = {
|
attrs = {
|
||||||
"cpu": attr.string(mandatory = True),
|
|
||||||
"compiler": attr.string(),
|
"compiler": attr.string(),
|
||||||
|
"cpu": attr.string(mandatory = True),
|
||||||
"disable_static_cc_toolchains": attr.bool(),
|
"disable_static_cc_toolchains": attr.bool(),
|
||||||
},
|
},
|
||||||
provides = [CcToolchainConfigInfo],
|
provides = [CcToolchainConfigInfo],
|
||||||
|
|
|
@ -14,8 +14,9 @@
|
||||||
|
|
||||||
"""A Starlark cc_toolchain configuration rule for freebsd."""
|
"""A Starlark cc_toolchain configuration rule for freebsd."""
|
||||||
|
|
||||||
|
load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES")
|
||||||
load(
|
load(
|
||||||
"@rules_cc//cc/private/toolchain:cc_toolchain_config_lib.bzl",
|
"@rules_cc//cc:cc_toolchain_config_lib.bzl",
|
||||||
"action_config",
|
"action_config",
|
||||||
"feature",
|
"feature",
|
||||||
"flag_group",
|
"flag_group",
|
||||||
|
@ -24,7 +25,6 @@ load(
|
||||||
"tool_path",
|
"tool_path",
|
||||||
"with_feature_set",
|
"with_feature_set",
|
||||||
)
|
)
|
||||||
load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES")
|
|
||||||
|
|
||||||
all_compile_actions = [
|
all_compile_actions = [
|
||||||
ACTION_NAMES.c_compile,
|
ACTION_NAMES.c_compile,
|
||||||
|
|
|
@ -115,25 +115,53 @@ def auto_configure_warning(msg):
|
||||||
"""Output warning message during auto configuration."""
|
"""Output warning message during auto configuration."""
|
||||||
yellow = "\033[1;33m"
|
yellow = "\033[1;33m"
|
||||||
no_color = "\033[0m"
|
no_color = "\033[0m"
|
||||||
|
|
||||||
|
# buildifier: disable=print
|
||||||
print("\n%sAuto-Configuration Warning:%s %s\n" % (yellow, no_color, msg))
|
print("\n%sAuto-Configuration Warning:%s %s\n" % (yellow, no_color, msg))
|
||||||
|
|
||||||
def get_env_var(repository_ctx, name, default = None, enable_warning = True):
|
def get_env_var(repository_ctx, name, default = None, enable_warning = True):
|
||||||
"""Find an environment variable in system path. Doesn't %-escape the value!"""
|
"""Find an environment variable in system path. Doesn't %-escape the value!
|
||||||
|
|
||||||
|
Args:
|
||||||
|
repository_ctx: The repository context.
|
||||||
|
name: Name of the environment variable.
|
||||||
|
default: Default value to be used when such environment variable is not present.
|
||||||
|
enable_warning: Show warning if the variable is not present.
|
||||||
|
Returns:
|
||||||
|
value of the environment variable or default.
|
||||||
|
"""
|
||||||
|
|
||||||
if name in repository_ctx.os.environ:
|
if name in repository_ctx.os.environ:
|
||||||
return repository_ctx.os.environ[name]
|
return repository_ctx.os.environ[name]
|
||||||
if default != None:
|
if default != None:
|
||||||
if enable_warning:
|
if enable_warning:
|
||||||
auto_configure_warning("'%s' environment variable is not set, using '%s' as default" % (name, default))
|
auto_configure_warning("'%s' environment variable is not set, using '%s' as default" % (name, default))
|
||||||
return default
|
return default
|
||||||
auto_configure_fail("'%s' environment variable is not set" % name)
|
return auto_configure_fail("'%s' environment variable is not set" % name)
|
||||||
|
|
||||||
def which(repository_ctx, cmd, default = None):
|
def which(repository_ctx, cmd, default = None):
|
||||||
"""A wrapper around repository_ctx.which() to provide a fallback value. Doesn't %-escape the value!"""
|
"""A wrapper around repository_ctx.which() to provide a fallback value. Doesn't %-escape the value!
|
||||||
|
|
||||||
|
Args:
|
||||||
|
repository_ctx: The repository context.
|
||||||
|
cmd: name of the executable to resolve.
|
||||||
|
default: Value to be returned when such executable couldn't be found.
|
||||||
|
Returns:
|
||||||
|
absolute path to the cmd or default when not found.
|
||||||
|
"""
|
||||||
result = repository_ctx.which(cmd)
|
result = repository_ctx.which(cmd)
|
||||||
return default if result == None else str(result)
|
return default if result == None else str(result)
|
||||||
|
|
||||||
def which_cmd(repository_ctx, cmd, default = None):
|
def which_cmd(repository_ctx, cmd, default = None):
|
||||||
"""Find cmd in PATH using repository_ctx.which() and fail if cannot find it. Doesn't %-escape the cmd!"""
|
"""Find cmd in PATH using repository_ctx.which() and fail if cannot find it. Doesn't %-escape the cmd!
|
||||||
|
|
||||||
|
Args:
|
||||||
|
repository_ctx: The repository context.
|
||||||
|
cmd: name of the executable to resolve.
|
||||||
|
default: Value to be returned when such executable couldn't be found.
|
||||||
|
Returns:
|
||||||
|
absolute path to the cmd or default when not found.
|
||||||
|
"""
|
||||||
result = repository_ctx.which(cmd)
|
result = repository_ctx.which(cmd)
|
||||||
if result != None:
|
if result != None:
|
||||||
return str(result)
|
return str(result)
|
||||||
|
@ -149,7 +177,16 @@ def execute(
|
||||||
command,
|
command,
|
||||||
environment = None,
|
environment = None,
|
||||||
expect_failure = False):
|
expect_failure = False):
|
||||||
"""Execute a command, return stdout if succeed and throw an error if it fails. Doesn't %-escape the result!"""
|
"""Execute a command, return stdout if succeed and throw an error if it fails. Doesn't %-escape the result!
|
||||||
|
|
||||||
|
Args:
|
||||||
|
repository_ctx: The repository context.
|
||||||
|
command: command to execute.
|
||||||
|
environment: dictionary with environment variables to set for the command.
|
||||||
|
expect_failure: True if the command is expected to fail.
|
||||||
|
Returns:
|
||||||
|
stdout of the executed command.
|
||||||
|
"""
|
||||||
if environment:
|
if environment:
|
||||||
result = repository_ctx.execute(command, environment = environment)
|
result = repository_ctx.execute(command, environment = environment)
|
||||||
else:
|
else:
|
||||||
|
@ -178,7 +215,13 @@ def execute(
|
||||||
return stripped_stdout
|
return stripped_stdout
|
||||||
|
|
||||||
def get_cpu_value(repository_ctx):
|
def get_cpu_value(repository_ctx):
|
||||||
"""Compute the cpu_value based on the OS name. Doesn't %-escape the result!"""
|
"""Compute the cpu_value based on the OS name. Doesn't %-escape the result!
|
||||||
|
|
||||||
|
Args:
|
||||||
|
repository_ctx: The repository context.
|
||||||
|
Returns:
|
||||||
|
One of (darwin, freebsd, x64_windows, ppc, s390x, arm, aarch64, k8, piii)
|
||||||
|
"""
|
||||||
os_name = repository_ctx.os.name.lower()
|
os_name = repository_ctx.os.name.lower()
|
||||||
if os_name.startswith("mac os"):
|
if os_name.startswith("mac os"):
|
||||||
return "darwin"
|
return "darwin"
|
||||||
|
|
|
@ -16,13 +16,13 @@
|
||||||
|
|
||||||
load("@bazel_tools//tools/osx:xcode_configure.bzl", "run_xcode_locator")
|
load("@bazel_tools//tools/osx:xcode_configure.bzl", "run_xcode_locator")
|
||||||
load(
|
load(
|
||||||
"@rules_cc//cc/private/toolchain:lib_cc_configure.bzl",
|
":lib_cc_configure.bzl",
|
||||||
"escape_string",
|
"escape_string",
|
||||||
"resolve_labels",
|
"resolve_labels",
|
||||||
"write_builtin_include_directory_paths",
|
"write_builtin_include_directory_paths",
|
||||||
)
|
)
|
||||||
load(
|
load(
|
||||||
"@rules_cc//cc/private/toolchain:unix_cc_configure.bzl",
|
":unix_cc_configure.bzl",
|
||||||
"configure_unix_toolchain",
|
"configure_unix_toolchain",
|
||||||
"find_cc",
|
"find_cc",
|
||||||
"get_env",
|
"get_env",
|
||||||
|
@ -51,7 +51,12 @@ def _get_escaped_xcode_cxx_inc_directories(repository_ctx, cc, xcode_toolchains)
|
||||||
return include_dirs
|
return include_dirs
|
||||||
|
|
||||||
def configure_osx_toolchain(repository_ctx, overriden_tools):
|
def configure_osx_toolchain(repository_ctx, overriden_tools):
|
||||||
"""Configure C++ toolchain on macOS."""
|
"""Configure C++ toolchain on macOS.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
repository_ctx: The repository context.
|
||||||
|
overriden_tools: dictionary of overriden tools.
|
||||||
|
"""
|
||||||
paths = resolve_labels(repository_ctx, [
|
paths = resolve_labels(repository_ctx, [
|
||||||
"@rules_cc//cc/private/toolchain:osx_cc_wrapper.sh.tpl",
|
"@rules_cc//cc/private/toolchain:osx_cc_wrapper.sh.tpl",
|
||||||
"@bazel_tools//tools/objc:libtool.sh",
|
"@bazel_tools//tools/objc:libtool.sh",
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
package(default_visibility = ["//visibility:private"])
|
|
||||||
|
|
||||||
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
|
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "srcs",
|
|
||||||
srcs = glob(
|
|
||||||
["**"],
|
|
||||||
exclude = [
|
|
||||||
".*",
|
|
||||||
"*~",
|
|
||||||
],
|
|
||||||
),
|
|
||||||
visibility = ["//cc/private/toolchain:__pkg__"],
|
|
||||||
)
|
|
||||||
|
|
||||||
filegroup(
|
|
||||||
name = "embedded_tools",
|
|
||||||
srcs = [
|
|
||||||
"BUILD.tools",
|
|
||||||
":srcs_for_embedded_tools",
|
|
||||||
],
|
|
||||||
visibility = ["//cc/private/toolchain:__pkg__"],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Rewrite the include path for runfiles.h in runfiles_src.cc, and create
|
|
||||||
# "generated_runfiles.{h,cc}". These files are renamed to "runfiles.{h,cc}" as
|
|
||||||
# part of creating the embedded tools of Bazel.
|
|
||||||
#
|
|
||||||
# We cannot just check in runfiles_src.{h,cc} as runfiles.{h,cc}, because it'd
|
|
||||||
# cause a header check failure on Windows when building targets in the Bazel
|
|
||||||
# source tree, if those targets depend on @rules_cc//cc/private/toolchain/runfiles,
|
|
||||||
# because due to lack of sandboxing they would accidentally pick up runfiles.h
|
|
||||||
# from @rules_cc//cc/private/toolchain/runfiles.
|
|
||||||
genrule(
|
|
||||||
name = "srcs_for_embedded_tools",
|
|
||||||
srcs = [
|
|
||||||
"runfiles_src.cc",
|
|
||||||
"runfiles_src.h",
|
|
||||||
],
|
|
||||||
outs = [
|
|
||||||
"generated_runfiles.cc",
|
|
||||||
"generated_runfiles.h",
|
|
||||||
],
|
|
||||||
# Keep this transformation logic in sync with the
|
|
||||||
# //scripts/bootstrap/compile.sh
|
|
||||||
cmd = ("sed " +
|
|
||||||
" 's|^#include.*/runfiles_src.h.*|#include \"tools/cpp/runfiles/runfiles.h\"|' " +
|
|
||||||
" $(location runfiles_src.cc) > $(location generated_runfiles.cc) && " +
|
|
||||||
"cp $(location runfiles_src.h) $(location generated_runfiles.h)"),
|
|
||||||
)
|
|
||||||
|
|
||||||
cc_library(
|
|
||||||
name = "runfiles",
|
|
||||||
testonly = 1,
|
|
||||||
srcs = ["runfiles_src.cc"],
|
|
||||||
hdrs = ["runfiles_src.h"],
|
|
||||||
)
|
|
||||||
|
|
||||||
cc_test(
|
|
||||||
name = "runfiles_test",
|
|
||||||
srcs = ["runfiles_test.cc"],
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
deps = [
|
|
||||||
":runfiles",
|
|
||||||
"@com_google_googletest//:gtest_main",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
test_suite(
|
|
||||||
name = "windows_tests",
|
|
||||||
tags = [
|
|
||||||
"-no_windows",
|
|
||||||
"-slow",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
test_suite(
|
|
||||||
name = "all_windows_tests",
|
|
||||||
tests = [
|
|
||||||
":windows_tests",
|
|
||||||
],
|
|
||||||
visibility = ["//tools:__pkg__"],
|
|
||||||
)
|
|
|
@ -1,8 +0,0 @@
|
||||||
# This package will host the C++ runfiles library when it's finally released.
|
|
||||||
|
|
||||||
cc_library(
|
|
||||||
name = "runfiles",
|
|
||||||
srcs = ["runfiles.cc"],
|
|
||||||
hdrs = ["runfiles.h"],
|
|
||||||
visibility = ["//visibility:public"],
|
|
||||||
)
|
|
|
@ -15,7 +15,7 @@
|
||||||
"""Configuring the C++ toolchain on Unix platforms."""
|
"""Configuring the C++ toolchain on Unix platforms."""
|
||||||
|
|
||||||
load(
|
load(
|
||||||
"@rules_cc//cc/private/toolchain:lib_cc_configure.bzl",
|
":lib_cc_configure.bzl",
|
||||||
"auto_configure_fail",
|
"auto_configure_fail",
|
||||||
"auto_configure_warning",
|
"auto_configure_warning",
|
||||||
"auto_configure_warning_maybe",
|
"auto_configure_warning_maybe",
|
||||||
|
@ -123,7 +123,16 @@ def _cxx_inc_convert(path):
|
||||||
return path
|
return path
|
||||||
|
|
||||||
def get_escaped_cxx_inc_directories(repository_ctx, cc, lang_flag, additional_flags = []):
|
def get_escaped_cxx_inc_directories(repository_ctx, cc, lang_flag, additional_flags = []):
|
||||||
"""Compute the list of default %-escaped C++ include directories."""
|
"""Compute the list of default %-escaped C++ include directories.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
repository_ctx: The repository context.
|
||||||
|
cc: path to the C compiler.
|
||||||
|
lang_flag: value for the language flag (c, c++).
|
||||||
|
additional_flags: additional flags to pass to cc.
|
||||||
|
Returns:
|
||||||
|
a list of escaped system include directories.
|
||||||
|
"""
|
||||||
result = repository_ctx.execute([cc, "-E", lang_flag, "-", "-v"] + additional_flags)
|
result = repository_ctx.execute([cc, "-E", lang_flag, "-", "-v"] + additional_flags)
|
||||||
index1 = result.stderr.find(_INC_DIR_MARKER_BEGIN)
|
index1 = result.stderr.find(_INC_DIR_MARKER_BEGIN)
|
||||||
if index1 == -1:
|
if index1 == -1:
|
||||||
|
@ -243,8 +252,14 @@ def _get_no_canonical_prefixes_opt(repository_ctx, cc):
|
||||||
)
|
)
|
||||||
return opt
|
return opt
|
||||||
|
|
||||||
def get_env(repository_ctx):
|
def _get_env(repository_ctx):
|
||||||
"""Convert the environment in a list of export if in Homebrew. Doesn't %-escape the result!"""
|
"""Convert the environment in a list of export if in Homebrew. Doesn't %-escape the result!
|
||||||
|
|
||||||
|
Args:
|
||||||
|
repository_ctx: The repository context.
|
||||||
|
Returns:
|
||||||
|
empty string or a list of exports in case we're running with homebrew. Don't ask me why.
|
||||||
|
"""
|
||||||
env = repository_ctx.os.environ
|
env = repository_ctx.os.environ
|
||||||
if "HOMEBREW_RUBY_PATH" in env:
|
if "HOMEBREW_RUBY_PATH" in env:
|
||||||
return "\n".join([
|
return "\n".join([
|
||||||
|
@ -304,7 +319,13 @@ def find_cc(repository_ctx, overriden_tools):
|
||||||
return _find_generic(repository_ctx, "gcc", "CC", overriden_tools)
|
return _find_generic(repository_ctx, "gcc", "CC", overriden_tools)
|
||||||
|
|
||||||
def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools):
|
def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools):
|
||||||
"""Configure C++ toolchain on Unix platforms."""
|
"""Configure C++ toolchain on Unix platforms.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
repository_ctx: The repository context.
|
||||||
|
cpu_value: current cpu name.
|
||||||
|
overriden_tools: overriden tools.
|
||||||
|
"""
|
||||||
paths = resolve_labels(repository_ctx, [
|
paths = resolve_labels(repository_ctx, [
|
||||||
"@rules_cc//cc/private/toolchain:BUILD.tpl",
|
"@rules_cc//cc/private/toolchain:BUILD.tpl",
|
||||||
"@rules_cc//cc/private/toolchain:armeabi_cc_toolchain_config.bzl",
|
"@rules_cc//cc/private/toolchain:armeabi_cc_toolchain_config.bzl",
|
||||||
|
@ -411,16 +432,10 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools):
|
||||||
"BUILD",
|
"BUILD",
|
||||||
paths["@rules_cc//cc/private/toolchain:BUILD.tpl"],
|
paths["@rules_cc//cc/private/toolchain:BUILD.tpl"],
|
||||||
{
|
{
|
||||||
"%{cc_toolchain_identifier}": cc_toolchain_identifier,
|
"%{abi_libc_version}": escape_string(get_env_var(
|
||||||
"%{name}": cpu_value,
|
|
||||||
"%{supports_param_files}": "0" if darwin else "1",
|
|
||||||
"%{cc_compiler_deps}": get_starlark_list([":builtin_include_directory_paths"] + (
|
|
||||||
[":cc_wrapper"] if darwin else []
|
|
||||||
)),
|
|
||||||
"%{compiler}": escape_string(get_env_var(
|
|
||||||
repository_ctx,
|
repository_ctx,
|
||||||
"BAZEL_COMPILER",
|
"ABI_LIBC_VERSION",
|
||||||
"compiler",
|
"local",
|
||||||
False,
|
False,
|
||||||
)),
|
)),
|
||||||
"%{abi_version}": escape_string(get_env_var(
|
"%{abi_version}": escape_string(get_env_var(
|
||||||
|
@ -429,40 +444,10 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools):
|
||||||
"local",
|
"local",
|
||||||
False,
|
False,
|
||||||
)),
|
)),
|
||||||
"%{abi_libc_version}": escape_string(get_env_var(
|
"%{cc_compiler_deps}": get_starlark_list([":builtin_include_directory_paths"] + (
|
||||||
repository_ctx,
|
[":cc_wrapper"] if darwin else []
|
||||||
"ABI_LIBC_VERSION",
|
|
||||||
"local",
|
|
||||||
False,
|
|
||||||
)),
|
)),
|
||||||
"%{host_system_name}": escape_string(get_env_var(
|
"%{cc_toolchain_identifier}": cc_toolchain_identifier,
|
||||||
repository_ctx,
|
|
||||||
"BAZEL_HOST_SYSTEM",
|
|
||||||
"local",
|
|
||||||
False,
|
|
||||||
)),
|
|
||||||
"%{target_libc}": "macosx" if darwin else escape_string(get_env_var(
|
|
||||||
repository_ctx,
|
|
||||||
"BAZEL_TARGET_LIBC",
|
|
||||||
"local",
|
|
||||||
False,
|
|
||||||
)),
|
|
||||||
"%{target_cpu}": escape_string(get_env_var(
|
|
||||||
repository_ctx,
|
|
||||||
"BAZEL_TARGET_CPU",
|
|
||||||
cpu_value,
|
|
||||||
False,
|
|
||||||
)),
|
|
||||||
"%{target_system_name}": escape_string(get_env_var(
|
|
||||||
repository_ctx,
|
|
||||||
"BAZEL_TARGET_SYSTEM",
|
|
||||||
"local",
|
|
||||||
False,
|
|
||||||
)),
|
|
||||||
"%{tool_paths}": ",\n ".join(
|
|
||||||
['"%s": "%s"' % (k, v) for k, v in tool_paths.items()],
|
|
||||||
),
|
|
||||||
"%{cxx_builtin_include_directories}": get_starlark_list(builtin_include_directories),
|
|
||||||
"%{compile_flags}": get_starlark_list(
|
"%{compile_flags}": get_starlark_list(
|
||||||
[
|
[
|
||||||
# Security hardening requires optimization.
|
# Security hardening requires optimization.
|
||||||
|
@ -488,7 +473,23 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools):
|
||||||
"-fno-omit-frame-pointer",
|
"-fno-omit-frame-pointer",
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
"%{compiler}": escape_string(get_env_var(
|
||||||
|
repository_ctx,
|
||||||
|
"BAZEL_COMPILER",
|
||||||
|
"compiler",
|
||||||
|
False,
|
||||||
|
)),
|
||||||
|
"%{coverage_compile_flags}": coverage_compile_flags,
|
||||||
|
"%{coverage_link_flags}": coverage_link_flags,
|
||||||
|
"%{cxx_builtin_include_directories}": get_starlark_list(builtin_include_directories),
|
||||||
"%{cxx_flags}": get_starlark_list(cxx_opts + _escaped_cplus_include_paths(repository_ctx)),
|
"%{cxx_flags}": get_starlark_list(cxx_opts + _escaped_cplus_include_paths(repository_ctx)),
|
||||||
|
"%{dbg_compile_flags}": get_starlark_list(["-g"]),
|
||||||
|
"%{host_system_name}": escape_string(get_env_var(
|
||||||
|
repository_ctx,
|
||||||
|
"BAZEL_HOST_SYSTEM",
|
||||||
|
"local",
|
||||||
|
False,
|
||||||
|
)),
|
||||||
"%{link_flags}": get_starlark_list((
|
"%{link_flags}": get_starlark_list((
|
||||||
["-fuse-ld=" + gold_linker_path] if gold_linker_path else []
|
["-fuse-ld=" + gold_linker_path] if gold_linker_path else []
|
||||||
) + _add_linker_option_if_supported(
|
) + _add_linker_option_if_supported(
|
||||||
|
@ -518,6 +519,7 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools):
|
||||||
)
|
)
|
||||||
) + link_opts),
|
) + link_opts),
|
||||||
"%{link_libs}": get_starlark_list(link_libs),
|
"%{link_libs}": get_starlark_list(link_libs),
|
||||||
|
"%{name}": cpu_value,
|
||||||
"%{opt_compile_flags}": get_starlark_list(
|
"%{opt_compile_flags}": get_starlark_list(
|
||||||
[
|
[
|
||||||
# No debug symbols.
|
# No debug symbols.
|
||||||
|
@ -552,6 +554,29 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools):
|
||||||
"-gc-sections",
|
"-gc-sections",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
"%{supports_param_files}": "0" if darwin else "1",
|
||||||
|
"%{supports_start_end_lib}": "True" if gold_linker_path else "False",
|
||||||
|
"%{target_cpu}": escape_string(get_env_var(
|
||||||
|
repository_ctx,
|
||||||
|
"BAZEL_TARGET_CPU",
|
||||||
|
cpu_value,
|
||||||
|
False,
|
||||||
|
)),
|
||||||
|
"%{target_libc}": "macosx" if darwin else escape_string(get_env_var(
|
||||||
|
repository_ctx,
|
||||||
|
"BAZEL_TARGET_LIBC",
|
||||||
|
"local",
|
||||||
|
False,
|
||||||
|
)),
|
||||||
|
"%{target_system_name}": escape_string(get_env_var(
|
||||||
|
repository_ctx,
|
||||||
|
"BAZEL_TARGET_SYSTEM",
|
||||||
|
"local",
|
||||||
|
False,
|
||||||
|
)),
|
||||||
|
"%{tool_paths}": ",\n ".join(
|
||||||
|
['"%s": "%s"' % (k, v) for k, v in tool_paths.items()],
|
||||||
|
),
|
||||||
"%{unfiltered_compile_flags}": get_starlark_list(
|
"%{unfiltered_compile_flags}": get_starlark_list(
|
||||||
_get_no_canonical_prefixes_opt(repository_ctx, cc) + [
|
_get_no_canonical_prefixes_opt(repository_ctx, cc) + [
|
||||||
# Make C++ compilation deterministic. Use linkstamping instead of these
|
# Make C++ compilation deterministic. Use linkstamping instead of these
|
||||||
|
@ -562,9 +587,5 @@ def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools):
|
||||||
"-D__TIME__=\\\"redacted\\\"",
|
"-D__TIME__=\\\"redacted\\\"",
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
"%{dbg_compile_flags}": get_starlark_list(["-g"]),
|
|
||||||
"%{coverage_compile_flags}": coverage_compile_flags,
|
|
||||||
"%{coverage_link_flags}": coverage_link_flags,
|
|
||||||
"%{supports_start_end_lib}": "True" if gold_linker_path else "False",
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -14,8 +14,9 @@
|
||||||
|
|
||||||
"""A Starlark cc_toolchain configuration rule"""
|
"""A Starlark cc_toolchain configuration rule"""
|
||||||
|
|
||||||
|
load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES")
|
||||||
load(
|
load(
|
||||||
"@rules_cc//cc/private/toolchain:cc_toolchain_config_lib.bzl",
|
"@rules_cc//cc:cc_toolchain_config_lib.bzl",
|
||||||
"feature",
|
"feature",
|
||||||
"feature_set",
|
"feature_set",
|
||||||
"flag_group",
|
"flag_group",
|
||||||
|
@ -24,7 +25,6 @@ load(
|
||||||
"variable_with_value",
|
"variable_with_value",
|
||||||
"with_feature_set",
|
"with_feature_set",
|
||||||
)
|
)
|
||||||
load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES")
|
|
||||||
|
|
||||||
all_compile_actions = [
|
all_compile_actions = [
|
||||||
ACTION_NAMES.c_compile,
|
ACTION_NAMES.c_compile,
|
||||||
|
@ -1171,27 +1171,27 @@ def _impl(ctx):
|
||||||
cc_toolchain_config = rule(
|
cc_toolchain_config = rule(
|
||||||
implementation = _impl,
|
implementation = _impl,
|
||||||
attrs = {
|
attrs = {
|
||||||
"cpu": attr.string(mandatory = True),
|
|
||||||
"compiler": attr.string(mandatory = True),
|
|
||||||
"toolchain_identifier": attr.string(mandatory = True),
|
|
||||||
"host_system_name": attr.string(mandatory = True),
|
|
||||||
"target_system_name": attr.string(mandatory = True),
|
|
||||||
"target_libc": attr.string(mandatory = True),
|
|
||||||
"abi_version": attr.string(mandatory = True),
|
|
||||||
"abi_libc_version": attr.string(mandatory = True),
|
"abi_libc_version": attr.string(mandatory = True),
|
||||||
"cxx_builtin_include_directories": attr.string_list(),
|
"abi_version": attr.string(mandatory = True),
|
||||||
"tool_paths": attr.string_dict(),
|
|
||||||
"compile_flags": attr.string_list(),
|
"compile_flags": attr.string_list(),
|
||||||
"dbg_compile_flags": attr.string_list(),
|
"compiler": attr.string(mandatory = True),
|
||||||
"opt_compile_flags": attr.string_list(),
|
|
||||||
"cxx_flags": attr.string_list(),
|
|
||||||
"link_flags": attr.string_list(),
|
|
||||||
"link_libs": attr.string_list(),
|
|
||||||
"opt_link_flags": attr.string_list(),
|
|
||||||
"unfiltered_compile_flags": attr.string_list(),
|
|
||||||
"coverage_compile_flags": attr.string_list(),
|
"coverage_compile_flags": attr.string_list(),
|
||||||
"coverage_link_flags": attr.string_list(),
|
"coverage_link_flags": attr.string_list(),
|
||||||
|
"cpu": attr.string(mandatory = True),
|
||||||
|
"cxx_builtin_include_directories": attr.string_list(),
|
||||||
|
"cxx_flags": attr.string_list(),
|
||||||
|
"dbg_compile_flags": attr.string_list(),
|
||||||
|
"host_system_name": attr.string(mandatory = True),
|
||||||
|
"link_flags": attr.string_list(),
|
||||||
|
"link_libs": attr.string_list(),
|
||||||
|
"opt_compile_flags": attr.string_list(),
|
||||||
|
"opt_link_flags": attr.string_list(),
|
||||||
"supports_start_end_lib": attr.bool(),
|
"supports_start_end_lib": attr.bool(),
|
||||||
|
"target_libc": attr.string(mandatory = True),
|
||||||
|
"target_system_name": attr.string(mandatory = True),
|
||||||
|
"tool_paths": attr.string_dict(),
|
||||||
|
"toolchain_identifier": attr.string(mandatory = True),
|
||||||
|
"unfiltered_compile_flags": attr.string_list(),
|
||||||
},
|
},
|
||||||
provides = [CcToolchainConfigInfo],
|
provides = [CcToolchainConfigInfo],
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
"""Configuring the C++ toolchain on Windows."""
|
"""Configuring the C++ toolchain on Windows."""
|
||||||
|
|
||||||
load(
|
load(
|
||||||
"@rules_cc//cc/private/toolchain:lib_cc_configure.bzl",
|
":lib_cc_configure.bzl",
|
||||||
"auto_configure_fail",
|
"auto_configure_fail",
|
||||||
"auto_configure_warning",
|
"auto_configure_warning",
|
||||||
"auto_configure_warning_maybe",
|
"auto_configure_warning_maybe",
|
||||||
|
@ -99,7 +99,7 @@ def _add_system_root(repository_ctx, env):
|
||||||
env["PATH"] = env["PATH"] + ";" + _get_system_root(repository_ctx) + "\\system32"
|
env["PATH"] = env["PATH"] + ";" + _get_system_root(repository_ctx) + "\\system32"
|
||||||
return env
|
return env
|
||||||
|
|
||||||
def find_vc_path(repository_ctx):
|
def _find_vc_path(repository_ctx):
|
||||||
"""Find Visual C++ build tools install path. Doesn't %-escape the result."""
|
"""Find Visual C++ build tools install path. Doesn't %-escape the result."""
|
||||||
|
|
||||||
# 1. Check if BAZEL_VC or BAZEL_VS is already set by user.
|
# 1. Check if BAZEL_VC or BAZEL_VS is already set by user.
|
||||||
|
@ -360,7 +360,7 @@ def _get_winsdk_full_version(repository_ctx):
|
||||||
"""Return the value of BAZEL_WINSDK_FULL_VERSION if defined, otherwise an empty string."""
|
"""Return the value of BAZEL_WINSDK_FULL_VERSION if defined, otherwise an empty string."""
|
||||||
return repository_ctx.os.environ.get("BAZEL_WINSDK_FULL_VERSION", default = "")
|
return repository_ctx.os.environ.get("BAZEL_WINSDK_FULL_VERSION", default = "")
|
||||||
|
|
||||||
def find_msvc_tool(repository_ctx, vc_path, tool):
|
def _find_msvc_tool(repository_ctx, vc_path, tool):
|
||||||
"""Find the exact path of a specific build tool in MSVC. Doesn't %-escape the result."""
|
"""Find the exact path of a specific build tool in MSVC. Doesn't %-escape the result."""
|
||||||
tool_path = None
|
tool_path = None
|
||||||
if _is_vs_2017_or_2019(vc_path):
|
if _is_vs_2017_or_2019(vc_path):
|
||||||
|
@ -384,7 +384,7 @@ def _find_missing_vc_tools(repository_ctx, vc_path):
|
||||||
missing_tools.append("VCVARSALL.BAT")
|
missing_tools.append("VCVARSALL.BAT")
|
||||||
|
|
||||||
for tool in ["cl.exe", "link.exe", "lib.exe", "ml64.exe"]:
|
for tool in ["cl.exe", "link.exe", "lib.exe", "ml64.exe"]:
|
||||||
if not find_msvc_tool(repository_ctx, vc_path, tool):
|
if not _find_msvc_tool(repository_ctx, vc_path, tool):
|
||||||
missing_tools.append(tool)
|
missing_tools.append(tool)
|
||||||
|
|
||||||
return missing_tools
|
return missing_tools
|
||||||
|
@ -397,7 +397,7 @@ def _is_support_debug_fastlink(repository_ctx, linker):
|
||||||
result = execute(repository_ctx, [linker], expect_failure = True)
|
result = execute(repository_ctx, [linker], expect_failure = True)
|
||||||
return result.find("/DEBUG[:{FASTLINK|FULL|NONE}]") != -1
|
return result.find("/DEBUG[:{FASTLINK|FULL|NONE}]") != -1
|
||||||
|
|
||||||
def find_llvm_path(repository_ctx):
|
def _find_llvm_path(repository_ctx):
|
||||||
"""Find LLVM install path."""
|
"""Find LLVM install path."""
|
||||||
|
|
||||||
# 1. Check if BAZEL_LLVM is already set by user.
|
# 1. Check if BAZEL_LLVM is already set by user.
|
||||||
|
@ -443,7 +443,7 @@ def find_llvm_path(repository_ctx):
|
||||||
auto_configure_warning_maybe(repository_ctx, "LLVM installation found at %s" % llvm_dir)
|
auto_configure_warning_maybe(repository_ctx, "LLVM installation found at %s" % llvm_dir)
|
||||||
return llvm_dir
|
return llvm_dir
|
||||||
|
|
||||||
def find_llvm_tool(repository_ctx, llvm_path, tool):
|
def _find_llvm_tool(repository_ctx, llvm_path, tool):
|
||||||
"""Find the exact path of a specific build tool in LLVM. Doesn't %-escape the result."""
|
"""Find the exact path of a specific build tool in LLVM. Doesn't %-escape the result."""
|
||||||
tool_path = llvm_path + "\\bin\\" + tool
|
tool_path = llvm_path + "\\bin\\" + tool
|
||||||
|
|
||||||
|
@ -460,7 +460,7 @@ def _find_missing_llvm_tools(repository_ctx, llvm_path):
|
||||||
"""Check if any required tool is missing under given LLVM path."""
|
"""Check if any required tool is missing under given LLVM path."""
|
||||||
missing_tools = []
|
missing_tools = []
|
||||||
for tool in ["clang-cl.exe", "lld-link.exe", "llvm-lib.exe"]:
|
for tool in ["clang-cl.exe", "lld-link.exe", "llvm-lib.exe"]:
|
||||||
if not find_llvm_tool(repository_ctx, llvm_path, tool):
|
if not _find_llvm_tool(repository_ctx, llvm_path, tool):
|
||||||
missing_tools.append(tool)
|
missing_tools.append(tool)
|
||||||
|
|
||||||
return missing_tools
|
return missing_tools
|
||||||
|
@ -481,17 +481,17 @@ def _get_msys_mingw_vars(repository_ctx):
|
||||||
msys_mingw_vars = {
|
msys_mingw_vars = {
|
||||||
"%{cxx_builtin_include_directories}": inc_dir_msys,
|
"%{cxx_builtin_include_directories}": inc_dir_msys,
|
||||||
"%{mingw_cxx_builtin_include_directories}": inc_dir_mingw,
|
"%{mingw_cxx_builtin_include_directories}": inc_dir_mingw,
|
||||||
"%{tool_paths}": tool_paths,
|
"%{mingw_tool_bin_path}": tool_bin_path_mingw,
|
||||||
"%{mingw_tool_paths}": tool_paths_mingw,
|
"%{mingw_tool_paths}": tool_paths_mingw,
|
||||||
"%{tool_bin_path}": tool_bin_path,
|
"%{tool_bin_path}": tool_bin_path,
|
||||||
"%{mingw_tool_bin_path}": tool_bin_path_mingw,
|
"%{tool_paths}": tool_paths,
|
||||||
}
|
}
|
||||||
return msys_mingw_vars
|
return msys_mingw_vars
|
||||||
|
|
||||||
def _get_msvc_vars(repository_ctx, paths):
|
def _get_msvc_vars(repository_ctx, paths):
|
||||||
"""Get the variables we need to populate the MSVC toolchains."""
|
"""Get the variables we need to populate the MSVC toolchains."""
|
||||||
msvc_vars = dict()
|
msvc_vars = dict()
|
||||||
vc_path = find_vc_path(repository_ctx)
|
vc_path = _find_vc_path(repository_ctx)
|
||||||
missing_tools = None
|
missing_tools = None
|
||||||
if not vc_path:
|
if not vc_path:
|
||||||
repository_ctx.template(
|
repository_ctx.template(
|
||||||
|
@ -518,17 +518,17 @@ def _get_msvc_vars(repository_ctx, paths):
|
||||||
if not vc_path or missing_tools:
|
if not vc_path or missing_tools:
|
||||||
write_builtin_include_directory_paths(repository_ctx, "msvc", [], file_suffix = "_msvc")
|
write_builtin_include_directory_paths(repository_ctx, "msvc", [], file_suffix = "_msvc")
|
||||||
msvc_vars = {
|
msvc_vars = {
|
||||||
"%{msvc_env_tmp}": "msvc_not_found",
|
|
||||||
"%{msvc_env_path}": "msvc_not_found",
|
|
||||||
"%{msvc_env_include}": "msvc_not_found",
|
|
||||||
"%{msvc_env_lib}": "msvc_not_found",
|
|
||||||
"%{msvc_cl_path}": "vc_installation_error.bat",
|
|
||||||
"%{msvc_ml_path}": "vc_installation_error.bat",
|
|
||||||
"%{msvc_link_path}": "vc_installation_error.bat",
|
|
||||||
"%{msvc_lib_path}": "vc_installation_error.bat",
|
|
||||||
"%{dbg_mode_debug_flag}": "/DEBUG",
|
"%{dbg_mode_debug_flag}": "/DEBUG",
|
||||||
"%{fastbuild_mode_debug_flag}": "/DEBUG",
|
"%{fastbuild_mode_debug_flag}": "/DEBUG",
|
||||||
|
"%{msvc_cl_path}": "vc_installation_error.bat",
|
||||||
"%{msvc_cxx_builtin_include_directories}": "",
|
"%{msvc_cxx_builtin_include_directories}": "",
|
||||||
|
"%{msvc_env_include}": "msvc_not_found",
|
||||||
|
"%{msvc_env_lib}": "msvc_not_found",
|
||||||
|
"%{msvc_env_path}": "msvc_not_found",
|
||||||
|
"%{msvc_env_tmp}": "msvc_not_found",
|
||||||
|
"%{msvc_lib_path}": "vc_installation_error.bat",
|
||||||
|
"%{msvc_link_path}": "vc_installation_error.bat",
|
||||||
|
"%{msvc_ml_path}": "vc_installation_error.bat",
|
||||||
}
|
}
|
||||||
return msvc_vars
|
return msvc_vars
|
||||||
|
|
||||||
|
@ -540,23 +540,23 @@ def _get_msvc_vars(repository_ctx, paths):
|
||||||
|
|
||||||
llvm_path = ""
|
llvm_path = ""
|
||||||
if _use_clang_cl(repository_ctx):
|
if _use_clang_cl(repository_ctx):
|
||||||
llvm_path = find_llvm_path(repository_ctx)
|
llvm_path = _find_llvm_path(repository_ctx)
|
||||||
if not llvm_path:
|
if not llvm_path:
|
||||||
auto_configure_fail("\nUSE_CLANG_CL is set to 1, but Bazel cannot find Clang installation on your system.\n" +
|
auto_configure_fail("\nUSE_CLANG_CL is set to 1, but Bazel cannot find Clang installation on your system.\n" +
|
||||||
"Please install Clang via http://releases.llvm.org/download.html\n")
|
"Please install Clang via http://releases.llvm.org/download.html\n")
|
||||||
cl_path = find_llvm_tool(repository_ctx, llvm_path, "clang-cl.exe")
|
cl_path = _find_llvm_tool(repository_ctx, llvm_path, "clang-cl.exe")
|
||||||
link_path = find_llvm_tool(repository_ctx, llvm_path, "lld-link.exe")
|
link_path = _find_llvm_tool(repository_ctx, llvm_path, "lld-link.exe")
|
||||||
if not link_path:
|
if not link_path:
|
||||||
link_path = find_msvc_tool(repository_ctx, vc_path, "link.exe")
|
link_path = _find_msvc_tool(repository_ctx, vc_path, "link.exe")
|
||||||
lib_path = find_llvm_tool(repository_ctx, llvm_path, "llvm-lib.exe")
|
lib_path = _find_llvm_tool(repository_ctx, llvm_path, "llvm-lib.exe")
|
||||||
if not lib_path:
|
if not lib_path:
|
||||||
lib_path = find_msvc_tool(repository_ctx, vc_path, "lib.exe")
|
lib_path = _find_msvc_tool(repository_ctx, vc_path, "lib.exe")
|
||||||
else:
|
else:
|
||||||
cl_path = find_msvc_tool(repository_ctx, vc_path, "cl.exe")
|
cl_path = _find_msvc_tool(repository_ctx, vc_path, "cl.exe")
|
||||||
link_path = find_msvc_tool(repository_ctx, vc_path, "link.exe")
|
link_path = _find_msvc_tool(repository_ctx, vc_path, "link.exe")
|
||||||
lib_path = find_msvc_tool(repository_ctx, vc_path, "lib.exe")
|
lib_path = _find_msvc_tool(repository_ctx, vc_path, "lib.exe")
|
||||||
|
|
||||||
msvc_ml_path = find_msvc_tool(repository_ctx, vc_path, "ml64.exe")
|
msvc_ml_path = _find_msvc_tool(repository_ctx, vc_path, "ml64.exe")
|
||||||
escaped_cxx_include_directories = []
|
escaped_cxx_include_directories = []
|
||||||
|
|
||||||
for path in escaped_include_paths.split(";"):
|
for path in escaped_include_paths.split(";"):
|
||||||
|
@ -574,23 +574,23 @@ def _get_msvc_vars(repository_ctx, paths):
|
||||||
|
|
||||||
write_builtin_include_directory_paths(repository_ctx, "msvc", escaped_cxx_include_directories, file_suffix = "_msvc")
|
write_builtin_include_directory_paths(repository_ctx, "msvc", escaped_cxx_include_directories, file_suffix = "_msvc")
|
||||||
msvc_vars = {
|
msvc_vars = {
|
||||||
"%{msvc_env_tmp}": escaped_tmp_dir,
|
|
||||||
"%{msvc_env_path}": escaped_paths,
|
|
||||||
"%{msvc_env_include}": escaped_include_paths,
|
|
||||||
"%{msvc_env_lib}": escaped_lib_paths,
|
|
||||||
"%{msvc_cl_path}": cl_path,
|
|
||||||
"%{msvc_ml_path}": msvc_ml_path,
|
|
||||||
"%{msvc_link_path}": link_path,
|
|
||||||
"%{msvc_lib_path}": lib_path,
|
|
||||||
"%{dbg_mode_debug_flag}": "/DEBUG:FULL" if support_debug_fastlink else "/DEBUG",
|
"%{dbg_mode_debug_flag}": "/DEBUG:FULL" if support_debug_fastlink else "/DEBUG",
|
||||||
"%{fastbuild_mode_debug_flag}": "/DEBUG:FASTLINK" if support_debug_fastlink else "/DEBUG",
|
"%{fastbuild_mode_debug_flag}": "/DEBUG:FASTLINK" if support_debug_fastlink else "/DEBUG",
|
||||||
|
"%{msvc_cl_path}": cl_path,
|
||||||
"%{msvc_cxx_builtin_include_directories}": " " + ",\n ".join(escaped_cxx_include_directories),
|
"%{msvc_cxx_builtin_include_directories}": " " + ",\n ".join(escaped_cxx_include_directories),
|
||||||
|
"%{msvc_env_include}": escaped_include_paths,
|
||||||
|
"%{msvc_env_lib}": escaped_lib_paths,
|
||||||
|
"%{msvc_env_path}": escaped_paths,
|
||||||
|
"%{msvc_env_tmp}": escaped_tmp_dir,
|
||||||
|
"%{msvc_lib_path}": lib_path,
|
||||||
|
"%{msvc_link_path}": link_path,
|
||||||
|
"%{msvc_ml_path}": msvc_ml_path,
|
||||||
}
|
}
|
||||||
return msvc_vars
|
return msvc_vars
|
||||||
|
|
||||||
def _get_clang_cl_vars(repository_ctx, paths, msvc_vars):
|
def _get_clang_cl_vars(repository_ctx, paths, msvc_vars):
|
||||||
"""Get the variables we need to populate the clang-cl toolchains."""
|
"""Get the variables we need to populate the clang-cl toolchains."""
|
||||||
llvm_path = find_llvm_path(repository_ctx)
|
llvm_path = _find_llvm_path(repository_ctx)
|
||||||
error_script = None
|
error_script = None
|
||||||
if msvc_vars["%{msvc_cl_path}"] == "vc_installation_error.bat":
|
if msvc_vars["%{msvc_cl_path}"] == "vc_installation_error.bat":
|
||||||
error_script = "vc_installation_error.bat"
|
error_script = "vc_installation_error.bat"
|
||||||
|
@ -621,23 +621,23 @@ def _get_clang_cl_vars(repository_ctx, paths, msvc_vars):
|
||||||
if error_script:
|
if error_script:
|
||||||
write_builtin_include_directory_paths(repository_ctx, "clang-cl", [], file_suffix = "_clangcl")
|
write_builtin_include_directory_paths(repository_ctx, "clang-cl", [], file_suffix = "_clangcl")
|
||||||
clang_cl_vars = {
|
clang_cl_vars = {
|
||||||
"%{clang_cl_env_tmp}": "clang_cl_not_found",
|
"%{clang_cl_cl_path}": error_script,
|
||||||
"%{clang_cl_env_path}": "clang_cl_not_found",
|
"%{clang_cl_cxx_builtin_include_directories}": "",
|
||||||
|
"%{clang_cl_dbg_mode_debug_flag}": "/DEBUG",
|
||||||
"%{clang_cl_env_include}": "clang_cl_not_found",
|
"%{clang_cl_env_include}": "clang_cl_not_found",
|
||||||
"%{clang_cl_env_lib}": "clang_cl_not_found",
|
"%{clang_cl_env_lib}": "clang_cl_not_found",
|
||||||
"%{clang_cl_cl_path}": error_script,
|
"%{clang_cl_env_path}": "clang_cl_not_found",
|
||||||
"%{clang_cl_link_path}": error_script,
|
"%{clang_cl_env_tmp}": "clang_cl_not_found",
|
||||||
"%{clang_cl_lib_path}": error_script,
|
|
||||||
"%{clang_cl_ml_path}": error_script,
|
|
||||||
"%{clang_cl_dbg_mode_debug_flag}": "/DEBUG",
|
|
||||||
"%{clang_cl_fastbuild_mode_debug_flag}": "/DEBUG",
|
"%{clang_cl_fastbuild_mode_debug_flag}": "/DEBUG",
|
||||||
"%{clang_cl_cxx_builtin_include_directories}": "",
|
"%{clang_cl_lib_path}": error_script,
|
||||||
|
"%{clang_cl_link_path}": error_script,
|
||||||
|
"%{clang_cl_ml_path}": error_script,
|
||||||
}
|
}
|
||||||
return clang_cl_vars
|
return clang_cl_vars
|
||||||
|
|
||||||
clang_cl_path = find_llvm_tool(repository_ctx, llvm_path, "clang-cl.exe")
|
clang_cl_path = _find_llvm_tool(repository_ctx, llvm_path, "clang-cl.exe")
|
||||||
lld_link_path = find_llvm_tool(repository_ctx, llvm_path, "lld-link.exe")
|
lld_link_path = _find_llvm_tool(repository_ctx, llvm_path, "lld-link.exe")
|
||||||
llvm_lib_path = find_llvm_tool(repository_ctx, llvm_path, "llvm-lib.exe")
|
llvm_lib_path = _find_llvm_tool(repository_ctx, llvm_path, "llvm-lib.exe")
|
||||||
|
|
||||||
clang_version = _get_clang_version(repository_ctx, clang_cl_path)
|
clang_version = _get_clang_version(repository_ctx, clang_cl_path)
|
||||||
clang_dir = llvm_path + "\\lib\\clang\\" + clang_version
|
clang_dir = llvm_path + "\\lib\\clang\\" + clang_version
|
||||||
|
@ -647,23 +647,27 @@ def _get_clang_cl_vars(repository_ctx, paths, msvc_vars):
|
||||||
clang_cl_include_directories = msvc_vars["%{msvc_cxx_builtin_include_directories}"] + (",\n \"%s\"" % clang_include_path)
|
clang_cl_include_directories = msvc_vars["%{msvc_cxx_builtin_include_directories}"] + (",\n \"%s\"" % clang_include_path)
|
||||||
write_builtin_include_directory_paths(repository_ctx, "clang-cl", [clang_cl_include_directories], file_suffix = "_clangcl")
|
write_builtin_include_directory_paths(repository_ctx, "clang-cl", [clang_cl_include_directories], file_suffix = "_clangcl")
|
||||||
clang_cl_vars = {
|
clang_cl_vars = {
|
||||||
"%{clang_cl_env_tmp}": msvc_vars["%{msvc_env_tmp}"],
|
|
||||||
"%{clang_cl_env_path}": msvc_vars["%{msvc_env_path}"],
|
|
||||||
"%{clang_cl_env_include}": msvc_vars["%{msvc_env_include}"] + ";" + clang_include_path,
|
|
||||||
"%{clang_cl_env_lib}": msvc_vars["%{msvc_env_lib}"] + ";" + clang_lib_path,
|
|
||||||
"%{clang_cl_cxx_builtin_include_directories}": clang_cl_include_directories,
|
|
||||||
"%{clang_cl_cl_path}": clang_cl_path,
|
"%{clang_cl_cl_path}": clang_cl_path,
|
||||||
"%{clang_cl_link_path}": lld_link_path,
|
"%{clang_cl_cxx_builtin_include_directories}": clang_cl_include_directories,
|
||||||
"%{clang_cl_lib_path}": llvm_lib_path,
|
|
||||||
"%{clang_cl_ml_path}": msvc_vars["%{msvc_ml_path}"],
|
|
||||||
# LLVM's lld-link.exe doesn't support /DEBUG:FASTLINK.
|
# LLVM's lld-link.exe doesn't support /DEBUG:FASTLINK.
|
||||||
"%{clang_cl_dbg_mode_debug_flag}": "/DEBUG",
|
"%{clang_cl_dbg_mode_debug_flag}": "/DEBUG",
|
||||||
|
"%{clang_cl_env_include}": msvc_vars["%{msvc_env_include}"] + ";" + clang_include_path,
|
||||||
|
"%{clang_cl_env_lib}": msvc_vars["%{msvc_env_lib}"] + ";" + clang_lib_path,
|
||||||
|
"%{clang_cl_env_path}": msvc_vars["%{msvc_env_path}"],
|
||||||
|
"%{clang_cl_env_tmp}": msvc_vars["%{msvc_env_tmp}"],
|
||||||
"%{clang_cl_fastbuild_mode_debug_flag}": "/DEBUG",
|
"%{clang_cl_fastbuild_mode_debug_flag}": "/DEBUG",
|
||||||
|
"%{clang_cl_lib_path}": llvm_lib_path,
|
||||||
|
"%{clang_cl_link_path}": lld_link_path,
|
||||||
|
"%{clang_cl_ml_path}": msvc_vars["%{msvc_ml_path}"],
|
||||||
}
|
}
|
||||||
return clang_cl_vars
|
return clang_cl_vars
|
||||||
|
|
||||||
def configure_windows_toolchain(repository_ctx):
|
def configure_windows_toolchain(repository_ctx):
|
||||||
"""Configure C++ toolchain on Windows."""
|
"""Configure C++ toolchain on Windows.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
repository_ctx: The repository context.
|
||||||
|
"""
|
||||||
paths = resolve_labels(repository_ctx, [
|
paths = resolve_labels(repository_ctx, [
|
||||||
"@rules_cc//cc/private/toolchain:BUILD.windows.tpl",
|
"@rules_cc//cc/private/toolchain:BUILD.windows.tpl",
|
||||||
"@rules_cc//cc/private/toolchain:windows_cc_toolchain_config.bzl",
|
"@rules_cc//cc/private/toolchain:windows_cc_toolchain_config.bzl",
|
||||||
|
|
|
@ -14,8 +14,9 @@
|
||||||
|
|
||||||
"""A Starlark cc_toolchain configuration rule for Windows"""
|
"""A Starlark cc_toolchain configuration rule for Windows"""
|
||||||
|
|
||||||
|
load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES")
|
||||||
load(
|
load(
|
||||||
"@rules_cc//cc/private/toolchain:cc_toolchain_config_lib.bzl",
|
"@rules_cc//cc:cc_toolchain_config_lib.bzl",
|
||||||
"action_config",
|
"action_config",
|
||||||
"artifact_name_pattern",
|
"artifact_name_pattern",
|
||||||
"env_entry",
|
"env_entry",
|
||||||
|
@ -29,7 +30,6 @@ load(
|
||||||
"variable_with_value",
|
"variable_with_value",
|
||||||
"with_feature_set",
|
"with_feature_set",
|
||||||
)
|
)
|
||||||
load("@rules_cc//cc:action_names.bzl", "ACTION_NAMES")
|
|
||||||
|
|
||||||
all_compile_actions = [
|
all_compile_actions = [
|
||||||
ACTION_NAMES.c_compile,
|
ACTION_NAMES.c_compile,
|
||||||
|
@ -1315,28 +1315,28 @@ def _impl(ctx):
|
||||||
cc_toolchain_config = rule(
|
cc_toolchain_config = rule(
|
||||||
implementation = _impl,
|
implementation = _impl,
|
||||||
attrs = {
|
attrs = {
|
||||||
"cpu": attr.string(mandatory = True),
|
|
||||||
"compiler": attr.string(),
|
|
||||||
"toolchain_identifier": attr.string(),
|
|
||||||
"host_system_name": attr.string(),
|
|
||||||
"target_system_name": attr.string(),
|
|
||||||
"target_libc": attr.string(),
|
|
||||||
"abi_version": attr.string(),
|
|
||||||
"abi_libc_version": attr.string(),
|
"abi_libc_version": attr.string(),
|
||||||
"tool_paths": attr.string_dict(),
|
"abi_version": attr.string(),
|
||||||
|
"compiler": attr.string(),
|
||||||
|
"cpu": attr.string(mandatory = True),
|
||||||
"cxx_builtin_include_directories": attr.string_list(),
|
"cxx_builtin_include_directories": attr.string_list(),
|
||||||
|
"dbg_mode_debug_flag": attr.string(),
|
||||||
"default_link_flags": attr.string_list(default = []),
|
"default_link_flags": attr.string_list(default = []),
|
||||||
"msvc_env_tmp": attr.string(default = "msvc_not_found"),
|
"fastbuild_mode_debug_flag": attr.string(),
|
||||||
"msvc_env_path": attr.string(default = "msvc_not_found"),
|
"host_system_name": attr.string(),
|
||||||
|
"msvc_cl_path": attr.string(default = "vc_installation_error.bat"),
|
||||||
"msvc_env_include": attr.string(default = "msvc_not_found"),
|
"msvc_env_include": attr.string(default = "msvc_not_found"),
|
||||||
"msvc_env_lib": attr.string(default = "msvc_not_found"),
|
"msvc_env_lib": attr.string(default = "msvc_not_found"),
|
||||||
"msvc_cl_path": attr.string(default = "vc_installation_error.bat"),
|
"msvc_env_path": attr.string(default = "msvc_not_found"),
|
||||||
"msvc_ml_path": attr.string(default = "vc_installation_error.bat"),
|
"msvc_env_tmp": attr.string(default = "msvc_not_found"),
|
||||||
"msvc_link_path": attr.string(default = "vc_installation_error.bat"),
|
|
||||||
"msvc_lib_path": attr.string(default = "vc_installation_error.bat"),
|
"msvc_lib_path": attr.string(default = "vc_installation_error.bat"),
|
||||||
"dbg_mode_debug_flag": attr.string(),
|
"msvc_link_path": attr.string(default = "vc_installation_error.bat"),
|
||||||
"fastbuild_mode_debug_flag": attr.string(),
|
"msvc_ml_path": attr.string(default = "vc_installation_error.bat"),
|
||||||
|
"target_libc": attr.string(),
|
||||||
|
"target_system_name": attr.string(),
|
||||||
"tool_bin_path": attr.string(default = "not_found"),
|
"tool_bin_path": attr.string(default = "not_found"),
|
||||||
|
"tool_paths": attr.string_dict(),
|
||||||
|
"toolchain_identifier": attr.string(),
|
||||||
},
|
},
|
||||||
provides = [CcToolchainConfigInfo],
|
provides = [CcToolchainConfigInfo],
|
||||||
)
|
)
|
||||||
|
|
|
@ -14,35 +14,18 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Finds the c++ toolchain.
|
Deprecated, use find_cc_toolchain.bzl
|
||||||
|
|
||||||
Returns the toolchain if enabled, and falls back to a toolchain constructed from
|
|
||||||
the CppConfiguration.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def find_cpp_toolchain(ctx):
|
load(":find_cc_toolchain.bzl", "find_cc_toolchain")
|
||||||
"""
|
|
||||||
Finds the c++ toolchain.
|
|
||||||
|
|
||||||
If the c++ toolchain is in use, returns it. Otherwise, returns a c++
|
def find_cpp_toolchain(ctx):
|
||||||
toolchain derived from legacy toolchain selection.
|
"""Deprecated, use `find_cc_toolchain` instead.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
ctx: The rule context for which to find a toolchain.
|
ctx: See `find_cc_toolchain`.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A CcToolchainProvider.
|
A CcToolchainInfo.
|
||||||
"""
|
"""
|
||||||
|
return find_cc_toolchain(ctx)
|
||||||
# Check the incompatible flag for toolchain resolution.
|
|
||||||
if hasattr(cc_common, "is_cc_toolchain_resolution_enabled_do_not_use") and cc_common.is_cc_toolchain_resolution_enabled_do_not_use(ctx = ctx):
|
|
||||||
if "@rules_cc//cc:toolchain_type" in ctx.toolchains:
|
|
||||||
return ctx.toolchains["@rules_cc//cc:toolchain_type"]
|
|
||||||
fail("In order to use find_cpp_toolchain, you must include the '@rules_cc//cc:toolchain_type' in the toolchains argument to your rule.")
|
|
||||||
|
|
||||||
# Fall back to the legacy implicit attribute lookup.
|
|
||||||
if hasattr(ctx.attr, "_cc_toolchain"):
|
|
||||||
return ctx.attr._cc_toolchain[cc_common.CcToolchainInfo]
|
|
||||||
|
|
||||||
# We didn't find anything.
|
|
||||||
fail("In order to use find_cpp_toolchain, you must define the '_cc_toolchain' attribute on your rule or aspect.")
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
|
load("@rules_pkg//:pkg.bzl", "pkg_tar")
|
||||||
|
load("@rules_pkg//releasing:defs.bzl", "print_rel_notes")
|
||||||
|
load("//cc:version.bzl", "version")
|
||||||
|
|
||||||
package(
|
package(
|
||||||
default_visibility = ["//visibility:private"],
|
default_visibility = ["//visibility:private"],
|
||||||
)
|
)
|
||||||
|
|
||||||
load("@rules_cc//cc:version.bzl", "version")
|
|
||||||
load("@rules_pkg//:pkg.bzl", "pkg_tar")
|
|
||||||
load("@rules_pkg//releasing:defs.bzl", "print_rel_notes")
|
|
||||||
|
|
||||||
# Build the artifact to put on the github release page.
|
# Build the artifact to put on the github release page.
|
||||||
pkg_tar(
|
pkg_tar(
|
||||||
name = "rules_cc-%s" % version,
|
name = "rules_cc-%s" % version,
|
||||||
|
|
|
@ -13,11 +13,12 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
# Example showing how to create a custom Starlark rule that rules_cc can depend on
|
# Example showing how to create a custom Starlark rule that rules_cc can depend on
|
||||||
licenses(["notice"])
|
|
||||||
|
|
||||||
load("//examples/my_c_compile:my_c_compile.bzl", "my_c_compile")
|
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
||||||
load("//examples/my_c_archive:my_c_archive.bzl", "my_c_archive")
|
load("//examples/my_c_archive:my_c_archive.bzl", "my_c_archive")
|
||||||
load("@rules_cc//cc:defs.bzl", "cc_binary")
|
load("//examples/my_c_compile:my_c_compile.bzl", "my_c_compile")
|
||||||
|
|
||||||
|
licenses(["notice"])
|
||||||
|
|
||||||
cc_binary(
|
cc_binary(
|
||||||
name = "main",
|
name = "main",
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
|
|
||||||
"""Example showing how to create a rule that rules_cc can depend on."""
|
"""Example showing how to create a rule that rules_cc can depend on."""
|
||||||
|
|
||||||
|
load("@rules_cc//cc:action_names.bzl", "CPP_LINK_STATIC_LIBRARY_ACTION_NAME")
|
||||||
load("@rules_cc//cc:toolchain_utils.bzl", "find_cpp_toolchain")
|
load("@rules_cc//cc:toolchain_utils.bzl", "find_cpp_toolchain")
|
||||||
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "CPP_LINK_STATIC_LIBRARY_ACTION_NAME")
|
|
||||||
load("//examples/my_c_compile:my_c_compile.bzl", "MyCCompileInfo")
|
load("//examples/my_c_compile:my_c_compile.bzl", "MyCCompileInfo")
|
||||||
|
|
||||||
def _my_c_archive_impl(ctx):
|
def _my_c_archive_impl(ctx):
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
|
|
||||||
"""Example showing how to create a rule that just compiles C sources."""
|
"""Example showing how to create a rule that just compiles C sources."""
|
||||||
|
|
||||||
|
load("@rules_cc//cc:action_names.bzl", "C_COMPILE_ACTION_NAME")
|
||||||
load("@rules_cc//cc:toolchain_utils.bzl", "find_cpp_toolchain")
|
load("@rules_cc//cc:toolchain_utils.bzl", "find_cpp_toolchain")
|
||||||
load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "C_COMPILE_ACTION_NAME")
|
|
||||||
|
|
||||||
MyCCompileInfo = provider(doc = "", fields = ["object"])
|
MyCCompileInfo = provider(doc = "", fields = ["object"])
|
||||||
|
|
||||||
|
|
|
@ -14,15 +14,16 @@
|
||||||
|
|
||||||
"""Dependencies that are needed for rules_cc tests and tools."""
|
"""Dependencies that are needed for rules_cc tests and tools."""
|
||||||
|
|
||||||
load("@bazel_federation//:repositories.bzl", "bazel_skylib", "protobuf", "rules_go", "rules_pkg")
|
load("@bazel_federation//:repositories.bzl", "bazel_skylib", "protobuf", "rules_go", "rules_pkg", "rules_python")
|
||||||
load("@bazel_federation//:third_party_repositories.bzl", "abseil_py", "py_mock", "six", "zlib")
|
load("@bazel_federation//:third_party_repositories.bzl", "abseil_py", "py_mock", "six", "zlib")
|
||||||
|
|
||||||
def rules_cc_internal_deps():
|
def rules_cc_internal_deps():
|
||||||
"""Fetches all required dependencies for rules_cc tests and tools."""
|
"""Fetches all dependencies for rules_cc tests and tools."""
|
||||||
bazel_skylib()
|
bazel_skylib()
|
||||||
protobuf()
|
protobuf()
|
||||||
rules_go()
|
rules_go()
|
||||||
rules_pkg()
|
rules_pkg()
|
||||||
|
rules_python()
|
||||||
|
|
||||||
abseil_py()
|
abseil_py()
|
||||||
py_mock()
|
py_mock()
|
||||||
|
|
|
@ -14,15 +14,19 @@
|
||||||
|
|
||||||
"""Setup for rules_cc tests and tools."""
|
"""Setup for rules_cc tests and tools."""
|
||||||
|
|
||||||
|
load("@bazel_federation//setup:rules_pkg.bzl", "rules_pkg_setup")
|
||||||
|
load("@bazel_federation//setup:rules_python.bzl", "rules_python_setup")
|
||||||
|
|
||||||
# TODO(fweikert): Add setup.bzl file for skylib to the federation and load it instead of workspace.bzl
|
# TODO(fweikert): Add setup.bzl file for skylib to the federation and load it instead of workspace.bzl
|
||||||
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
|
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
|
||||||
|
|
||||||
# TODO(fweikert): Also load rules_go's setup.bzl file from the federation once it exists
|
# TODO(fweikert): Also load rules_go's setup.bzl file from the federation once it exists
|
||||||
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
|
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
|
||||||
load("@bazel_federation//setup:rules_pkg.bzl", "rules_pkg_setup")
|
|
||||||
|
|
||||||
def rules_cc_internal_setup():
|
def rules_cc_internal_setup():
|
||||||
|
"""Setup of dependencies of tests and development-only tools used in rules_cc repository."""
|
||||||
bazel_skylib_workspace()
|
bazel_skylib_workspace()
|
||||||
go_rules_dependencies()
|
go_rules_dependencies()
|
||||||
go_register_toolchains()
|
go_register_toolchains()
|
||||||
rules_pkg_setup()
|
rules_pkg_setup()
|
||||||
|
rules_python_setup()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"extends": [
|
"extends": [
|
||||||
"config:base"
|
"config:base",
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ licenses(["notice"]) # Apache 2.0
|
||||||
|
|
||||||
load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")
|
load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")
|
||||||
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
|
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
|
||||||
|
load("@rules_proto//proto:defs.bzl", "proto_library")
|
||||||
|
|
||||||
py_proto_library(
|
py_proto_library(
|
||||||
name = "crosstool_config_py_pb2",
|
name = "crosstool_config_py_pb2",
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
# Six provides simple utilities for wrapping over differences between Python 2
|
# Six provides simple utilities for wrapping over differences between Python 2
|
||||||
# and Python 3.
|
# and Python 3.
|
||||||
|
|
||||||
|
load("@rules_python//python:defs.bzl", "py_library")
|
||||||
|
|
||||||
licenses(["notice"]) # MIT
|
licenses(["notice"]) # MIT
|
||||||
|
|
||||||
exports_files(["LICENSE"])
|
exports_files(["LICENSE"])
|
||||||
|
|
|
@ -12,11 +12,14 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
package(default_visibility = ["//visibility:public"])
|
|
||||||
|
|
||||||
# Go rules
|
# Go rules
|
||||||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
|
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
|
||||||
|
|
||||||
|
# Python rules
|
||||||
|
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
|
||||||
|
|
||||||
|
package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
licenses(["notice"]) # Apache 2.0
|
licenses(["notice"]) # Apache 2.0
|
||||||
|
|
||||||
py_binary(
|
py_binary(
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
load("//cc:defs.bzl", "cc_library", "cc_test")
|
||||||
|
|
||||||
|
licenses(["notice"])
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "runfiles",
|
||||||
|
testonly = 1,
|
||||||
|
srcs = ["runfiles_src.cc"],
|
||||||
|
hdrs = ["runfiles_src.h"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_test(
|
||||||
|
name = "runfiles_test",
|
||||||
|
srcs = ["runfiles_test.cc"],
|
||||||
|
deps = [
|
||||||
|
":runfiles",
|
||||||
|
"@com_google_googletest//:gtest_main",
|
||||||
|
],
|
||||||
|
)
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
// The "srcs_for_embedded_tools" rule in the same package sets the line below to
|
// The "srcs_for_embedded_tools" rule in the same package sets the line below to
|
||||||
// include runfiles.h from the correct path. Do not modify the line below.
|
// include runfiles.h from the correct path. Do not modify the line below.
|
||||||
#include "cc/private/toolchain/runfiles/runfiles_src.h"
|
#include "tools/runfiles/runfiles_src.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
|
@ -12,7 +12,7 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include "cc/private/toolchain/runfiles/runfiles_src.h"
|
#include "tools/runfiles/runfiles_src.h"
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
Loading…
Reference in New Issue