Skip to content

Commit

Permalink
Select Legacy Generator lockfile based on Rust version
Browse files Browse the repository at this point in the history
This preserves compatibility with stable Rust versions below 1.56
while fixing nightly Rust for the legacy CMake Generator.
  • Loading branch information
jschwe committed Aug 8, 2023
1 parent 1752605 commit 19a288a
Show file tree
Hide file tree
Showing 8 changed files with 282 additions and 58 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ jobs:
os: ubuntu-20.04
rust: nightly

test_legacy_new_lockfile_msrv:
name: Test MSRV of the new lockfile
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Install Rust
id: install_rust
uses: dtolnay/rust-toolchain@1.56
- name: Test Generator build with MSRV
run: cargo build
working-directory: generator

test:
name: Test Corrosion
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -326,6 +338,7 @@ jobs:
- test_legacy_mac
- test_legacy_windows
- test_legacy_stable
- test_legacy_new_lockfile_msrv
- test
- test_msvc
- test_cxxbridge
Expand Down
12 changes: 4 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,11 @@ endif()
include(GNUInstallDirs)

if(CORROSION_INSTALL_EXECUTABLE)
# Builds the generator executable
corrosion_import_crate(MANIFEST_PATH generator/Cargo.toml)

set(_CORROSION_GENERATOR_DESTINATION "${CMAKE_INSTALL_FULL_LIBEXECDIR}")

corrosion_install(
TARGETS corrosion-generator
DESTINATION "${_CORROSION_GENERATOR_DESTINATION}"
get_property(
_CORROSION_GENERATOR_EXE
TARGET Corrosion::Generator PROPERTY IMPORTED_LOCATION
)
install(PROGRAMS "${_CORROSION_GENERATOR_EXE}" DESTINATION "${CMAKE_INSTALL_FULL_LIBEXECDIR}")
else()
message(DEBUG "Not installing corrosion-generator since "
"`CORROSION_INSTALL_EXECUTABLE` is set to ${CORROSION_INSTALL_EXECUTABLE}"
Expand Down
15 changes: 7 additions & 8 deletions cmake/Corrosion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -571,20 +571,19 @@ endif()
if(CORROSION_NATIVE_TOOLING)
if (NOT TARGET Corrosion::Generator )
add_subdirectory(generator)
else()
get_property(
_CORROSION_GENERATOR_EXE
TARGET Corrosion::Generator PROPERTY IMPORTED_LOCATION
)
endif()
get_property(
_CORROSION_GENERATOR_EXE
TARGET Corrosion::Generator PROPERTY IMPORTED_LOCATION
)
set(
_CORROSION_GENERATOR
${CMAKE_COMMAND} -E env
_CORROSION_GENERATOR
${CMAKE_COMMAND} -E env
CARGO_BUILD_RUSTC=${RUSTC_EXECUTABLE}
${_CORROSION_GENERATOR_EXE}
--cargo ${CARGO_EXECUTABLE}
${_CORROSION_VERBOSE_OUTPUT_FLAG}
CACHE INTERNAL "corrosion-generator runner"
CACHE INTERNAL "corrosion-generator runner"
)
endif()

Expand Down
24 changes: 21 additions & 3 deletions generator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
message(STATUS "Building CMake Generator for Corrosion - This may take a while")

set(generator_destination "${CMAKE_CURRENT_BINARY_DIR}/legacy_generator_src")
set(generator_src "${CMAKE_CURRENT_BINARY_DIR}/legacy_generator_src")
set(generator_destination "${CMAKE_CURRENT_BINARY_DIR}/legacy_generator")
set(generator_build_quiet "")

file(MAKE_DIRECTORY "${generator_src}")
file(COPY src DESTINATION "${generator_src}")
if(Rust_VERSION VERSION_LESS "1.56")
message(STATUS "Corrosion Generator: Using Compatibility lock file, due to rust version less than 1.56")
file(COPY Compat.Cargo.lock Compat.Cargo.toml DESTINATION "${generator_src}")
file(RENAME "${generator_src}/Compat.Cargo.lock" "${generator_src}/Cargo.lock")
file(RENAME "${generator_src}/Compat.Cargo.toml" "${generator_src}/Cargo.toml")
else()
file(COPY Cargo.lock Cargo.toml DESTINATION "${generator_src}")
endif()

# Using cargo install has the advantage of caching the build in the user .cargo directory,
# so likely the rebuild will be very cheap even after deleting the build directory.
execute_process(
Expand All @@ -18,7 +29,7 @@ execute_process(
--root "${generator_destination}"
--locked
${_CORROSION_QUIET_OUTPUT_FLAG}
WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}"
WORKING_DIRECTORY "${generator_src}"
RESULT_VARIABLE generator_build_failed
)
if(generator_build_failed)
Expand All @@ -30,9 +41,16 @@ set(host_executable_suffix "")
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
set(host_executable_suffix ".exe")
endif()

set(_CORROSION_GENERATOR_EXE
"${generator_destination}/bin/corrosion-generator${host_executable_suffix}"
PARENT_SCOPE)
)

add_executable(Corrosion::Generator IMPORTED GLOBAL)
set_property(
TARGET Corrosion::Generator
PROPERTY IMPORTED_LOCATION "${_CORROSION_GENERATOR_EXE}")

if (CORROSION_DEV_MODE)
# If you're developing Corrosion, you want to make sure to re-configure whenever the
# generator changes.
Expand Down
62 changes: 30 additions & 32 deletions generator/Cargo.lock

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

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

[dependencies]
cargo_metadata = "0.15"
# The crates below are indirect dependencies of cargo metadata,
# We explicitly specify maximum versions to allow building the generator
# with older toolchains.
# Version 1.0.157 upgrades to syn 2.0 and raises MSRV to 1.56
serde = { version = ">=1, <1.0.157", default-features=false }
# Version 1.0.40 upgrades to syn 2.0 and raises MSRV to 1.56
thiserror = { version = ">=1, <1.0.40", default-features=false }

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

0 comments on commit 19a288a

Please sign in to comment.