-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
configure_make: support autotools cross-compilation
This teaches the autotools-based configure script to pass --host when cross-compilation is detected. This fixes at least part of #1082. This functionality is off by default (because configure_make can be used for non-autotools builds) and can be enabled by passing configure_xcompile to configure_make. This functionality is also extended to the built_tools that use autoconf (pkg-config and make). It also does a bit of generalization to make it easier to support more platforms in the future, and adds s390x to the detected arches.
- Loading branch information
Showing
9 changed files
with
247 additions
and
28 deletions.
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
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
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
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,61 @@ | ||
# buildifier: disable=module-docstring | ||
load( | ||
"//foreign_cc/private/framework:platform.bzl", | ||
"arch_name", | ||
"os_name", | ||
"target_arch_name", | ||
"target_os_name", | ||
"triplet_name", | ||
) | ||
|
||
def detect_xcompile(ctx): | ||
"""A helper function for detecting and setting autoconf-style xcompile flags | ||
Args: | ||
ctx (ctx): The current rule's context object | ||
Returns: | ||
list(str): The flags to set, or None if xcompiling is disabled | ||
""" | ||
|
||
if not ctx.attr.configure_xcompile: | ||
return None | ||
|
||
host_triplet = triplet_name( | ||
os_name(ctx), | ||
arch_name(ctx), | ||
) | ||
|
||
if host_triplet == "unknown": | ||
# buildifier: disable=print | ||
print("host is unknown; please update foreign_cc/private/framework/platform.bzl") | ||
return None | ||
|
||
target_triplet = triplet_name( | ||
target_os_name(ctx), | ||
target_arch_name(ctx), | ||
) | ||
|
||
if target_triplet == "unknown": | ||
# buildifier: disable=print | ||
print("target is unknown; please update foreign_cc/private/framework/platform.bzl") | ||
return None | ||
|
||
if target_triplet == host_triplet: | ||
return None | ||
|
||
# We pass both --host and --build here, even though we technically only | ||
# need to pass --host. This is because autotools compares them (without | ||
# normalization) to determine if a build is a cross-compile | ||
# | ||
# If we don't pass --build, autotools will populate it itself, and it might | ||
# be normalized such that autotools thinks it's a cross-compile, but it | ||
# shouldn't be. | ||
# | ||
# An example of this is if we pass --host=x86_64-pc-linux-gnu but the | ||
# target compiler thinks it's for x86_64-unknown-linux-gnu; if we don't | ||
# pass --build, that will incorrectly be considered a cross-compile. | ||
# | ||
# Also, no, this isn't backwards. --host means target | ||
# https://www.gnu.org/software/automake/manual/html_node/Cross_002dCompilation.html | ||
return ["--host=" + target_triplet, "--build=" + host_triplet] |
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
Oops, something went wrong.