@@ -31,6 +31,19 @@ option(
3131 OFF
3232)
3333
34+ if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_NAME STREQUAL "iOS" )
35+ if (DEFINED CORROSION_HOST_TARGET_LINKER)
36+ set (_corrosion_host_linker "${CORROSION_HOST_TARGET_LINKER} " )
37+ message (DEBUG "Using user provided CORROSION_HOST_TARGET_LINKER: ${CORROSION_HOST_TARGET_LINKER} " )
38+ else ()
39+ set (_corrosion_host_linker "/usr/bin/cc" )
40+ endif ()
41+ set (CORROSION_HOST_TARGET_LINKER "${_corrosion_host_linker} "
42+ CACHE STRING
43+ "The linker-driver corrosion will use to compile host-targets. Currently only used when cross-compiling for iOS."
44+ FORCE)
45+ endif ()
46+
3447find_package (Rust REQUIRED)
3548
3649if (CMAKE_GENERATOR MATCHES "Visual Studio"
@@ -794,27 +807,11 @@ function(_add_cargo_build out_cargo_build_out_dir)
794807 # (Presumably this is because XCode modifies PATH).
795808 # This causes linker errors, because Rust compiles build-scripts and proc-macros for the host-platform, and
796809 # assumes `cc` is a valid linker driver for the host platform (but in this case `cc` targets iOS).
797- # To work around this we explicitly set the linker for the host platform, and use a dummy CMake project
798- # to determine a suitable C compiler.
810+ # To work around this we explicitly set the linker for the host platform.
799811 unset (cargo_host_target_linker)
800812 if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_SYSTEM_NAME STREQUAL "iOS" )
801813 string (TOUPPER "${Rust_CARGO_HOST_TARGET_CACHED} " host_target_upper)
802814 string (REPLACE "-" "_" host_target_upper_underscore "${host_target_upper} " )
803- if (NOT DEFINED CACHE {CORROSION_HOST_TARGET_LINKER})
804- message (CHECK_START "CORROSION_HOST_TARGET_LINKER not defined - Determining linker for host architecture (${Rust_CARGO_HOST_TARGET_CACHED} )" )
805- unset (corrosion_host_c_compiler)
806- _corrosion_determine_host_compiler(corrosion_host_c_compiler cor_error_info)
807- set (host_target_linker_description "The linker-driver corrosion will use to compile host-targets. Currently only used when compiling for iOS." )
808- if (DEFINED corrosion_host_c_compiler)
809- message (CHECK_PASS "${corrosion_host_c_compiler} " )
810- set (CORROSION_HOST_TARGET_LINKER "${corrosion_host_c_compiler} " CACHE STRING "${host_target_linker_description} " )
811- else ()
812- set (fallback_linker "/usr/bin/cc" )
813- message (CHECK_FAIL "Failed - ${cor_error_info} . Falling back to ${fallback_linker} " )
814- set (CORROSION_HOST_TARGET_LINKER "${fallback_linker} " CACHE STRING "${host_target_linker_description} " )
815- endif ()
816- endif ()
817- _corrosion_determine_host_compiler(corrosion_host_c_compiler cor_error_info)
818815 set (cargo_host_target_linker "CARGO_TARGET_${host_target_upper_underscore} _LINKER=$CACHE{CORROSION_HOST_TARGET_LINKER} " )
819816 message (DEBUG "Setting `${cargo_host_target_linker} ` for target ${target_name} to workaround a hostbuild"
820817 " issue when building targets for iOS."
@@ -2312,52 +2309,6 @@ function(corrosion_parse_package_version package_manifest_path out_package_versi
23122309 endif ()
23132310endfunction ()
23142311
2315- function (_corrosion_determine_host_compiler host_c_compiler_out error_out)
2316- # Create minimal CMakeLists.txt to be generated for the host.
2317- set (package_dir "${CMAKE_BINARY_DIR} /corrosion/host_compiler" )
2318- file (REMOVE_RECURSE "${package_dir} " )
2319- file (MAKE_DIRECTORY "${package_dir} " )
2320- set (lists "cmake_minimum_required(VERSION 3.10)\n " )
2321- string (APPEND lists "project(CorrosionDetermineHostCompiler LANGUAGES C)\n " )
2322- # We add a `:` after the compiler so we can easily match the end, since `:` is
2323- # invalid in filenames.
2324- string (APPEND lists "message(STATUS \" HOST_C_COMPILER=\$ {CMAKE_C_COMPILER}:\" )\n " )
2325- file (WRITE "${package_dir} /CMakeLists.txt" "${lists} " )
2326-
2327- # Generate the CMake project.
2328- execute_process (
2329- COMMAND
2330- ${CMAKE_COMMAND} -E env
2331- --unset=SDKROOT
2332- ${CMAKE_COMMAND}
2333- -DCMAKE_CROSSCOMPILING=OFF
2334- -DCMAKE_SYSTEM_NAME=${CMAKE_HOST_SYSTEM_NAME}
2335- "${package_dir} "
2336- WORKING_DIRECTORY "${package_dir} "
2337- OUTPUT_VARIABLE host_detection_output
2338- ERROR_VARIABLE host_detection_error
2339- RESULT_VARIABLE host_detection_result
2340- OUTPUT_STRIP_TRAILING_WHITESPACE
2341- ERROR_STRIP_TRAILING_WHITESPACE
2342- )
2343-
2344- # Check if configuring the dummy CMake project failed.
2345- if (NOT host_detection_result EQUAL 0)
2346- message (WARNING "Failed to detect host compiler. Result: ${host_detection_result} \n "
2347- "Output: ${host_detection_output} \n "
2348- "Error: ${host_detection_error} " )
2349- return ()
2350- endif ()
2351-
2352- # Extract C compiler from the output.
2353- string (REGEX MATCH "HOST_C_COMPILER=([^:\r\n ]*):" host_c_compiler_match "${host_detection_output} " )
2354- if (host_c_compiler_match)
2355- set ("${host_c_compiler_out} " "${CMAKE_MATCH_1} " PARENT_SCOPE)
2356- else ()
2357- set ("${error_out} " "Regex match failure: ${host_detection_output} " )
2358- endif ()
2359- endfunction ()
2360-
23612312function (_corrosion_initialize_properties target_name)
23622313 # Initialize the `<XYZ>_OUTPUT_DIRECTORY` properties based on `CMAKE_<XYZ>_OUTPUT_DIRECTORY`.
23632314 foreach (output_var RUNTIME_OUTPUT_DIRECTORY ARCHIVE_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY PDB_OUTPUT_DIRECTORY )
0 commit comments