@@ -45,6 +45,7 @@ def create_cmake_script(
45
45
target_os ,
46
46
target_arch ,
47
47
host_os ,
48
+ host_arch ,
48
49
generator ,
49
50
cmake_path ,
50
51
tools ,
@@ -68,6 +69,7 @@ def create_cmake_script(
68
69
target_os: The target OS for the build
69
70
target_arch: The target arch for the build
70
71
host_os: The execution OS for the build
72
+ host_arch: The execution arch for the build
71
73
generator: The generator target for cmake to use
72
74
cmake_path: The path to the cmake executable
73
75
tools: cc_toolchain tools (CxxToolsInfo)
@@ -93,6 +95,23 @@ def create_cmake_script(
93
95
toolchain_dict = _fill_crossfile_from_toolchain (workspace_name , tools , flags , target_os )
94
96
params = None
95
97
98
+ # Avoid CMake passing the wrong linker flags when cross compiling
99
+ # by setting CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR,
100
+ # see https://github.com/bazel-contrib/rules_foreign_cc/issues/289,
101
+ # and https://github.com/bazel-contrib/rules_foreign_cc/pull/1062
102
+ # note: these parameters must be set in the toolchain file, not just in the
103
+ # cache, and CMAKE_SYSTEM_PROCESSOR is ignored unless CMAKE_SYSTEM_NAME is
104
+ # also set.
105
+ if target_os == "unknown" :
106
+ # buildifier: disable=print
107
+ print ("target_os is unknown, please update foreign_cc/private/framework/platform.bzl and foreign_cc/private/cmake_script.bzl; triggered by" , current_label )
108
+ elif target_arch == "unknown" :
109
+ # buildifier: disable=print
110
+ print ("target_arch is unknown, please update foreign_cc/private/framework/platform.bzl and foreign_cc/private/cmake_script.bzl; triggered by" , current_label )
111
+ elif target_os != host_os or target_arch != host_arch :
112
+ toolchain_dict .update (_TARGET_OS_PARAMS .get (target_os , {}))
113
+ toolchain_dict .update (_TARGET_ARCH_PARAMS .get (target_arch , {}))
114
+
96
115
keys_with_empty_values_in_user_cache = [key for key in user_cache if user_cache .get (key ) == "" ]
97
116
98
117
if no_toolchain_file :
@@ -123,17 +142,6 @@ def create_cmake_script(
123
142
if not params .cache .get ("CMAKE_RANLIB" ):
124
143
params .cache .update ({"CMAKE_RANLIB" : "" })
125
144
126
- # Avoid CMake passing the wrong linker flags when cross compiling
127
- # by setting CMAKE_SYSTEM_NAME and CMAKE_SYSTEM_PROCESSOR,
128
- # see https://github.com/bazel-contrib/rules_foreign_cc/issues/289,
129
- # and https://github.com/bazel-contrib/rules_foreign_cc/pull/1062
130
- if target_os == "unknown" :
131
- # buildifier: disable=print
132
- print ("target_os is unknown, please update foreign_cc/private/framework/platform.bzl and foreign_cc/private/cmake_script.bzl; triggered by" , current_label )
133
- elif target_os != host_os :
134
- params .cache .update (_TARGET_OS_PARAMS .get (target_os , {}))
135
- params .cache .update (_TARGET_ARCH_PARAMS .get (target_arch , {}))
136
-
137
145
set_env_vars = [
138
146
"export {}=\" {}\" " .format (key , _escape_dquote_bash (params .env [key ]))
139
147
for key in params .env
@@ -194,6 +202,7 @@ _CMAKE_ENV_VARS_FOR_CROSSTOOL = {
194
202
}
195
203
196
204
_CMAKE_CACHE_ENTRIES_CROSSTOOL = {
205
+ "ANDROID" : struct (value = "ANDROID" , replace = False ),
197
206
"CMAKE_AR" : struct (value = "CMAKE_AR" , replace = True ),
198
207
"CMAKE_ASM_FLAGS" : struct (value = "CMAKE_ASM_FLAGS_INIT" , replace = False ),
199
208
"CMAKE_CXX_ARCHIVE_CREATE" : struct (value = "CMAKE_CXX_ARCHIVE_CREATE" , replace = False ),
@@ -206,6 +215,8 @@ _CMAKE_CACHE_ENTRIES_CROSSTOOL = {
206
215
"CMAKE_RANLIB" : struct (value = "CMAKE_RANLIB" , replace = True ),
207
216
"CMAKE_SHARED_LINKER_FLAGS" : struct (value = "CMAKE_SHARED_LINKER_FLAGS_INIT" , replace = False ),
208
217
"CMAKE_STATIC_LINKER_FLAGS" : struct (value = "CMAKE_STATIC_LINKER_FLAGS_INIT" , replace = False ),
218
+ "CMAKE_SYSTEM_NAME" : struct (value = "CMAKE_SYSTEM_NAME" , replace = False ),
219
+ "CMAKE_SYSTEM_PROCESSOR" : struct (value = "CMAKE_SYSTEM_PROCESSOR" , replace = False ),
209
220
}
210
221
211
222
def _create_crosstool_file_text (toolchain_dict , user_cache , user_env ):
0 commit comments