Skip to content

Commit

Permalink
Add parameter to corrosion_import_crate to return list of added targe…
Browse files Browse the repository at this point in the history
…ts (#312)

* Allow retrieving list of imported crates
* Write about retrieving imported crates list in docs
  • Loading branch information
temeddix committed Jan 25, 2023
1 parent 34473df commit 44749a9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -196,6 +196,8 @@ corrosion_import_crate(MANIFEST_PATH <path/to/cargo.toml>
[NO_LINKER_OVERRIDE]
# Will let Rust/Cargo determine which linker to use instead of corrosion (when linking is invoked by Rust) (Ignored with CMake < 3.19)
[PROFILE <cargo-profile>]
# Retrieve the list of imported crates in the current scope
[IMPORTED_CRATES <variable-name>]
# Build only the specified crate types (Ignored with CMake < 3.19)
[CRATE_TYPES <crate_type1> ... <crate_typeN>]
# Only import the specified crates from a workspace
Expand Down
1 change: 1 addition & 0 deletions RELEASES.md
Expand Up @@ -29,6 +29,7 @@
- Get metadata with `--locked` (requires a lock-file). This might cause issues, reports are welcome.
- Experimental cxxbridge integration.
- Add a helper function to parse the package version from a Cargo.toml file
- Add new `IMPORTED_CRATES` flag to `corrosion_import_crate()` to retrieve the list of imported crates in the current scope ([#312](https://github.com/corrosion-rs/corrosion/pull/312)).

# 0.3.2 (2023-01-11)

Expand Down
6 changes: 5 additions & 1 deletion cmake/Corrosion.cmake
Expand Up @@ -1042,7 +1042,7 @@ endfunction()

function(corrosion_import_crate)
set(OPTIONS ALL_FEATURES NO_DEFAULT_FEATURES NO_STD NO_LINKER_OVERRIDE)
set(ONE_VALUE_KEYWORDS MANIFEST_PATH PROFILE)
set(ONE_VALUE_KEYWORDS MANIFEST_PATH PROFILE IMPORTED_CRATES)
set(MULTI_VALUE_KEYWORDS CRATE_TYPES CRATES FEATURES FLAGS)
cmake_parse_arguments(COR "${OPTIONS}" "${ONE_VALUE_KEYWORDS}" "${MULTI_VALUE_KEYWORDS}" ${ARGN})

Expand Down Expand Up @@ -1126,6 +1126,10 @@ function(corrosion_import_crate)
PROFILE
"${COR_PROFILE}"
)

if (DEFINED COR_IMPORTED_CRATES)
set(${COR_IMPORTED_CRATES} ${imported_crates} PARENT_SCOPE)
endif()
endif()
endfunction(corrosion_import_crate)

Expand Down
2 changes: 2 additions & 0 deletions cmake/CorrosionGenerator.cmake
Expand Up @@ -227,6 +227,8 @@ function(_generator_add_cargo_targets no_linker_override)
message(DEBUG "Corrosion created the following CMake targets: ${curr_created_targets}")
endif()

set(imported_crates ${created_targets} PARENT_SCOPE)

foreach(target_name ${created_targets})
foreach(output_var RUNTIME_OUTPUT_DIRECTORY ARCHIVE_OUTPUT_DIRECTORY LIBRARY_OUTPUT_DIRECTORY PDB_OUTPUT_DIRECTORY)
get_target_property(output_dir ${target_name} "${output_var}")
Expand Down

0 comments on commit 44749a9

Please sign in to comment.