-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mark module extension as reproducible #328
Open
fmeum
wants to merge
4
commits into
bazelbuild:master
Choose a base branch
from
fmeum:reproducible
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"""Extension configuring the C++ toolchain on macOS.""" | ||
|
||
load("@bazel_skylib//lib:modules.bzl", "modules") | ||
load("//crosstool/internal:setup.bzl", "apple_cc_autoconf", "apple_cc_autoconf_toolchains") | ||
|
||
def _apple_cc_configure_extension_impl(): | ||
apple_cc_autoconf_toolchains(name = "local_config_apple_cc_toolchains") | ||
apple_cc_autoconf(name = "local_config_apple_cc") | ||
|
||
apple_cc_configure_extension = modules.as_extension(_apple_cc_configure_extension_impl) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this repo we use |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"""Configure the Apple CC toolchain (internal part)""" | ||
|
||
load("//crosstool:osx_cc_configure.bzl", "configure_osx_toolchain") | ||
|
||
_DISABLE_ENV_VAR = "BAZEL_NO_APPLE_CPP_TOOLCHAIN" | ||
_OLD_DISABLE_ENV_VAR = "BAZEL_USE_CPP_ONLY_TOOLCHAIN" | ||
|
||
def _apple_cc_autoconf_toolchains_impl(repository_ctx): | ||
"""Generate BUILD file with 'toolchain' targets for the local host C++ toolchain. | ||
|
||
Args: | ||
repository_ctx: repository context | ||
""" | ||
env = repository_ctx.os.environ | ||
should_disable = _DISABLE_ENV_VAR in env and env[_DISABLE_ENV_VAR] == "1" | ||
old_should_disable = _OLD_DISABLE_ENV_VAR in env and env[_OLD_DISABLE_ENV_VAR] == "1" | ||
|
||
if should_disable or old_should_disable: | ||
repository_ctx.file("BUILD", "# Apple CC toolchain autoconfiguration was disabled by {} env variable.".format( | ||
_DISABLE_ENV_VAR if should_disable else _OLD_DISABLE_ENV_VAR, | ||
)) | ||
elif repository_ctx.os.name.startswith("mac os"): | ||
repository_ctx.symlink( | ||
repository_ctx.path(Label("@build_bazel_apple_support//crosstool:BUILD.toolchains")), | ||
"BUILD", | ||
) | ||
else: | ||
repository_ctx.file("BUILD", "# Apple CC toolchain autoconfiguration was disabled because you're not running on macOS") | ||
|
||
apple_cc_autoconf_toolchains = repository_rule( | ||
environ = [ | ||
_DISABLE_ENV_VAR, | ||
_OLD_DISABLE_ENV_VAR, | ||
], | ||
implementation = _apple_cc_autoconf_toolchains_impl, | ||
configure = True, | ||
) | ||
|
||
def _apple_cc_autoconf_impl(repository_ctx): | ||
env = repository_ctx.os.environ | ||
should_disable = _DISABLE_ENV_VAR in env and env[_DISABLE_ENV_VAR] == "1" | ||
old_should_disable = _OLD_DISABLE_ENV_VAR in env and env[_OLD_DISABLE_ENV_VAR] == "1" | ||
|
||
if should_disable or old_should_disable: | ||
repository_ctx.file("BUILD", "# Apple CC autoconfiguration was disabled by {} env variable.".format( | ||
_DISABLE_ENV_VAR if should_disable else _OLD_DISABLE_ENV_VAR, | ||
)) | ||
elif repository_ctx.os.name.startswith("mac os"): | ||
success, error = configure_osx_toolchain(repository_ctx) | ||
if not success: | ||
fail("Failed to configure Apple CC toolchain, if you only have the command line tools installed and not Xcode, you cannot use this toolchain. You should either remove it or temporarily set '{}=1' in the environment: {}".format(_DISABLE_ENV_VAR, error)) | ||
else: | ||
repository_ctx.file("BUILD", "# Apple CC autoconfiguration was disabled because you're not on macOS") | ||
|
||
apple_cc_autoconf = repository_rule( | ||
environ = [ | ||
_DISABLE_ENV_VAR, | ||
_OLD_DISABLE_ENV_VAR, | ||
"APPLE_SUPPORT_LAYERING_CHECK_BETA", | ||
"BAZEL_ALLOW_NON_APPLICATIONS_XCODE", # Signals to configure_osx_toolchain that some Xcodes may live outside of /Applications and we need to probe further when detecting/configuring them. | ||
"DEVELOPER_DIR", # Used for making sure we use the right Xcode for compiling toolchain binaries | ||
"GCOV", # TODO: Remove this | ||
"USE_CLANG_CL", # Kept as a hack for those who rely on this invaliding the toolchain | ||
"USER", # Used to allow paths for custom toolchains to be used by C* compiles | ||
"XCODE_VERSION", # Force re-computing the toolchain by including the current Xcode version info in an env var | ||
], | ||
implementation = _apple_cc_autoconf_impl, | ||
configure = True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,12 @@ | ||
"""Configure the Apple CC toolchain""" | ||
|
||
load("//crosstool:osx_cc_configure.bzl", "configure_osx_toolchain") | ||
|
||
_DISABLE_ENV_VAR = "BAZEL_NO_APPLE_CPP_TOOLCHAIN" | ||
_OLD_DISABLE_ENV_VAR = "BAZEL_USE_CPP_ONLY_TOOLCHAIN" | ||
|
||
def _apple_cc_autoconf_toolchains_impl(repository_ctx): | ||
"""Generate BUILD file with 'toolchain' targets for the local host C++ toolchain. | ||
|
||
Args: | ||
repository_ctx: repository context | ||
""" | ||
env = repository_ctx.os.environ | ||
should_disable = _DISABLE_ENV_VAR in env and env[_DISABLE_ENV_VAR] == "1" | ||
old_should_disable = _OLD_DISABLE_ENV_VAR in env and env[_OLD_DISABLE_ENV_VAR] == "1" | ||
|
||
if should_disable or old_should_disable: | ||
repository_ctx.file("BUILD", "# Apple CC toolchain autoconfiguration was disabled by {} env variable.".format( | ||
_DISABLE_ENV_VAR if should_disable else _OLD_DISABLE_ENV_VAR, | ||
)) | ||
elif repository_ctx.os.name.startswith("mac os"): | ||
repository_ctx.symlink( | ||
repository_ctx.path(Label("@build_bazel_apple_support//crosstool:BUILD.toolchains")), | ||
"BUILD", | ||
) | ||
else: | ||
repository_ctx.file("BUILD", "# Apple CC toolchain autoconfiguration was disabled because you're not running on macOS") | ||
|
||
_apple_cc_autoconf_toolchains = repository_rule( | ||
environ = [ | ||
_DISABLE_ENV_VAR, | ||
_OLD_DISABLE_ENV_VAR, | ||
], | ||
implementation = _apple_cc_autoconf_toolchains_impl, | ||
configure = True, | ||
) | ||
|
||
def _apple_cc_autoconf_impl(repository_ctx): | ||
env = repository_ctx.os.environ | ||
should_disable = _DISABLE_ENV_VAR in env and env[_DISABLE_ENV_VAR] == "1" | ||
old_should_disable = _OLD_DISABLE_ENV_VAR in env and env[_OLD_DISABLE_ENV_VAR] == "1" | ||
|
||
if should_disable or old_should_disable: | ||
repository_ctx.file("BUILD", "# Apple CC autoconfiguration was disabled by {} env variable.".format( | ||
_DISABLE_ENV_VAR if should_disable else _OLD_DISABLE_ENV_VAR, | ||
)) | ||
elif repository_ctx.os.name.startswith("mac os"): | ||
success, error = configure_osx_toolchain(repository_ctx) | ||
if not success: | ||
fail("Failed to configure Apple CC toolchain, if you only have the command line tools installed and not Xcode, you cannot use this toolchain. You should either remove it or temporarily set '{}=1' in the environment: {}".format(_DISABLE_ENV_VAR, error)) | ||
else: | ||
repository_ctx.file("BUILD", "# Apple CC autoconfiguration was disabled because you're not on macOS") | ||
|
||
_apple_cc_autoconf = repository_rule( | ||
environ = [ | ||
_DISABLE_ENV_VAR, | ||
_OLD_DISABLE_ENV_VAR, | ||
"APPLE_SUPPORT_LAYERING_CHECK_BETA", | ||
"BAZEL_ALLOW_NON_APPLICATIONS_XCODE", # Signals to configure_osx_toolchain that some Xcodes may live outside of /Applications and we need to probe further when detecting/configuring them. | ||
"DEVELOPER_DIR", # Used for making sure we use the right Xcode for compiling toolchain binaries | ||
"GCOV", # TODO: Remove this | ||
"USE_CLANG_CL", # Kept as a hack for those who rely on this invaliding the toolchain | ||
"USER", # Used to allow paths for custom toolchains to be used by C* compiles | ||
"XCODE_VERSION", # Force re-computing the toolchain by including the current Xcode version info in an env var | ||
], | ||
implementation = _apple_cc_autoconf_impl, | ||
configure = True, | ||
) | ||
load("//crosstool/internal:setup.bzl", "apple_cc_autoconf", "apple_cc_autoconf_toolchains") | ||
|
||
# buildifier: disable=unnamed-macro | ||
def apple_cc_configure(): | ||
_apple_cc_autoconf_toolchains(name = "local_config_apple_cc_toolchains") | ||
_apple_cc_autoconf(name = "local_config_apple_cc") | ||
apple_cc_autoconf_toolchains(name = "local_config_apple_cc_toolchains") | ||
apple_cc_autoconf(name = "local_config_apple_cc") | ||
native.register_toolchains( | ||
# Use register_toolchain's target pattern expansion to register all toolchains in the package. | ||
"@local_config_apple_cc_toolchains//:all", | ||
) | ||
|
||
def _apple_cc_configure_extension_impl(_): | ||
_apple_cc_autoconf_toolchains(name = "local_config_apple_cc_toolchains") | ||
_apple_cc_autoconf(name = "local_config_apple_cc") | ||
|
||
apple_cc_configure_extension = module_extension(implementation = _apple_cc_configure_extension_impl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file rename a breaking change for users? We have a blurb in the README that references the old name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be, yes. I think it's better to wait for apple_support to drop Bazel 5 support and then land this commit without the need for this breaking change.