Skip to content

Commit

Permalink
Simplify native CMake generator
Browse files Browse the repository at this point in the history
After the previous refactoring of Corrosion CMake code, we can now reuse
a significant portion of logic and greatly simplify
the Rust application that generates some CMake code.

We still need it for legacy CMake versions to parse JSON, but a lot of
functionality was already implemented in CMake.

This commit removes this code duplication.
  • Loading branch information
jschwe committed Sep 12, 2022
1 parent 49dba3f commit a498c62
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 558 deletions.
31 changes: 2 additions & 29 deletions cmake/Corrosion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,8 @@ function(corrosion_import_crate)
set(COR_MANIFEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${COR_MANIFEST_PATH})
endif()

_corrosion_parse_platform(${COR_MANIFEST_PATH} ${Rust_VERSION} ${_CORROSION_RUST_CARGO_TARGET})

if (CORROSION_NATIVE_TOOLING)
execute_process(
COMMAND
Expand All @@ -795,27 +797,6 @@ function(corrosion_import_crate)
set (_CORROSION_CONFIGURATION_ROOT --configuration-root ${CMAKE_VS_PLATFORM_NAME})
endif()

if (_CORROSION_RUST_CARGO_TARGET)
set(_CORROSION_TARGET --target ${_CORROSION_RUST_CARGO_TARGET})
endif()

if(CMAKE_CONFIGURATION_TYPES)
string (REPLACE ";" "," _CONFIGURATION_TYPES
"${CMAKE_CONFIGURATION_TYPES}")
set (_CORROSION_CONFIGURATION_TYPES --configuration-types
${_CONFIGURATION_TYPES})
elseif(CMAKE_BUILD_TYPE)
set (_CORROSION_CONFIGURATION_TYPES --configuration-type
${CMAKE_BUILD_TYPE})
else()
# uses default build type
endif()

set(no_default_libs_arg)
if(COR_NO_STD)
set(no_default_libs_arg "--no-default-libraries")
endif()

set(crates_args)
foreach(crate ${COR_CRATES})
list(APPEND crates_args --crates ${crate})
Expand All @@ -827,12 +808,8 @@ function(corrosion_import_crate)
--manifest-path ${COR_MANIFEST_PATH}
gen-cmake
${_CORROSION_CONFIGURATION_ROOT}
${_CORROSION_TARGET}
${_CORROSION_CONFIGURATION_TYPES}
${crates_args}
${cargo_profile}
${no_default_libs_arg}
--cargo-version ${_CORROSION_CARGO_VERSION}
-o ${generated_cmake}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
RESULT_VARIABLE ret)
Expand All @@ -846,10 +823,6 @@ function(corrosion_import_crate)
_generator_add_cargo_targets(
MANIFEST_PATH
"${COR_MANIFEST_PATH}"
TARGET
"${_CORROSION_RUST_CARGO_TARGET}"
RUST_VERSION
"${Rust_VERSION}"
CRATES
"${COR_CRATES}"
PROFILE
Expand Down
4 changes: 1 addition & 3 deletions cmake/CorrosionGenerator.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ endfunction()

function(_generator_add_cargo_targets)
set(options "")
set(one_value_args MANIFEST_PATH TARGET RUST_VERSION PROFILE)
set(one_value_args MANIFEST_PATH PROFILE)
set(multi_value_args CRATES)
cmake_parse_arguments(
GGC
Expand All @@ -124,8 +124,6 @@ function(_generator_add_cargo_targets)
string(JSON ws_mems_len LENGTH ${workspace_members})
math(EXPR ws_mems_len-1 "${ws_mems_len} - 1")

_corrosion_parse_platform(${GGC_MANIFEST_PATH} ${GGC_RUST_VERSION} ${GGC_TARGET})

set(created_targets "")
foreach(ix RANGE ${pkgs_len-1})
string(JSON pkg GET "${packages}" ${ix})
Expand Down
72 changes: 32 additions & 40 deletions generator/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ edition = "2018"

[dependencies]
cargo_metadata = "0.14"
semver = "1.0"
platforms = "2.0"

[dependencies.clap]
version = "2.34"
Expand Down
Loading

0 comments on commit a498c62

Please sign in to comment.