-
Notifications
You must be signed in to change notification settings - Fork 248
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
fix linux cross compiling on macos #1062
Merged
jsharpe
merged 13 commits into
bazel-contrib:main
from
jungleraptor:isaac/fix-linux-xcompile-on-mac
Jun 27, 2023
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
53a67af
fix linux cross compiling on macos
jungleraptor e06e25b
add test
jungleraptor 18f1df7
linter
jungleraptor f7a0423
wip: handle cmake xcompile manual vars
jungleraptor cecfc9b
fix
jungleraptor 43c1ac1
update tests
jungleraptor d7be3c2
fix
jungleraptor e877142
format
jungleraptor 26fbd5c
add debug
jungleraptor 8581cd8
fix
jungleraptor 7a957fd
fix
jungleraptor 3581e34
linter
jungleraptor adcaf54
clean ups
jungleraptor 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 |
---|---|---|
|
@@ -17,9 +17,30 @@ def _escape_dquote_bash_crosstool(text): | |
# We use a starlark raw string to prevent the need to escape backslashes for starlark as well. | ||
return text.replace('"', r'\\\\\\\"') | ||
|
||
_TARGET_OS_PARAMS = { | ||
"android": { | ||
"ANDROID": "YES", | ||
"CMAKE_SYSTEM_NAME": "Linux", | ||
}, | ||
"linux": { | ||
"CMAKE_SYSTEM_NAME": "Linux", | ||
}, | ||
} | ||
|
||
_TARGET_ARCH_PARAMS = { | ||
"aarch64": { | ||
"CMAKE_SYSTEM_PROCESSOR": "aarch64", | ||
}, | ||
"x86_64": { | ||
"CMAKE_SYSTEM_PROCESSOR": "x86_64", | ||
}, | ||
} | ||
|
||
def create_cmake_script( | ||
workspace_name, | ||
target_os, | ||
target_arch, | ||
host_os, | ||
generator, | ||
cmake_path, | ||
tools, | ||
|
@@ -39,6 +60,8 @@ def create_cmake_script( | |
Args: | ||
workspace_name: current workspace name | ||
target_os: The target OS for the build | ||
target_arch: The target arch for the build | ||
host_os: The execution OS for the build | ||
generator: The generator target for cmake to use | ||
cmake_path: The path to the cmake executable | ||
tools: cc_toolchain tools (CxxToolsInfo) | ||
|
@@ -93,13 +116,13 @@ def create_cmake_script( | |
if not params.cache.get("CMAKE_RANLIB"): | ||
params.cache.update({"CMAKE_RANLIB": ""}) | ||
|
||
# Avoid cmake passing wrong linker flags when targeting android on macOS | ||
# https://github.com/bazelbuild/rules_foreign_cc/issues/289 | ||
if target_os == "android": | ||
params.cache.update({ | ||
"ANDROID": "YES", | ||
"CMAKE_SYSTEM_NAME": "Linux", | ||
}) | ||
# Avoid CMake passing the wrong linker flags when cross compiling | ||
# by setting CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR, | ||
# see https://github.com/bazelbuild/rules_foreign_cc/issues/289, | ||
# and https://github.com/bazelbuild/rules_foreign_cc/pull/1062 | ||
if target_os != host_os and target_os != "unknown": | ||
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. There's more to it than this (i.e. linux-x86_64 -> linux-aarch64). Probably should be a function like |
||
params.cache.update(_TARGET_OS_PARAMS.get(target_os, {})) | ||
params.cache.update(_TARGET_ARCH_PARAMS.get(target_arch, {})) | ||
|
||
set_env_vars = [ | ||
"export {}=\"{}\"".format(key, _escape_dquote_bash(params.env[key])) | ||
|
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
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.
There's a little more nuance to it than this (mostly on mac) but I think this is a good enough start.