diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f7c784d7..9bd60ae9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -9,58 +9,6 @@ on: - 'stable/**' jobs: - test_legacy_linux: - name: Test Corrosion (CMake 3.15) - uses: ./.github/workflows/test_legacy.yaml - with : - os: ubuntu-20.04 - rust: 1.46.0 - test_legacy_mac: - name: Test Corrosion (CMake 3.15) - uses: ./.github/workflows/test_legacy.yaml - with: - os: macos-12 - rust: 1.54.0 - test_legacy_windows: - name: Test Corrosion (CMake 3.15) - uses: ./.github/workflows/test_legacy.yaml - with: - os: windows-2019 - rust: 1.46.0 - - test_legacy_stable: - name: Legacy CMake + stable Rust - uses: ./.github/workflows/test_legacy.yaml - strategy: - fail-fast: false - matrix: - os: - - windows-2019 # windows-latest is currently not having a supported MSVC compiler - - ubuntu-20.04 - - macos-12 - with: - os: ${{ matrix.os }} - rust: stable - - test_legacy_nightly: - name: Legacy CMake + nightly Rust - uses: ./.github/workflows/test_legacy.yaml - with: - 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 }} @@ -82,35 +30,34 @@ jobs: - darwin - msvc cmake: - - 3.19.0 + - 3.22.0 rust: - # Our MSRV is already tested with the legacy generator, so just test the current stable rust here. - - stable + - "stable" generator: - default # This is just whatever the platform default is - ninja compiler: [default] include: - rust: nightly - cmake: 3.19.0 + cmake: 3.22.0 generator: ninja arch: x86_64 abi: msvc os: windows-2019 - rust: nightly - cmake: 3.19.0 + cmake: 3.22.0 generator: ninja arch: x86_64 abi: gnu os: ubuntu-latest - rust: nightly - cmake: 3.19.0 + cmake: 3.22.0 generator: ninja arch: x86_64 abi: darwin os: macos-12 - rust: 1.54 - cmake: 3.19.0 + cmake: 3.22.0 generator: ninja arch: x86_64 abi: msvc @@ -119,7 +66,7 @@ jobs: - os: ubuntu-latest arch: x86_64 abi: gnu - cmake: 3.20.0 + cmake: 3.22.0 rust: 1.54 generator: ninja-multiconfig @@ -199,9 +146,9 @@ jobs: - arch: x86_64 rust: 1.46.0 - os: windows-2019 - cmake: 3.20.6 # Multi-config Generators require at least CMake 3.20 + cmake: 3.22.0 # Multi-config Generators require at least CMake 3.20 - os: windows-2022 - cmake: 3.21.5 # VS on windows-2022 requires at least CMake 3.21 + cmake: 3.22.0 steps: - uses: actions/checkout@v3 @@ -259,7 +206,7 @@ jobs: uses: "./.github/actions/setup_test" with: target_arch: x86_64 - cmake: 3.15.7 + cmake: 3.22.0 rust: stable minus 2 releases abi: ${{ matrix.abi }} generator: ninja @@ -290,7 +237,7 @@ jobs: - name: Install CMake uses: corrosion-rs/install-cmake@v2 with: - cmake: 3.18.0 + cmake: 3.22.0 ninja: 1.10.0 - name: Install Rust uses: dtolnay/rust-toolchain@master @@ -334,11 +281,6 @@ jobs: name: bors-ci-status if: ${{ always() }} needs: - - test_legacy_linux - - test_legacy_mac - - test_legacy_windows - - test_legacy_stable - - test_legacy_new_lockfile_msrv - test - test_msvc - test_cxxbridge diff --git a/.github/workflows/test_legacy.yaml b/.github/workflows/test_legacy.yaml deleted file mode 100644 index 8aa95462..00000000 --- a/.github/workflows/test_legacy.yaml +++ /dev/null @@ -1,80 +0,0 @@ -name: Test Corrosion using prebuilt legacy generator - -on: - workflow_call: - inputs: - os: - required: true - type: string - rust: - required: false - type: string - default: 1.46.0 - target_arch: - required: false - type: string - default: x86_64 - generator: - required: false - type: string - default : ninja - -jobs: - test_legacy: - name: Test (${{inputs.os}}) - runs-on: ${{ inputs.os }} - strategy: - fail-fast: false - steps: - - uses: actions/checkout@v3 - - name: Cache Legacy Generator - id: cache_generator - uses: actions/cache@v3 - with: - path: ${{github.workspace}}/corrosion-prebuilt-generator - key: ${{ runner.os }}-${{ inputs.rust }}-generator-${{ hashFiles('generator/src/**', 'generator/Cargo.toml', 'generator/Cargo.lock') }} - - name: Setup Environment and Configure CMake - uses: "./.github/actions/setup_test" - with: - target_arch: x86_64 - cmake: 3.15.7 - rust: ${{inputs.rust}} - generator: ninja - build_dir: build - install_path: ${{github.workspace}}/corrosion-prebuilt-generator - configure_params: "-DCMAKE_BUILD_TYPE=Release" - if: steps.cache_generator.outputs.cache-hit != 'true' - - name: Build corrosion - run: cmake --build build --config Release - if: steps.cache_generator.outputs.cache-hit != 'true' - - name: Install corrosion - run: cmake --install build --config Release - if: steps.cache_generator.outputs.cache-hit != 'true' - - name: Determine Corrosion Generator path - id: cor_gen - shell: bash - run: | - export base_generator_bin="${{github.workspace}}/corrosion-prebuilt-generator/libexec/corrosion-generator" - if [ "${{ runner.os }}" == "Windows" ]; then - echo "generator_bin=${base_generator_bin}.exe" >> $GITHUB_OUTPUT - else - echo "generator_bin=${base_generator_bin}" >> $GITHUB_OUTPUT - chmod +x "${base_generator_bin}" - fi - - name: Setup Environment and Configure CMake - uses: "./.github/actions/setup_test" - with: - target_arch: ${{inputs.target_arch}} - cmake: 3.15.7 - rust: ${{inputs.rust}} - generator: ${{inputs.generator}} - build_dir: build - configure_params: "-DCORROSION_GENERATOR_EXECUTABLE=${{steps.cor_gen.outputs.generator_bin}}" - - name: Run Tests - id: run_tests - working-directory: build - run: ctest --build-config Debug -j 3 - - name: Rerun failed tests verbose - working-directory: build - run: ctest --rerun-failed --verbose --build-config Debug - if: ${{ failure() && steps.run_tests.conclusion == 'failure' }} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 678d133b..c56d9063 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,11 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.22) project(Corrosion # Official releases will be major.minor.patch. When the `tweak` field is # set it indicates that we are on a commit, that is not a officially # tagged release. Users don't need to care about this, it is mainly to # clearly see in configure logs which version was used, without needing to # rely on `git`, since Corrosion may be installed or otherwise packaged. - VERSION 0.4.3 + VERSION 0.4.99.99 # a 0.5-pre-release LANGUAGES NONE HOMEPAGE_URL "https://corrosion-rs.github.io/corrosion/" ) @@ -22,12 +22,6 @@ endif() # ==== Corrosion Configuration ==== -option( - CORROSION_DEV_MODE - "Enables some additional features if you're developing Corrosion" - ${_CORROSION_TOP_LEVEL} -) - option( CORROSION_BUILD_TESTS "Build Corrosion test project" @@ -39,18 +33,6 @@ set( "Use prebuilt, non-bootstrapped corrosion-generator") mark_as_advanced(CORROSION_GENERATOR_EXECUTABLE) -if (CORROSION_GENERATOR_EXECUTABLE) - add_executable(Corrosion::Generator IMPORTED GLOBAL) - set_property( - TARGET Corrosion::Generator - PROPERTY IMPORTED_LOCATION ${CORROSION_GENERATOR_EXECUTABLE}) - set(CORROSION_INSTALL_EXECUTABLE_DEFAULT OFF) -elseif(CORROSION_NATIVE_TOOLING OR CMAKE_VERSION VERSION_LESS 3.19.0) - set(CORROSION_INSTALL_EXECUTABLE_DEFAULT "ON") -else() - set(CORROSION_INSTALL_EXECUTABLE_DEFAULT OFF) -endif() - option( CORROSION_INSTALL_EXECUTABLE "Controls whether corrosion-generator is installed with the package" @@ -58,6 +40,11 @@ option( ) mark_as_advanced(CORROSION_INSTALL_EXECUTABLE) +if (CORROSION_GENERATOR_EXECUTABLE OR CORROSION_INSTALL_EXECUTABLE) + message(FATAL_ERROR "The Cache variables CORROSION_GENERATOR_EXECUTABLE CORROSION_INSTALL_EXECUTABLE" + " were removed.") +endif() + if (_CORROSION_TOP_LEVEL) # We need to enable a language for corrosions test to work. # For projects using corrosion this is not needed @@ -87,18 +74,6 @@ endif() include(GNUInstallDirs) -if(CORROSION_INSTALL_EXECUTABLE) - 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}" - ) -endif() - # Generate the Config file include(CMakePackageConfigHelpers) diff --git a/README.md b/README.md index fa14ad4e..10fbeb27 100644 --- a/README.md +++ b/README.md @@ -38,3 +38,13 @@ add_executable(your_cpp_bin main.cpp) target_link_libraries(your_cpp_bin PUBLIC rust-lib) ``` +## Requirements + +### Stable v0.4 Release + +- CMake 3.15 or newer. Some features may only be available on more recents CMake versions +- Rust 1.46 or newer. Some platforms / features may require more recent Rust versions + +### Development (master branch) + +- CMake 3.22 or newer diff --git a/RELEASES.md b/RELEASES.md index 7a9097c6..996f7e7a 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,10 @@ +# Unreleased + +### Breaking Changes + +- The master branch of corrosion now requires CMake 3.22. See also the + [v0.4.0 Release notes](#040-lts-2023-06-01) for more details. + # v0.4.3 (2023-09-09) ### Fixes diff --git a/cmake/Corrosion.cmake b/cmake/Corrosion.cmake index 876ae5c1..152af2c2 100644 --- a/cmake/Corrosion.cmake +++ b/cmake/Corrosion.cmake @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.22) list(APPEND CMAKE_MESSAGE_CONTEXT "Corrosion") @@ -10,14 +10,8 @@ get_cmake_property(COR_IS_MULTI_CONFIG GENERATOR_IS_MULTI_CONFIG) set(COR_IS_MULTI_CONFIG "${COR_IS_MULTI_CONFIG}" CACHE BOOL "Do not change this" FORCE) mark_as_advanced(FORCE COR_IS_MULTI_CONFIG) -if (COR_IS_MULTI_CONFIG AND CMAKE_VERSION VERSION_LESS 3.20.0) - message(FATAL_ERROR "Corrosion requires at least CMake 3.20 with Multi-Config Generators such as " - "\"Ninja Multi-Config\" or Visual Studio. " - "Please use a different generator or update to cmake >= 3.20.\n" - "Note: You are using CMake ${CMAKE_VERSION} (Path: `${CMAKE_COMMAND}`) with " - " the `${CMAKE_GENERATOR}` Generator." - ) -elseif(NOT COR_IS_MULTI_CONFIG AND DEFINED CMAKE_CONFIGURATION_TYPES) + +if(NOT COR_IS_MULTI_CONFIG AND DEFINED CMAKE_CONFIGURATION_TYPES) message(WARNING "The Generator is ${CMAKE_GENERATOR}, which is not a multi-config " "Generator, but CMAKE_CONFIGURATION_TYPES is set. Please don't set " "CMAKE_CONFIGURATION_TYPES unless you are using a multi-config Generator." @@ -93,9 +87,7 @@ if(CMAKE_GENERATOR MATCHES "Visual Studio" " causes the build to fail. Please upgrade your Rust version to 1.54 or newer.") endif() -if (NOT TARGET Corrosion::Generator) - message(STATUS "Using Corrosion as a subdirectory") -endif() +# message(STATUS "Using Corrosion as a subdirectory") get_property( RUSTC_EXECUTABLE @@ -555,9 +547,7 @@ function(_corrosion_add_bin_target workspace_manifest_path bin_name out_bin_bypr endfunction() -if (NOT CORROSION_NATIVE_TOOLING) - include(CorrosionGenerator) -endif() +include(CorrosionGenerator) # Note: `cmake_language(GET_MESSAGE_LOG_LEVEL )` requires CMake 3.25, # so we offer our own option to control verbosity of downstream commands (e.g. cargo build) @@ -568,25 +558,6 @@ else() set(_CORROSION_QUIET_OUTPUT_FLAG --quiet) endif() -if(CORROSION_NATIVE_TOOLING) - if (NOT TARGET Corrosion::Generator ) - add_subdirectory(generator) - endif() - get_property( - _CORROSION_GENERATOR_EXE - TARGET Corrosion::Generator PROPERTY IMPORTED_LOCATION - ) - set( - _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" - ) -endif() - set(_CORROSION_CARGO_VERSION ${Rust_CARGO_VERSION} CACHE INTERNAL "cargo version used by corrosion") set(_CORROSION_RUST_CARGO_TARGET ${Rust_CARGO_TARGET} CACHE INTERNAL "target triple used by corrosion") set(_CORROSION_RUST_CARGO_HOST_TARGET ${Rust_CARGO_HOST_TARGET} CACHE INTERNAL "host triple used by corrosion") @@ -607,19 +578,11 @@ set(_CORROSION_RUST_CARGO_TARGET_UPPER # immediately, we are using a different property name depending on the CMake version. However users avoid using # any of the properties directly, as they are no longer part of the public API and are to be considered deprecated. # Instead use the corrosion_set_... functions as documented in the Readme. -if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.19.0) - set(_CORR_PROP_FEATURES CORROSION_FEATURES CACHE INTERNAL "") - set(_CORR_PROP_ALL_FEATURES CORROSION_ALL_FEATURES CACHE INTERNAL "") - set(_CORR_PROP_NO_DEFAULT_FEATURES CORROSION_NO_DEFAULT_FEATURES CACHE INTERNAL "") - set(_CORR_PROP_ENV_VARS CORROSION_ENVIRONMENT_VARIABLES CACHE INTERNAL "") - set(_CORR_PROP_HOST_BUILD CORROSION_USE_HOST_BUILD CACHE INTERNAL "") -else() - set(_CORR_PROP_FEATURES INTERFACE_CORROSION_FEATURES CACHE INTERNAL "") - set(_CORR_PROP_ALL_FEATURES INTERFACE_CORROSION_ALL_FEATURES CACHE INTERNAL "") - set(_CORR_PROP_NO_DEFAULT_FEATURES INTERFACE_NO_DEFAULT_FEATURES CACHE INTERNAL "") - set(_CORR_PROP_ENV_VARS INTERFACE_CORROSION_ENVIRONMENT_VARIABLES CACHE INTERNAL "") - set(_CORR_PROP_HOST_BUILD INTERFACE_CORROSION_USE_HOST_BUILD CACHE INTERNAL "") -endif() +set(_CORR_PROP_FEATURES CORROSION_FEATURES CACHE INTERNAL "") +set(_CORR_PROP_ALL_FEATURES CORROSION_ALL_FEATURES CACHE INTERNAL "") +set(_CORR_PROP_NO_DEFAULT_FEATURES CORROSION_NO_DEFAULT_FEATURES CACHE INTERNAL "") +set(_CORR_PROP_ENV_VARS CORROSION_ENVIRONMENT_VARIABLES CACHE INTERNAL "") +set(_CORR_PROP_HOST_BUILD CORROSION_USE_HOST_BUILD CACHE INTERNAL "") # Add custom command to build one target in a package (crate) # @@ -998,67 +961,17 @@ function(corrosion_import_crate) endif() set(imported_crates "") - if (CORROSION_NATIVE_TOOLING) - get_filename_component(manifest_directory "${COR_MANIFEST_PATH}" DIRECTORY) - get_filename_component(toml_dir_name ${manifest_directory} NAME) - - set( - generated_cmake - "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/corrosion/${toml_dir_name}.dir/cargo-build.cmake" - ) - - if (CMAKE_VS_PLATFORM_NAME) - set (_CORROSION_CONFIGURATION_ROOT --configuration-root ${CMAKE_VS_PLATFORM_NAME}) - endif() - set(crates_args) - foreach(crate ${COR_CRATES}) - list(APPEND crates_args --crates ${crate}) - endforeach() - if(DEFINED COR_CRATE_TYPES) - set(crate_types "--crate-type=${COR_CRATE_TYPES}") - endif() - - list(APPEND passthrough_to_acb_args ${no_linker_override}) - if(passthrough_to_acb_args) - # 31 == 0x1f - string(ASCII 31 unit_seperator) - list(JOIN passthrough_to_acb_args "${unit_seperator}" joined_args) - set(passthrough_to_acb "--passthrough-acb=${joined_args}") - endif() - - execute_process( - COMMAND - ${_CORROSION_GENERATOR} - --manifest-path ${COR_MANIFEST_PATH} - gen-cmake - ${_CORROSION_CONFIGURATION_ROOT} - ${crates_args} - ${crate_types} - ${cargo_profile_native_generator} - --imported-crates=imported_crates - ${passthrough_to_acb} - -o ${generated_cmake} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - RESULT_VARIABLE ret) - - if (NOT ret EQUAL "0") - message(FATAL_ERROR "corrosion-generator failed") - endif() - - include(${generated_cmake}) - else() - _generator_add_cargo_targets( - MANIFEST_PATH - "${COR_MANIFEST_PATH}" - IMPORTED_CRATES - imported_crates - ${crate_allowlist} - ${crate_types} - ${cargo_profile} - ${no_linker_override} - ) - endif() + _generator_add_cargo_targets( + MANIFEST_PATH + "${COR_MANIFEST_PATH}" + IMPORTED_CRATES + imported_crates + ${crate_allowlist} + ${crate_types} + ${cargo_profile} + ${no_linker_override} + ) # Not target props yet: # NO_STD @@ -1082,11 +995,6 @@ function(corrosion_import_crate) endif() endfunction() -function(corrosion_set_linker_language target_name language) - message(FATAL_ERROR "corrosion_set_linker_language was deprecated and removed." - "Please use corrosion_set_linker and set a specific linker.") -endfunction() - function(corrosion_set_linker target_name linker) if(NOT linker) message(FATAL_ERROR "The linker passed to `corrosion_set_linker` may not be empty") diff --git a/cmake/CorrosionConfig.cmake.in b/cmake/CorrosionConfig.cmake.in index abf099c3..7ec2e82b 100644 --- a/cmake/CorrosionConfig.cmake.in +++ b/cmake/CorrosionConfig.cmake.in @@ -6,13 +6,4 @@ endif() list(APPEND CMAKE_MODULE_PATH "@CMAKE_INSTALL_FULL_DATADIR@/cmake") -set(CORROSION_NATIVE_TOOLING_INSTALLED @CORROSION_NATIVE_TOOLING@) -if(CORROSION_NATIVE_TOOLING_INSTALLED AND NOT TARGET Corrosion::Generator) - add_executable(Corrosion::Generator IMPORTED GLOBAL) - - set_property( - TARGET Corrosion::Generator - PROPERTY IMPORTED_LOCATION "@CMAKE_INSTALL_FULL_LIBEXECDIR@/corrosion-generator") -endif() - include(Corrosion) diff --git a/doc/src/usage.md b/doc/src/usage.md index 19bf950d..b942441f 100644 --- a/doc/src/usage.md +++ b/doc/src/usage.md @@ -90,25 +90,15 @@ them **before** `find_package(Corrosion REQUIRED)`. - `Rust_CARGO_TARGET:STRING` - The default target triple to build for. Alter for cross-compiling. Default: On Visual Studio Generator, the matching triple for `CMAKE_VS_PLATFORM_NAME`. Otherwise, the default target triple reported by `${Rust_COMPILER} --version --verbose`. -- `CORROSION_NATIVE_TOOLING:BOOL` - Use a native tool (written in Rust) as part of Corrosion. This - option increases the configure-time significantly unless Corrosion is installed. - Default: `OFF` if CMake >= 3.19.0. Forced `ON` for CMake < 3.19. + #### Developer/Maintainer Options These options are not used in the course of normal Corrosion usage, but are used to configure how Corrosion is built and installed. Only applies to Corrosion builds and subdirectory uses. -- `CORROSION_DEV_MODE:BOOL` - Indicates that Corrosion is being actively developed. Default: `OFF` - if Corrosion is a subdirectory, `ON` if it is the top-level project - `CORROSION_BUILD_TESTS:BOOL` - Build the Corrosion tests. Default: `Off` if Corrosion is a subdirectory, `ON` if it is the top-level project -- `CORROSION_GENERATOR_EXECUTABLE:STRING` - Specify a path to the corrosion-generator executable. - This is to support scenarios where it's easier to build corrosion-generator outside of the normal - bootstrap path, such as in the case of package managers that make it very easy to import Rust - crates for fully reproducible, offline builds. -- `CORROSION_INSTALL_EXECUTABLE:BOOL` - Controls whether corrosion-generator is installed with the - package. Default: `ON` with `CORROSION_GENERATOR_EXECUTABLE` unset, otherwise `OFF` ### Information provided by Corrosion @@ -295,14 +285,14 @@ cmake -S. -Bbuild-android-arm64 -GNinja -DCMAKE_SYSTEM_NAME=Android \ **Important note:** The Android SDK ships with CMake 3.10 at newest, which Android Studio will prefer over any CMake you've installed locally. CMake 3.10 is insufficient for using Corrosion, -which requires a minimum of CMake 3.15. If you're using Android Studio to build your project, +which requires a minimum of CMake 3.22. If you're using Android Studio to build your project, follow the instructions in the Android Studio documentation for [using a specific version of CMake](https://developer.android.com/studio/projects/install-ndk#vanilla_cmake). ### CMake `OUTPUT_DIRECTORY` target properties and `IMPORTED_LOCATION` -Corrosion respects the following `OUTPUT_DIRECTORY` target properties on CMake >= 3.19: +Corrosion respects the following `OUTPUT_DIRECTORY` target properties: - [ARCHIVE_OUTPUT_DIRECTORY](https://cmake.org/cmake/help/latest/prop_tgt/ARCHIVE_OUTPUT_DIRECTORY.html) - [LIBRARY_OUTPUT_DIRECTORY](https://cmake.org/cmake/help/latest/prop_tgt/LIBRARY_OUTPUT_DIRECTORY.html) - [RUNTIME_OUTPUT_DIRECTORY](https://cmake.org/cmake/help/latest/prop_tgt/RUNTIME_OUTPUT_DIRECTORY.html) diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt deleted file mode 100644 index c3f9a329..00000000 --- a/generator/CMakeLists.txt +++ /dev/null @@ -1,64 +0,0 @@ -message(STATUS "Building CMake Generator for Corrosion - This may take a while") - -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( - COMMAND ${CMAKE_COMMAND} - -E env - # If the Generator is built at configure of a project (instead of being pre-installed) - # We don't want environment variables like `RUSTFLAGS` affecting the Generator build. - --unset=RUSTFLAGS - "CARGO_BUILD_RUSTC=${RUSTC_EXECUTABLE}" - "${CARGO_EXECUTABLE}" install - --path "." - --root "${generator_destination}" - --locked - ${_CORROSION_QUIET_OUTPUT_FLAG} - WORKING_DIRECTORY "${generator_src}" - RESULT_VARIABLE generator_build_failed -) -if(generator_build_failed) - message(FATAL_ERROR "Building CMake Generator for Corrosion - failed") -else() - message(STATUS "Building CMake Generator for Corrosion - done") -endif() -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}" -) - -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. - file(GLOB_RECURSE _RUST_FILES CONFIGURE_DEPENDS generator/src/*.rs) - file(GLOB _CARGO_FILES CONFIGURE_DEPENDS generator/Cargo.*) - set_property( - DIRECTORY APPEND - PROPERTY CMAKE_CONFIGURE_DEPENDS - ${_RUST_FILES} ${_CARGO_FILES}) -endif() - diff --git a/generator/Cargo.lock b/generator/Cargo.lock deleted file mode 100644 index 26457a0a..00000000 --- a/generator/Cargo.lock +++ /dev/null @@ -1,183 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "camino" -version = "1.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c59e92b5a388f549b863a7bea62612c09f24c8393560709a54558a9abdfb3b9c" -dependencies = [ - "serde", -] - -[[package]] -name = "cargo-platform" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cfa25e60aea747ec7e1124f238816749faa93759c6ff5b31f1ccdda137f4479" -dependencies = [ - "serde", -] - -[[package]] -name = "cargo_metadata" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7daec1a2a2129eeba1644b220b4647ec537b0b5d4bfd6876fcc5a540056b592" -dependencies = [ - "camino", - "cargo-platform", - "semver", - "serde", - "serde_json", - "thiserror", -] - -[[package]] -name = "clap" -version = "2.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" -dependencies = [ - "bitflags", - "textwrap", - "unicode-width", -] - -[[package]] -name = "corrosion-generator" -version = "0.1.0" -dependencies = [ - "cargo_metadata", - "clap", - "serde", -] - -[[package]] -name = "itoa" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" - -[[package]] -name = "proc-macro2" -version = "1.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "ryu" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" - -[[package]] -name = "semver" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0293b4b29daaf487284529cc2f5675b8e57c61f70167ba415a463651fd6a918" -dependencies = [ - "serde", -] - -[[package]] -name = "serde" -version = "1.0.188" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.188" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.105" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693151e1ac27563d6dbcec9dee9fbd5da8539b20fa14ad3752b2e6d363ace360" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "syn" -version = "2.0.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c324c494eba9d92503e6f1ef2e6df781e78f6a7705a0202d9801b198807d518a" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "thiserror" -version = "1.0.47" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97a802ec30afc17eee47b2855fc72e0c4cd62be9b4efe6591edde0ec5bd68d8f" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.47" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bb623b56e39ab7dcd4b1b98bb6c8f8d907ed255b18de254088016b27a8ee19b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "unicode-ident" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" - -[[package]] -name = "unicode-width" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" diff --git a/generator/Cargo.toml b/generator/Cargo.toml deleted file mode 100644 index e22689fa..00000000 --- a/generator/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "corrosion-generator" -version = "0.1.0" -authors = ["Andrew Gaspar "] -license = "MIT" -edition = "2018" - -[dependencies] -cargo_metadata = "0.17" -serde = { version = " 1.0.186", features = ["derive"] } - -[dependencies.clap] -version = "2.34" -default-features = false -# Make sure this crate still compiles while it is checked out -# in a sub-directory of a repository that has a Cargo.toml. -[workspace] diff --git a/generator/Compat.Cargo.lock b/generator/Compat.Cargo.lock deleted file mode 100644 index 02274a27..00000000 --- a/generator/Compat.Cargo.lock +++ /dev/null @@ -1,184 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "camino" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c530edf18f37068ac2d977409ed5cd50d53d73bc653c7647b48eb78976ac9ae2" -dependencies = [ - "serde", -] - -[[package]] -name = "cargo-platform" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" -dependencies = [ - "serde", -] - -[[package]] -name = "cargo_metadata" -version = "0.15.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08a1ec454bc3eead8719cb56e15dbbfecdbc14e4b3a3ae4936cc6e31f5fc0d07" -dependencies = [ - "camino", - "cargo-platform", - "semver", - "serde", - "serde_json", - "thiserror", -] - -[[package]] -name = "clap" -version = "2.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" -dependencies = [ - "bitflags", - "textwrap", - "unicode-width", -] - -[[package]] -name = "corrosion-generator" -version = "0.1.0" -dependencies = [ - "cargo_metadata", - "clap", - "serde", - "thiserror", -] - -[[package]] -name = "itoa" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" - -[[package]] -name = "proc-macro2" -version = "1.0.52" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "ryu" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" - -[[package]] -name = "semver" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" -dependencies = [ - "serde", -] - -[[package]] -name = "serde" -version = "1.0.156" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "314b5b092c0ade17c00142951e50ced110ec27cea304b1037c6969246c2469a4" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.156" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7e29c4601e36bcec74a223228dce795f4cd3616341a4af93520ca1a837c087d" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "thiserror" -version = "1.0.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "unicode-ident" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" - -[[package]] -name = "unicode-width" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" diff --git a/generator/Compat.Cargo.toml b/generator/Compat.Cargo.toml deleted file mode 100644 index 4097d969..00000000 --- a/generator/Compat.Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "corrosion-generator" -version = "0.1.0" -authors = ["Andrew Gaspar "] -license = "MIT" -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" -default-features = false -# Make sure this crate still compiles while it is checked out -# in a sub-directory of a repository that has a Cargo.toml. -[workspace] diff --git a/generator/src/main.rs b/generator/src/main.rs deleted file mode 100644 index df21133e..00000000 --- a/generator/src/main.rs +++ /dev/null @@ -1,95 +0,0 @@ -use std::path::PathBuf; - -use cargo_metadata::Metadata; -use clap::{App, Arg}; - -mod subcommands { - pub mod gen_cmake; -} - -use subcommands::*; - -// common options -const MANIFEST_PATH: &str = "manifest-path"; -const CARGO_EXECUTABLE: &str = "cargo-executable"; -const VERBOSE: &str = "verbose"; -const LOCKED: &str = "locked"; -const FROZEN: &str = "frozen"; - -pub struct GeneratorSharedArgs { - pub manifest_path: PathBuf, - pub cargo_executable: PathBuf, - pub metadata: Metadata, - pub verbose: bool, -} - -fn main() -> Result<(), Box> { - let matches = App::new("CMake Generator for Cargo") - .version("0.1") - .author("Andrew Gaspar ") - .about("Generates CMake files for Cargo projects") - .arg( - Arg::with_name(MANIFEST_PATH) - .long("manifest-path") - .value_name("Cargo.toml") - .help("Specifies the target Cargo project") - .required(true) - .takes_value(true), - ) - .arg( - Arg::with_name(CARGO_EXECUTABLE) - .long("cargo") - .value_name("EXECUTABLE") - .required(true) - .help("Path to the cargo executable to use"), - ) - .arg( - Arg::with_name(VERBOSE) - .long("verbose") - .help("Request verbose output"), - ) - .arg( - Arg::with_name(LOCKED) - .long("locked") - .help("Pass --locked to cargo invocations"), - ) - .arg( - Arg::with_name(FROZEN) - .long("frozen") - .help("Pass --frozen to cargo invocations"), - ) - .subcommand(gen_cmake::subcommand()) - .get_matches(); - - let mut cmd = cargo_metadata::MetadataCommand::new(); - cmd.no_deps(); - if matches.is_present(LOCKED) { - cmd.other_options(["--locked".into()]); - } - if matches.is_present(FROZEN) { - cmd.other_options(["--frozen".into()]); - } - - let manifest_path = matches.value_of(MANIFEST_PATH).unwrap(); - let cargo_executable = matches.value_of(CARGO_EXECUTABLE).unwrap(); - - cmd.manifest_path(manifest_path); - cmd.cargo_path(cargo_executable); - - let metadata = cmd.exec()?; - - let shared_args = GeneratorSharedArgs { - manifest_path: manifest_path.into(), - cargo_executable: cargo_executable.into(), - metadata, - verbose: matches.is_present(VERBOSE), - }; - - match matches.subcommand() { - (gen_cmake::GEN_CMAKE, Some(matches)) => gen_cmake::invoke(&shared_args, matches)?, - _ => unreachable!(), - }; - - // We should never reach this statement - std::process::exit(1); -} diff --git a/generator/src/subcommands/gen_cmake.rs b/generator/src/subcommands/gen_cmake.rs deleted file mode 100644 index 416d522b..00000000 --- a/generator/src/subcommands/gen_cmake.rs +++ /dev/null @@ -1,160 +0,0 @@ -use std::{ - fs::{create_dir_all, File}, - io::{stdout, Write}, - path::Path, - rc::Rc, -}; - -use clap::{App, Arg, ArgMatches, SubCommand}; - -mod target; - -// Command name -pub const GEN_CMAKE: &str = "gen-cmake"; - -// Options -const OUT_FILE: &str = "out-file"; -const CONFIGURATION_ROOT: &str = "configuration-root"; -const CRATES: &str = "crates"; -const IMPORTED_CRATES: &str = "imported-crates"; -const CRATE_TYPE: &str = "crate-type"; -const PASSTHROUGH_ADD_CARGO_BUILD: &str = "passthrough-acb"; - -pub fn subcommand() -> App<'static, 'static> { - SubCommand::with_name(GEN_CMAKE) - .arg( - Arg::with_name(CONFIGURATION_ROOT) - .long("configuration-root") - .value_name("DIRECTORY") - .takes_value(true) - .help( - "Specifies a root directory for configuration folders. E.g. Win32 \ - in VS Generator.", - ), - ) - .arg( - Arg::with_name(CRATES) - .long("crates") - .value_name("crates") - .takes_value(true) - .multiple(true) - .require_delimiter(true) - .help("Specifies which crates of the workspace to import"), - ) - .arg( - Arg::with_name(CRATE_TYPE) - .long(CRATE_TYPE) - .value_name("kind") - .possible_values(&["staticlib", "cdylib", "bin"]) - .multiple(true) - .value_delimiter(";") - .help("Only import the specified crate types") - ) - .arg( - Arg::with_name(OUT_FILE) - .short("o") - .long("out-file") - .value_name("FILE") - .help("Output CMake file name. Defaults to stdout."), - ) - .arg( - Arg::with_name(IMPORTED_CRATES) - .long(IMPORTED_CRATES) - .value_name("variable_name") - .takes_value(true) - .help("Save a list of the imported target names into c CMake variable with the given name"), - ) - .arg( - Arg::with_name(PASSTHROUGH_ADD_CARGO_BUILD) - .long(PASSTHROUGH_ADD_CARGO_BUILD) - .takes_value(true) - .multiple(true) - .value_delimiter(std::char::from_u32(0x1f).unwrap().to_string().as_str()) - .help("Passthrough arguments to the _add_cargo_build invocation(s) in CMake") - ) -} - -pub fn invoke( - args: &crate::GeneratorSharedArgs, - matches: &ArgMatches, -) -> Result<(), Box> { - let mut out_file: Box = if let Some(path) = matches.value_of(OUT_FILE) { - let path = Path::new(path); - if let Some(parent) = path.parent() { - create_dir_all(parent).expect("Failed to create directory!"); - } - let file = File::create(path).expect("Unable to open out-file!"); - Box::new(file) - } else { - Box::new(stdout()) - }; - - writeln!( - out_file, - "\ -cmake_minimum_required(VERSION 3.15) -" - )?; - - let crates = matches - .values_of(CRATES) - .map_or(Vec::new(), |c| c.collect()); - let crate_kinds: Option> = matches.values_of(CRATE_TYPE).map(|c| c.collect()); - let workspace_manifest_path = Rc::new(args.manifest_path.clone()); - let targets: Vec<_> = args - .metadata - .packages - .iter() - .filter(|p| { - args.metadata.workspace_members.contains(&p.id) - && (crates.is_empty() || crates.contains(&p.name.as_str())) - }) - .cloned() - .map(Rc::new) - .flat_map(|package| { - package - .targets - .iter() - .filter_map(|t| { - target::CargoTarget::from_metadata( - package.clone(), - t.clone(), - workspace_manifest_path.clone(), - &crate_kinds, - ) - }) - .collect::>() - }) - .collect(); - - let passthrough_args: Vec = matches - .values_of(PASSTHROUGH_ADD_CARGO_BUILD) - .map(|values| { - // Add quotes around each argument for CMake to preserve which arguments belong together. - values - .filter(|val| !val.is_empty()) - .map(|val| format!("\"{}\"", val)) - .collect() - }) - .unwrap_or_default(); - let passthrough_str = passthrough_args.join(" "); - - for target in &targets { - target - .emit_cmake_target(&mut out_file, &passthrough_str) - .unwrap(); - } - if let Some(imported_crate_list_name) = matches.value_of(IMPORTED_CRATES) { - let imported_targets: Vec<_> = targets.iter().map(|target| target.target_name()).collect(); - let imported_targets_list = imported_targets.join(";"); - writeln!( - out_file, - "set({} \"{}\")", - imported_crate_list_name, imported_targets_list - )?; - } - - writeln!(out_file)?; - - std::process::exit(0); -} diff --git a/generator/src/subcommands/gen_cmake/target.rs b/generator/src/subcommands/gen_cmake/target.rs deleted file mode 100644 index 0d0af9db..00000000 --- a/generator/src/subcommands/gen_cmake/target.rs +++ /dev/null @@ -1,216 +0,0 @@ -use std::error::Error; -use std::path::PathBuf; -use std::rc::Rc; - -#[derive(Clone)] -pub enum CargoTargetType { - Executable, - Library { - has_staticlib: bool, - has_cdylib: bool, - }, -} - -#[derive(Clone)] -pub struct CargoTarget { - cargo_package: Rc, - cargo_target: cargo_metadata::Target, - target_type: CargoTargetType, - workspace_manifest_path: Rc, -} - -impl CargoTargetType { - fn to_string(&self) -> String { - let mut s = String::new(); - match self { - Self::Executable => { - s.push_str("bin"); - } - Self::Library { - has_staticlib, - has_cdylib, - } => { - if *has_staticlib { - s.push_str("staticlib") - } - if *has_cdylib { - s.push_str(" cdylib") - } - } - } - s - } -} - -impl CargoTarget { - pub fn from_metadata( - cargo_package: Rc, - cargo_target: cargo_metadata::Target, - workspace_manifest_path: Rc, - // If Some, only import crates if the kind variant is given in crate_kinds. - crate_kinds: &Option>, - ) -> Option { - let filtered_kinds: Vec = cargo_target - .kind - .clone() - .into_iter() - .filter(|kind| match crate_kinds { - None => true, - Some(allowed_kinds_subset) => allowed_kinds_subset.contains(&&**kind), - }) - .collect(); - - let target_type = if filtered_kinds - .iter() - .any(|k| k.as_str() == "staticlib" || k.as_str() == "cdylib") - { - CargoTargetType::Library { - has_staticlib: filtered_kinds.iter().any(|k| k == "staticlib"), - has_cdylib: filtered_kinds.iter().any(|k| k == "cdylib"), - } - } else if filtered_kinds.iter().any(|k| k == "bin") { - CargoTargetType::Executable - } else { - return None; - }; - - Some(Self { - cargo_package, - cargo_target, - target_type, - workspace_manifest_path, - }) - } - - pub(crate) fn target_name(&self) -> &str { - &self.cargo_target.name - } - - pub fn emit_cmake_target( - &self, - out_file: &mut dyn std::io::Write, - passthrough_add_cargo_build: &str, - ) -> Result<(), Box> { - writeln!( - out_file, - "set(byproducts \"\") - set(cargo_build_out_dir \"\") - set(archive_byproducts \"\") - set(shared_lib_byproduct \"\") - set(pdb_byproduct \"\") - set(bin_byproduct \"\") - " - )?; - let ws_manifest = self - .workspace_manifest_path - .to_str() - .expect("Non-utf8 path encountered") - .replace("\\", "/"); - - match self.target_type { - CargoTargetType::Library { - has_staticlib, - has_cdylib, - } => { - assert!(has_staticlib || has_cdylib); - let ws_manifest = self - .workspace_manifest_path - .to_str() - .expect("Non-utf8 path encountered") - .replace("\\", "/"); - let mut lib_kinds = if has_staticlib { "staticlib" } else { "" }.to_string(); - if has_cdylib { - if has_staticlib { - lib_kinds.push(' '); - } - lib_kinds.push_str("cdylib") - } - - writeln!( - out_file, - " - _corrosion_add_library_target( - WORKSPACE_MANIFEST_PATH \"{workspace_manifest_path}\" - TARGET_NAME \"{target_name}\" - LIB_KINDS {lib_kinds} - OUT_ARCHIVE_OUTPUT_BYPRODUCTS archive_byproducts - OUT_SHARED_LIB_BYPRODUCTS shared_lib_byproduct - OUT_PDB_BYPRODUCT pdb_byproduct - ) - list(APPEND byproducts - \"${{archive_byproducts}}\" - \"${{shared_lib_byproduct}}\" - \"${{pdb_byproduct}}\" - ) - ", - workspace_manifest_path = ws_manifest, - target_name = self.cargo_target.name, - lib_kinds = lib_kinds, - )?; - } - CargoTargetType::Executable => { - writeln!( - out_file, - " - _corrosion_add_bin_target(\"{workspace_manifest_path}\" \"{target_name}\" - bin_byproduct pdb_byproduct - ) - set(byproducts \"\") - list(APPEND byproducts \"${{bin_byproduct}}\" \"${{pdb_byproduct}}\") - ", - workspace_manifest_path = ws_manifest, - target_name = self.cargo_target.name, - )?; - } - }; - let target_kinds = self.target_type.to_string(); - writeln!(out_file, - " - set(cargo_build_out_dir \"\") - _add_cargo_build( - cargo_build_out_dir - PACKAGE \"{package_name}\" - TARGET \"{target_name}\" - MANIFEST_PATH \"{package_manifest_path}\" - WORKSPACE_MANIFEST_PATH \"{workspace_manifest_path}\" - TARGET_KINDS {target_kinds} - BYPRODUCTS \"${{byproducts}}\" - {passthrough_add_cargo_build} - ) - - set_target_properties({target_name} PROPERTIES - INTERFACE_COR_PACKAGE_MANIFEST_PATH \"{package_manifest_path}\" - ) - - if(archive_byproducts) - _corrosion_copy_byproducts( - {target_name} ARCHIVE_OUTPUT_DIRECTORY \"${{cargo_build_out_dir}}\" \"${{archive_byproducts}}\" - ) - endif() - if(shared_lib_byproduct) - _corrosion_copy_byproducts( - {target_name} LIBRARY_OUTPUT_DIRECTORY \"${{cargo_build_out_dir}}\" \"${{shared_lib_byproduct}}\" - ) - endif() - if(pdb_byproduct) - _corrosion_copy_byproducts( - {target_name} PDB_OUTPUT_DIRECTORY \"${{cargo_build_out_dir}}\" \"${{pdb_byproduct}}\" - ) - endif() - if(bin_byproduct) - _corrosion_copy_byproducts( - {target_name} RUNTIME_OUTPUT_DIRECTORY \"${{cargo_build_out_dir}}\" \"${{bin_byproduct}}\" - ) - endif() - ", - package_name = self.cargo_package.name, - target_name = self.cargo_target.name, - package_manifest_path = self.cargo_package.manifest_path.as_str().replace("\\", "/"), - workspace_manifest_path = ws_manifest, - target_kinds = target_kinds, - passthrough_add_cargo_build = passthrough_add_cargo_build, - - )?; - Ok(()) - } -} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fd036e70..cd782c73 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -97,10 +97,6 @@ function(corrosion_tests_add_test test_name bin_names) if(CMAKE_GENERATOR_PLATFORM) set(TEST_GENERATOR_PLATFORM "GENERATOR_PLATFORM" "${CMAKE_GENERATOR_PLATFORM}") endif() - if(CORROSION_GENERATOR_EXECUTABLE) - # Mainly used in CI to build the native generator once and then reuse it for all tests - set(TEST_GENERATOR_BIN EXTERNAL_CORROSION_GENERATOR "${CORROSION_GENERATOR_EXECUTABLE}") - endif() if(CMAKE_CROSSCOMPILING) set(TEST_SYSTEM_NAME SYSTEM_NAME "${CMAKE_SYSTEM_NAME}") endif() @@ -118,7 +114,6 @@ function(corrosion_tests_add_test test_name bin_names) "${TEST_C_COMPILER}" "${TEST_CXX_COMPILER}" "${TEST_GENERATOR_PLATFORM}" - "${TEST_GENERATOR_BIN}" ${pass_through_arguments} COMMAND_EXPAND_LISTS @@ -169,7 +164,6 @@ add_subdirectory(custom_profiles) add_subdirectory(cbindgen) add_subdirectory(cxxbridge) add_subdirectory(envvar) -add_subdirectory(external_corrosion_generator) add_subdirectory(features) add_subdirectory(find_rust) add_subdirectory(gensource) diff --git a/test/ConfigureAndBuild.cmake b/test/ConfigureAndBuild.cmake index 513e506e..fbf40cb1 100644 --- a/test/ConfigureAndBuild.cmake +++ b/test/ConfigureAndBuild.cmake @@ -18,7 +18,6 @@ set(oneValueArgs C_COMPILER CXX_COMPILER SYSTEM_NAME - EXTERNAL_CORROSION_GENERATOR CARGO_PROFILE ) set(multiValueArgs "PASS_THROUGH_ARGS") @@ -43,11 +42,6 @@ endif() if(TEST_SYSTEM_NAME) set(TEST_SYSTEM_NAME "-DCMAKE_SYSTEM_NAME=${TEST_SYSTEM_NAME}") endif() -if(TEST_EXTERNAL_CORROSION_GENERATOR) - set(TEST_EXTERNAL_CORROSION_GENERATOR - "-DCORROSION_GENERATOR_EXECUTABLE=${TEST_EXTERNAL_CORROSION_GENERATOR}" - ) -endif() if(TEST_CARGO_PROFILE) set(TEST_CARGO_PROFILE "-DCARGO_PROFILE=${TEST_CARGO_PROFILE}") endif() @@ -71,7 +65,6 @@ execute_process( ${TEST_C_COMPILER} ${TEST_CXX_COMPILER} ${TEST_SYSTEM_NAME} - ${TEST_EXTERNAL_CORROSION_GENERATOR} ${TEST_CARGO_PROFILE} ${TEST_PASS_THROUGH_ARGS} -S "${TEST_SOURCE_DIR}" diff --git a/test/external_corrosion_generator/CMakeLists.txt b/test/external_corrosion_generator/CMakeLists.txt deleted file mode 100644 index 954f21f8..00000000 --- a/test/external_corrosion_generator/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -if(CORROSION_TESTS_INSTALL_CORROSION) - add_test(NAME "ExternalCorrosionGenerator" - COMMAND - ${CMAKE_COMMAND} - -P "${CMAKE_SOURCE_DIR}/test/ConfigureAndBuild.cmake" - SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/ExternalCorrosionGenerator" - BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/build" - GENERATOR "${CMAKE_GENERATOR}" - RUST_TOOLCHAIN "${Rust_TOOLCHAIN}" - EXTERNAL_CORROSION_GENERATOR "${test_install_path}/libexec/corrosion-generator" - COMMAND_EXPAND_LISTS - ) - set_tests_properties("ExternalCorrosionGenerator" PROPERTIES FIXTURES_REQUIRED "fixture_corrosion_install") -endif() \ No newline at end of file diff --git a/test/external_corrosion_generator/ExternalCorrosionGenerator/CMakeLists.txt b/test/external_corrosion_generator/ExternalCorrosionGenerator/CMakeLists.txt deleted file mode 100644 index 69f9b283..00000000 --- a/test/external_corrosion_generator/ExternalCorrosionGenerator/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(ExternalCorrosionGenerator LANGUAGES C) - -add_subdirectory(../../.. corrosion) - -get_property( - GENERATOR_EXE_LOCATION - TARGET Corrosion::Generator PROPERTY IMPORTED_LOCATION -) - -if (NOT GENERATOR_EXE_LOCATION STREQUAL CORROSION_GENERATOR_EXECUTABLE) - message( - FATAL_ERROR - "\ -Corrosion Generator not Imported Correctly: - Corrosion::Generator IMPORTED_LOCATION: ${GENERATOR_EXE_LOCATION} - CORROSION_GENERATOR_EXECUTABLE: ${CORROSION_GENERATOR_EXECUTABLE}") -endif() diff --git a/test/external_corrosion_generator/ExternalCorrosionGenerator/Test.cmake b/test/external_corrosion_generator/ExternalCorrosionGenerator/Test.cmake deleted file mode 100644 index e92b812e..00000000 --- a/test/external_corrosion_generator/ExternalCorrosionGenerator/Test.cmake +++ /dev/null @@ -1,14 +0,0 @@ -set(CORROSION_DIR ${CMAKE_ARGV3}) -set(CORROSION_INSTALL ${CMAKE_ARGV4}) - -execute_process( - COMMAND - ${CMAKE_COMMAND} . - -DCORROSION_GENERATOR_EXECUTABLE=${CORROSION_INSTALL}/libexec/corrosion-generator - COMMAND_ECHO STDOUT - RESULT_VARIABLE SUCCESS -) - -if (NOT SUCCESS EQUAL 0) - message(FATAL_ERROR) -endif() diff --git a/test/output directory/CMakeLists.txt b/test/output directory/CMakeLists.txt index 3cd92e47..357a4dd9 100644 --- a/test/output directory/CMakeLists.txt +++ b/test/output directory/CMakeLists.txt @@ -1,7 +1,3 @@ -if(CMAKE_VERSION VERSION_LESS 3.19.0) - return() -endif() - if(CMAKE_C_COMPILER) set(TEST_C_COMPILER "C_COMPILER" "${CMAKE_C_COMPILER}") endif()