Skip to content

Commit

Permalink
Don't use --target cargo flag when compiling to host
Browse files Browse the repository at this point in the history
  • Loading branch information
Luthaf committed Sep 5, 2023
1 parent 9a46735 commit e1ab54b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions rascaline-c-api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,29 @@ endif()

set(CARGO_TARGET_DIR ${CMAKE_CURRENT_BINARY_DIR}/target)
set(CARGO_BUILD_ARG "${CARGO_BUILD_ARG};--target-dir=${CARGO_TARGET_DIR}")

# Handle cross compilation with RUST_BUILD_TARGET
if ("${RUST_BUILD_TARGET}" STREQUAL "")
if (CARGO_VERSION_RAW MATCHES "host: ([a-zA-Z0-9_\\-]*)\n")
set(RUST_BUILD_TARGET "${CMAKE_MATCH_1}")
if (CARGO_VERSION_RAW MATCHES "host: ([a-zA-Z0-9_\\-]*)\n")
set(RUST_HOST_TARGET "${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR "failed to determine host target, output was: ${CARGO_VERSION_RAW}")
endif()
endif()

set(CARGO_BUILD_ARG "${CARGO_BUILD_ARG};--target=${RUST_BUILD_TARGET}")
set(CARGO_OUTPUT_DIR "${CARGO_TARGET_DIR}/${RUST_BUILD_TARGET}/${CARGO_BUILD_TYPE}")
if (${RASCALINE_MAIN_PROJECT})
message(STATUS "Compiling to host (${RUST_HOST_TARGET})")
endif()

set(CARGO_OUTPUT_DIR "${CARGO_TARGET_DIR}/${CARGO_BUILD_TYPE}")
set(RUST_BUILD_TARGET ${RUST_HOST_TARGET})
else()
if (${RASCALINE_MAIN_PROJECT})
message(STATUS "Cross-compiling to ${RUST_BUILD_TARGET}")
endif()

set(CARGO_BUILD_ARG "${CARGO_BUILD_ARG};--target=${RUST_BUILD_TARGET}")
set(CARGO_OUTPUT_DIR "${CARGO_TARGET_DIR}/${RUST_BUILD_TARGET}/${CARGO_BUILD_TYPE}")
endif()

if (NOT ${RASCALINE_ENABLE_CHEMFILES})
set(CARGO_BUILD_ARG "${CARGO_BUILD_ARG};--no-default-features")
Expand Down

0 comments on commit e1ab54b

Please sign in to comment.