From 6d78ccd2641a2a2c5c73875daff567796a77d250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?book=E8=AF=97=E6=84=8F?= Date: Wed, 16 Aug 2023 16:16:29 +0000 Subject: [PATCH 01/10] Delete connectors folder, add cargokit submodule --- .gitmodules | 3 + cargokit | 1 + connectors/README.md | 11 - connectors/cargokit/.gitignore | 1 - connectors/cargokit/LICENSE | 39 - connectors/cargokit/README | 2 - connectors/cargokit/build_pod.sh | 26 - connectors/cargokit/build_tool/Cargo.toml | 17 - .../cargokit/build_tool/src/build_android.rs | 316 ---- .../cargokit/build_tool/src/build_cmake.rs | 94 -- .../cargokit/build_tool/src/build_pod.rs | 158 -- .../cargokit/build_tool/src/build_tool.rs | 66 - connectors/cargokit/build_tool/src/logger.rs | 23 - connectors/cargokit/build_tool/src/utils.rs | 50 - connectors/cargokit/cmake/cargokit.cmake | 89 - connectors/cargokit/gradle/plugin.gradle | 164 -- connectors/cargokit/run_rust_tool.cmd | 25 - connectors/cargokit/run_rust_tool.sh | 25 - .../corrosion/.github/workflows/test.yaml | 321 ---- connectors/corrosion/.gitignore | 9 - connectors/corrosion/CMakeLists.txt | 141 -- connectors/corrosion/LICENSE | 21 - connectors/corrosion/README.md | 432 ----- connectors/corrosion/RELEASES.md | 248 --- connectors/corrosion/cmake/Corrosion.cmake | 1457 ----------------- .../corrosion/cmake/CorrosionConfig.cmake.in | 18 - .../corrosion/cmake/CorrosionGenerator.cmake | 243 --- connectors/corrosion/cmake/FindRust.cmake | 518 ------ connectors/corrosion/generator/Cargo.toml | 23 - connectors/corrosion/generator/src/main.rs | 80 - .../generator/src/subcommands/gen_cmake.rs | 114 -- .../src/subcommands/gen_cmake/target.rs | 194 --- .../generator/src/subcommands/print_root.rs | 14 - connectors/corrosion/test/CMakeLists.txt | 124 -- .../corrosion/test/ConfigureAndBuild.cmake | 107 -- connectors/corrosion/test/README.md | 7 - .../corrosion/test/cargo_flags/CMakeLists.txt | 3 - .../cargo_flags/cargo_flags/CMakeLists.txt | 16 - .../test/cargo_flags/cargo_flags/main.cpp | 6 - .../cargo_flags/cargo_flags/rust/Cargo.toml | 13 - .../cargo_flags/cargo_flags/rust/src/lib.rs | 14 - .../corrosion/test/cpp2rust/CMakeLists.txt | 5 - .../test/cpp2rust/cpp2rust/CMakeLists.txt | 32 - .../corrosion/test/cpp2rust/cpp2rust/lib.cpp | 5 - .../corrosion/test/cpp2rust/cpp2rust/lib2.cpp | 11 - .../cpp2rust/path with space/lib3.cpp | 8 - .../test/cpp2rust/cpp2rust/rust/Cargo.toml | 9 - .../cpp2rust/rust/rust_dependency/Cargo.toml | 8 - .../cpp2rust/rust/rust_dependency/src/lib.rs | 8 - .../cpp2rust/rust/src/bin/rust-exe.rs | 27 - .../corrosion/test/crate_type/CMakeLists.txt | 6 - .../test/crate_type/crate_type/CMakeLists.txt | 11 - .../test/crate_type/crate_type/main.cpp | 8 - .../crate_type/crate_type/proj1/Cargo.toml | 10 - .../crate_type/crate_type/proj1/src/lib.rs | 4 - .../crate_type/crate_type/proj2/Cargo.toml | 9 - .../crate_type/crate_type/proj2/src/lib.rs | 4 - .../test/custom_profiles/CMakeLists.txt | 10 - .../custom_profiles/CMakeLists.txt | 11 - .../custom_profiles/custom_profiles/main.cpp | 6 - .../custom_profiles/rust/Cargo.toml | 24 - .../custom_profiles/rust/src/lib.rs | 11 - .../corrosion/test/envvar/CMakeLists.txt | 5 - .../test/envvar/envvar/CMakeLists.txt | 23 - .../corrosion/test/envvar/envvar/Cargo.toml | 9 - .../corrosion/test/envvar/envvar/build.rs | 18 - .../corrosion/test/envvar/envvar/main.cpp | 5 - .../corrosion/test/envvar/envvar/src/lib.rs | 7 - .../CMakeLists.txt | 14 - .../ExternalCorrosionGenerator/CMakeLists.txt | 18 - .../ExternalCorrosionGenerator/Test.cmake | 14 - .../corrosion/test/features/CMakeLists.txt | 5 - .../test/features/features/CMakeLists.txt | 27 - .../corrosion/test/features/features/main.cpp | 13 - .../test/features/features/rust/Cargo.toml | 18 - .../test/features/features/rust/src/lib.rs | 26 - .../corrosion/test/find_rust/CMakeLists.txt | 2 - .../test/find_rust/find_rust/CMakeLists.txt | 9 - .../corrosion/test/gensource/CMakeLists.txt | 5 - .../test/gensource/gensource/.gitignore | 1 - .../test/gensource/gensource/CMakeLists.txt | 17 - .../test/gensource/gensource/Cargo.toml | 10 - .../gensource/generator/CMakeLists.txt | 2 - .../gensource/gensource/generator/Cargo.toml | 8 - .../gensource/gensource/generator/src/main.rs | 6 - .../test/gensource/gensource/src/lib.rs | 10 - .../corrosion/test/hostbuild/CMakeLists.txt | 11 - .../test/hostbuild/hostbuild/CMakeLists.txt | 7 - .../test/hostbuild/hostbuild/Cargo.toml | 8 - .../test/hostbuild/hostbuild/build.rs | 10 - .../test/hostbuild/hostbuild/src/lib.c | 5 - .../test/hostbuild/hostbuild/src/main.rs | 13 - .../corrosion/test/multitarget/CMakeLists.txt | 13 - .../multitarget/multitarget/CMakeLists.txt | 12 - .../test/multitarget/multitarget/Cargo.toml | 19 - .../test/multitarget/multitarget/lib.cpp | 5 - .../multitarget/multitarget/src/bin/bin1.rs | 8 - .../multitarget/multitarget/src/bin/bin2.rs | 8 - .../multitarget/multitarget/src/bin/bin3.rs | 8 - .../test/multitarget/multitarget/src/lib.rs | 9 - .../corrosion/test/nostd/CMakeLists.txt | 1 - .../corrosion/test/nostd/nostd/CMakeLists.txt | 11 - .../corrosion/test/nostd/nostd/main.cpp | 6 - .../test/nostd/nostd/rust/Cargo.toml | 17 - .../test/nostd/nostd/rust/src/lib.rs | 10 - .../test/output directory/CMakeLists.txt | 137 -- .../output directory/TestFileExists.cmake | 13 - .../output directory/CMakeLists.txt | 44 - .../output directory/consumer.cpp | 16 - .../output directory/proj1/Cargo.toml | 11 - .../proj1/src/bin/rust_bin1.rs | 3 - .../output directory/proj1/src/lib.rs | 4 - .../output directory/proj2/Cargo.toml | 11 - .../proj2/src/bin/rust_bin2.rs | 3 - .../output directory/proj2/src/lib.rs | 4 - .../test/parse_target_triple/CMakeLists.txt | 5 - .../parse_target_triple/CMakeLists.txt | 105 -- .../parse_target_triple/Cargo.toml | 1 - .../CMakeLists.txt | 10 - .../Cargo.toml | 1 - .../corrosion/test/rust2cpp/CMakeLists.txt | 9 - .../test/rust2cpp/rust2cpp/CMakeLists.txt | 12 - .../corrosion/test/rust2cpp/rust2cpp/main.cpp | 9 - .../test/rust2cpp/rust2cpp/rust/Cargo.toml | 11 - .../test/rust2cpp/rust2cpp/rust/src/lib.rs | 7 - .../corrosion/test/rustflags/CMakeLists.txt | 7 - .../cargo_config_rustflags/CMakeLists.txt | 11 - .../cargo_config_rustflags/Cargo.toml | 4 - .../cargo_config_rustflags/src/main.rs | 16 - .../test/rustflags/rustflags/CMakeLists.txt | 20 - .../test/rustflags/rustflags/main.cpp | 13 - .../test/rustflags/rustflags/rust/Cargo.toml | 11 - .../rustflags/rust/some_dependency/Cargo.toml | 6 - .../rustflags/rust/some_dependency/src/lib.rs | 10 - .../test/rustflags/rustflags/rust/src/lib.rs | 40 - .../corrosion/test/workspace/CMakeLists.txt | 6 - .../test/workspace/workspace/CMakeLists.txt | 9 - .../test/workspace/workspace/Cargo.toml | 2 - .../test/workspace/workspace/main.cpp | 4 - .../workspace/workspace/member1/Cargo.toml | 8 - .../workspace/workspace/member1/src/lib.rs | 7 - .../workspace/workspace/member2/Cargo.toml | 8 - .../workspace/workspace/member2/src/lib.rs | 7 - .../workspace/workspace/member3/Cargo.toml | 14 - .../workspace/workspace/member3/src/main.rs | 3 - 145 files changed, 4 insertions(+), 6531 deletions(-) create mode 100644 .gitmodules create mode 160000 cargokit delete mode 100644 connectors/README.md delete mode 100644 connectors/cargokit/.gitignore delete mode 100644 connectors/cargokit/LICENSE delete mode 100644 connectors/cargokit/README delete mode 100755 connectors/cargokit/build_pod.sh delete mode 100644 connectors/cargokit/build_tool/Cargo.toml delete mode 100644 connectors/cargokit/build_tool/src/build_android.rs delete mode 100644 connectors/cargokit/build_tool/src/build_cmake.rs delete mode 100644 connectors/cargokit/build_tool/src/build_pod.rs delete mode 100644 connectors/cargokit/build_tool/src/build_tool.rs delete mode 100644 connectors/cargokit/build_tool/src/logger.rs delete mode 100644 connectors/cargokit/build_tool/src/utils.rs delete mode 100644 connectors/cargokit/cmake/cargokit.cmake delete mode 100644 connectors/cargokit/gradle/plugin.gradle delete mode 100644 connectors/cargokit/run_rust_tool.cmd delete mode 100755 connectors/cargokit/run_rust_tool.sh delete mode 100644 connectors/corrosion/.github/workflows/test.yaml delete mode 100644 connectors/corrosion/.gitignore delete mode 100644 connectors/corrosion/CMakeLists.txt delete mode 100644 connectors/corrosion/LICENSE delete mode 100644 connectors/corrosion/README.md delete mode 100644 connectors/corrosion/RELEASES.md delete mode 100644 connectors/corrosion/cmake/Corrosion.cmake delete mode 100644 connectors/corrosion/cmake/CorrosionConfig.cmake.in delete mode 100644 connectors/corrosion/cmake/CorrosionGenerator.cmake delete mode 100644 connectors/corrosion/cmake/FindRust.cmake delete mode 100644 connectors/corrosion/generator/Cargo.toml delete mode 100644 connectors/corrosion/generator/src/main.rs delete mode 100644 connectors/corrosion/generator/src/subcommands/gen_cmake.rs delete mode 100644 connectors/corrosion/generator/src/subcommands/gen_cmake/target.rs delete mode 100644 connectors/corrosion/generator/src/subcommands/print_root.rs delete mode 100644 connectors/corrosion/test/CMakeLists.txt delete mode 100644 connectors/corrosion/test/ConfigureAndBuild.cmake delete mode 100644 connectors/corrosion/test/README.md delete mode 100644 connectors/corrosion/test/cargo_flags/CMakeLists.txt delete mode 100644 connectors/corrosion/test/cargo_flags/cargo_flags/CMakeLists.txt delete mode 100644 connectors/corrosion/test/cargo_flags/cargo_flags/main.cpp delete mode 100644 connectors/corrosion/test/cargo_flags/cargo_flags/rust/Cargo.toml delete mode 100644 connectors/corrosion/test/cargo_flags/cargo_flags/rust/src/lib.rs delete mode 100644 connectors/corrosion/test/cpp2rust/CMakeLists.txt delete mode 100644 connectors/corrosion/test/cpp2rust/cpp2rust/CMakeLists.txt delete mode 100644 connectors/corrosion/test/cpp2rust/cpp2rust/lib.cpp delete mode 100644 connectors/corrosion/test/cpp2rust/cpp2rust/lib2.cpp delete mode 100644 connectors/corrosion/test/cpp2rust/cpp2rust/path with space/lib3.cpp delete mode 100644 connectors/corrosion/test/cpp2rust/cpp2rust/rust/Cargo.toml delete mode 100644 connectors/corrosion/test/cpp2rust/cpp2rust/rust/rust_dependency/Cargo.toml delete mode 100644 connectors/corrosion/test/cpp2rust/cpp2rust/rust/rust_dependency/src/lib.rs delete mode 100644 connectors/corrosion/test/cpp2rust/cpp2rust/rust/src/bin/rust-exe.rs delete mode 100644 connectors/corrosion/test/crate_type/CMakeLists.txt delete mode 100644 connectors/corrosion/test/crate_type/crate_type/CMakeLists.txt delete mode 100644 connectors/corrosion/test/crate_type/crate_type/main.cpp delete mode 100644 connectors/corrosion/test/crate_type/crate_type/proj1/Cargo.toml delete mode 100644 connectors/corrosion/test/crate_type/crate_type/proj1/src/lib.rs delete mode 100644 connectors/corrosion/test/crate_type/crate_type/proj2/Cargo.toml delete mode 100644 connectors/corrosion/test/crate_type/crate_type/proj2/src/lib.rs delete mode 100644 connectors/corrosion/test/custom_profiles/CMakeLists.txt delete mode 100644 connectors/corrosion/test/custom_profiles/custom_profiles/CMakeLists.txt delete mode 100644 connectors/corrosion/test/custom_profiles/custom_profiles/main.cpp delete mode 100644 connectors/corrosion/test/custom_profiles/custom_profiles/rust/Cargo.toml delete mode 100644 connectors/corrosion/test/custom_profiles/custom_profiles/rust/src/lib.rs delete mode 100644 connectors/corrosion/test/envvar/CMakeLists.txt delete mode 100644 connectors/corrosion/test/envvar/envvar/CMakeLists.txt delete mode 100644 connectors/corrosion/test/envvar/envvar/Cargo.toml delete mode 100644 connectors/corrosion/test/envvar/envvar/build.rs delete mode 100644 connectors/corrosion/test/envvar/envvar/main.cpp delete mode 100644 connectors/corrosion/test/envvar/envvar/src/lib.rs delete mode 100644 connectors/corrosion/test/external_corrosion_generator/CMakeLists.txt delete mode 100644 connectors/corrosion/test/external_corrosion_generator/ExternalCorrosionGenerator/CMakeLists.txt delete mode 100644 connectors/corrosion/test/external_corrosion_generator/ExternalCorrosionGenerator/Test.cmake delete mode 100644 connectors/corrosion/test/features/CMakeLists.txt delete mode 100644 connectors/corrosion/test/features/features/CMakeLists.txt delete mode 100644 connectors/corrosion/test/features/features/main.cpp delete mode 100644 connectors/corrosion/test/features/features/rust/Cargo.toml delete mode 100644 connectors/corrosion/test/features/features/rust/src/lib.rs delete mode 100644 connectors/corrosion/test/find_rust/CMakeLists.txt delete mode 100644 connectors/corrosion/test/find_rust/find_rust/CMakeLists.txt delete mode 100644 connectors/corrosion/test/gensource/CMakeLists.txt delete mode 100644 connectors/corrosion/test/gensource/gensource/.gitignore delete mode 100644 connectors/corrosion/test/gensource/gensource/CMakeLists.txt delete mode 100644 connectors/corrosion/test/gensource/gensource/Cargo.toml delete mode 100644 connectors/corrosion/test/gensource/gensource/generator/CMakeLists.txt delete mode 100644 connectors/corrosion/test/gensource/gensource/generator/Cargo.toml delete mode 100644 connectors/corrosion/test/gensource/gensource/generator/src/main.rs delete mode 100644 connectors/corrosion/test/gensource/gensource/src/lib.rs delete mode 100644 connectors/corrosion/test/hostbuild/CMakeLists.txt delete mode 100644 connectors/corrosion/test/hostbuild/hostbuild/CMakeLists.txt delete mode 100644 connectors/corrosion/test/hostbuild/hostbuild/Cargo.toml delete mode 100644 connectors/corrosion/test/hostbuild/hostbuild/build.rs delete mode 100644 connectors/corrosion/test/hostbuild/hostbuild/src/lib.c delete mode 100644 connectors/corrosion/test/hostbuild/hostbuild/src/main.rs delete mode 100644 connectors/corrosion/test/multitarget/CMakeLists.txt delete mode 100644 connectors/corrosion/test/multitarget/multitarget/CMakeLists.txt delete mode 100644 connectors/corrosion/test/multitarget/multitarget/Cargo.toml delete mode 100644 connectors/corrosion/test/multitarget/multitarget/lib.cpp delete mode 100644 connectors/corrosion/test/multitarget/multitarget/src/bin/bin1.rs delete mode 100644 connectors/corrosion/test/multitarget/multitarget/src/bin/bin2.rs delete mode 100644 connectors/corrosion/test/multitarget/multitarget/src/bin/bin3.rs delete mode 100644 connectors/corrosion/test/multitarget/multitarget/src/lib.rs delete mode 100644 connectors/corrosion/test/nostd/CMakeLists.txt delete mode 100644 connectors/corrosion/test/nostd/nostd/CMakeLists.txt delete mode 100644 connectors/corrosion/test/nostd/nostd/main.cpp delete mode 100644 connectors/corrosion/test/nostd/nostd/rust/Cargo.toml delete mode 100644 connectors/corrosion/test/nostd/nostd/rust/src/lib.rs delete mode 100644 connectors/corrosion/test/output directory/CMakeLists.txt delete mode 100644 connectors/corrosion/test/output directory/TestFileExists.cmake delete mode 100644 connectors/corrosion/test/output directory/output directory/CMakeLists.txt delete mode 100644 connectors/corrosion/test/output directory/output directory/consumer.cpp delete mode 100644 connectors/corrosion/test/output directory/output directory/proj1/Cargo.toml delete mode 100644 connectors/corrosion/test/output directory/output directory/proj1/src/bin/rust_bin1.rs delete mode 100644 connectors/corrosion/test/output directory/output directory/proj1/src/lib.rs delete mode 100644 connectors/corrosion/test/output directory/output directory/proj2/Cargo.toml delete mode 100644 connectors/corrosion/test/output directory/output directory/proj2/src/bin/rust_bin2.rs delete mode 100644 connectors/corrosion/test/output directory/output directory/proj2/src/lib.rs delete mode 100644 connectors/corrosion/test/parse_target_triple/CMakeLists.txt delete mode 100644 connectors/corrosion/test/parse_target_triple/parse_target_triple/CMakeLists.txt delete mode 100644 connectors/corrosion/test/parse_target_triple/parse_target_triple/Cargo.toml delete mode 100644 connectors/corrosion/test/parse_target_triple/parse_target_triple_should_fail/CMakeLists.txt delete mode 100644 connectors/corrosion/test/parse_target_triple/parse_target_triple_should_fail/Cargo.toml delete mode 100644 connectors/corrosion/test/rust2cpp/CMakeLists.txt delete mode 100644 connectors/corrosion/test/rust2cpp/rust2cpp/CMakeLists.txt delete mode 100644 connectors/corrosion/test/rust2cpp/rust2cpp/main.cpp delete mode 100644 connectors/corrosion/test/rust2cpp/rust2cpp/rust/Cargo.toml delete mode 100644 connectors/corrosion/test/rust2cpp/rust2cpp/rust/src/lib.rs delete mode 100644 connectors/corrosion/test/rustflags/CMakeLists.txt delete mode 100644 connectors/corrosion/test/rustflags/cargo_config_rustflags/CMakeLists.txt delete mode 100644 connectors/corrosion/test/rustflags/cargo_config_rustflags/Cargo.toml delete mode 100644 connectors/corrosion/test/rustflags/cargo_config_rustflags/src/main.rs delete mode 100644 connectors/corrosion/test/rustflags/rustflags/CMakeLists.txt delete mode 100644 connectors/corrosion/test/rustflags/rustflags/main.cpp delete mode 100644 connectors/corrosion/test/rustflags/rustflags/rust/Cargo.toml delete mode 100644 connectors/corrosion/test/rustflags/rustflags/rust/some_dependency/Cargo.toml delete mode 100644 connectors/corrosion/test/rustflags/rustflags/rust/some_dependency/src/lib.rs delete mode 100644 connectors/corrosion/test/rustflags/rustflags/rust/src/lib.rs delete mode 100644 connectors/corrosion/test/workspace/CMakeLists.txt delete mode 100644 connectors/corrosion/test/workspace/workspace/CMakeLists.txt delete mode 100644 connectors/corrosion/test/workspace/workspace/Cargo.toml delete mode 100644 connectors/corrosion/test/workspace/workspace/main.cpp delete mode 100644 connectors/corrosion/test/workspace/workspace/member1/Cargo.toml delete mode 100644 connectors/corrosion/test/workspace/workspace/member1/src/lib.rs delete mode 100644 connectors/corrosion/test/workspace/workspace/member2/Cargo.toml delete mode 100644 connectors/corrosion/test/workspace/workspace/member2/src/lib.rs delete mode 100644 connectors/corrosion/test/workspace/workspace/member3/Cargo.toml delete mode 100644 connectors/corrosion/test/workspace/workspace/member3/src/main.rs diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..b1514d0b --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "cargokit"] + path = cargokit + url = https://github.com/irondash/cargokit diff --git a/cargokit b/cargokit new file mode 160000 index 00000000..54ae0380 --- /dev/null +++ b/cargokit @@ -0,0 +1 @@ +Subproject commit 54ae0380f0d85c31733b4e3f4bd34fbfb7003a35 diff --git a/connectors/README.md b/connectors/README.md deleted file mode 100644 index 59999de8..00000000 --- a/connectors/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Connectors - -These are tools for connecting Flutter and native compilers. - -Rust-In-Flutter was not made alone. There were pioneers that gave inspiration to the structure of this package. Credits to these wonderful efforts! - -- https://github.com/fzyzcjy/flutter_rust_bridge -- https://github.com/superlistapp/super_native_extensions -- https://github.com/brickpop/flutter-rust-ffi -- https://github.com/corrosion-rs/corrosion -- https://github.com/irondash/cargokit diff --git a/connectors/cargokit/.gitignore b/connectors/cargokit/.gitignore deleted file mode 100644 index 1de56593..00000000 --- a/connectors/cargokit/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target \ No newline at end of file diff --git a/connectors/cargokit/LICENSE b/connectors/cargokit/LICENSE deleted file mode 100644 index 54a7d589..00000000 --- a/connectors/cargokit/LICENSE +++ /dev/null @@ -1,39 +0,0 @@ -Copyright 2022 Matej Knopp - -================================================================================ - -MIT LICENSE - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS -OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -================================================================================ - -APACHE LICENSE, VERSION 2.0 - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - diff --git a/connectors/cargokit/README b/connectors/cargokit/README deleted file mode 100644 index e6869365..00000000 --- a/connectors/cargokit/README +++ /dev/null @@ -1,2 +0,0 @@ -Experimental repository to provide glue for seamlessly integrating cargo build -with flutter plugins and packages. diff --git a/connectors/cargokit/build_pod.sh b/connectors/cargokit/build_pod.sh deleted file mode 100755 index 8954fa4f..00000000 --- a/connectors/cargokit/build_pod.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -set -e - -BASEDIR=$(dirname "$0") - -# Remove XCode SDK from path. Otherwise this breaks tool compilation when building iOS project -NEW_PATH=`echo $PATH | tr ":" "\n" | grep -v "Contents/Developer/" | tr "\n" ":"` - -export PATH=${NEW_PATH%?} # remove trailing : - -export CARGOKIT_PLATFORM_NAME=$PLATFORM_NAME -export CARGOKIT_ARCHS=$ARCHS -export CARGOKIT_CONFIGURATION=$CONFIGURATION -export CARGOKIT_SRCROOT=$PODS_TARGET_SRCROOT -export CARGOKIT_TEMP_DIR=$TARGET_TEMP_DIR -export CARGOKIT_PRODUCT_NAME=$PRODUCT_NAME -export CARGOKIT_TARGET_DIR=$PODS_CONFIGURATION_BUILD_DIR -export CARGOKIT_TOOL_TEMP_DIR=$TARGET_TEMP_DIR/rust_tool - -$BASEDIR/run_rust_tool.sh build_pod $@ - -# Make a symlink from built framework to phony file, which will be used as input to -# build script. This should force rebuild (podspec currently doesn't support alwaysOutOfDate -# attribute on custom build phase) -ln -Fs "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}" "${BUILT_PRODUCTS_DIR}/connectors/cargokit_phony" -ln -Fs "${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}" "${BUILT_PRODUCTS_DIR}/connectors/cargokit_phony_out" diff --git a/connectors/cargokit/build_tool/Cargo.toml b/connectors/cargokit/build_tool/Cargo.toml deleted file mode 100644 index 77d694c1..00000000 --- a/connectors/cargokit/build_tool/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -# CargoKit will get symlinked to project, but it's not part of workspace - -[package] -name = "build_tool" -version = "0.1.0" -edition = "2021" - -[[bin]] -name = "build_tool" -path = "src/build_tool.rs" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -log = "0.4" -anyhow = "1.0" -semver = "1.0" diff --git a/connectors/cargokit/build_tool/src/build_android.rs b/connectors/cargokit/build_tool/src/build_android.rs deleted file mode 100644 index 364cec9c..00000000 --- a/connectors/cargokit/build_tool/src/build_android.rs +++ /dev/null @@ -1,316 +0,0 @@ -use std::{ - fmt::Debug, - fs, - io::Write, - path::{Path, PathBuf}, - process::Command, -}; - -use anyhow::{Context, Result}; -use log::{debug, info}; -use semver::Version; - -use super::utils::*; - -#[derive(Debug)] -enum Target { - ArmV7, - Arm64, - X86, - X86_64, -} - -impl Target { - fn rust_target(&self) -> &'static str { - match self { - Target::ArmV7 => "armv7-linux-androideabi", - Target::Arm64 => "aarch64-linux-android", - Target::X86 => "i686-linux-android", - Target::X86_64 => "x86_64-linux-android", - } - } - - fn target_dir(&self) -> &'static str { - match self { - Target::ArmV7 => "armeabi-v7a", - Target::Arm64 => "arm64-v8a", - Target::X86 => "x86", - Target::X86_64 => "x86_64", - } - } - - fn min_sdk_version(&self) -> i32 { - match self { - Target::ArmV7 => 16, - Target::Arm64 => 21, - Target::X86 => 16, - Target::X86_64 => 21, - } - } - - fn from_flutter_target(s: &str) -> Option { - match s { - "android-arm" => Some(Target::ArmV7), - "android-arm64" => Some(Target::Arm64), - "android-x86" => Some(Target::X86), - "android-x64" => Some(Target::X86_64), - _ => None, - } - } -} - -fn get_targets() -> Vec { - let platforms = std::env::var("CARGOKIT_TARGET_PLATFORMS") - .ok() - .unwrap_or_else(|| "".into()); - platforms - .split(',') - .filter_map(Target::from_flutter_target) - .collect() -} - -fn is_release() -> bool { - let configuration = std::env::var("CARGOKIT_BUILD_MODE") - .ok() - .unwrap_or_else(|| "release".into()); - configuration != "debug" -} - -#[cfg(target_os = "macos")] -const ARCH: &str = "darwin-x86_64"; -#[cfg(target_os = "linux")] -const ARCH: &str = "linux-x86_64"; -#[cfg(target_os = "windows")] -const ARCH: &str = "windows-x86_64"; - -// Workaround for libgcc missing in NDK23, inspired by cargo-ndk -fn libgcc_workaround(build_dir: &Path, ndk_version: &Version) -> Result { - let workaround_dir = build_dir - .join("cargokit") - .join("libgcc_workaround") - .join(ndk_version.major.to_string()); - fs::create_dir_all(&workaround_dir)?; - if ndk_version.major >= 23 { - let mut file = std::fs::File::create(workaround_dir.join("libgcc.a"))?; - file.write_all(b"INPUT(-lunwind)")?; - } else { - // Other way around, untested, forward libgcc.a from libunwind once Rust - // gets updated for NDK23+. - let mut file = std::fs::File::create(workaround_dir.join("libunwind.a"))?; - file.write_all(b"INPUT(-lgcc)")?; - } - - let mut rustflags = match std::env::var("CARGO_ENCODED_RUSTFLAGS") { - Ok(val) => val, - Err(std::env::VarError::NotPresent) => "".to_string(), - Err(std::env::VarError::NotUnicode(_)) => { - log::error!("RUSTFLAGS environment variable contains non-unicode characters"); - std::process::exit(1); - } - }; - - if !rustflags.is_empty() { - rustflags.push('\x1f'); - } - rustflags.push_str("-L\x1f"); - rustflags.push_str(&workaround_dir.to_string_lossy()); - - Ok(rustflags) -} - -fn pick_existing(paths: Vec) -> Option { - paths.into_iter().find(|p| p.exists()) -} - -fn install_ndk(sdk_path: &Path, ndk_version: &str, java_home: &str) -> Result<()> { - #[cfg(target_os = "windows")] - const SDK_MANAGER_EXTENSION: &str = ".bat"; - #[cfg(not(target_os = "windows"))] - const SDK_MANAGER_EXTENSION: &str = ""; - - let sdk_manager = sdk_path - .join("cmdline-tools") - .join("latest") - .join("bin") - .join(format!("sdkmanager{}", SDK_MANAGER_EXTENSION)); - - let mut cmd = Command::new(sdk_manager); - cmd.arg("--install") - .arg(format!("ndk;{}", ndk_version)) - .env("JAVA_HOME", java_home); - - run_command(cmd)?; - - Ok(()) -} - -fn build_for_target(target: &Target) -> Result<()> { - let min_version = string_from_env("CARGOKIT_MIN_SDK_VERSION")?; - let min_version: i32 = min_version.parse()?; - let min_version = min_version.max(target.min_sdk_version()); - - let ndk_version = string_from_env("CARGOKIT_NDK_VERSION")?; - - let sdk_path = path_from_env("CARGOKIT_SDK_DIR")?; - let ndk_path = sdk_path.join("ndk").join(&ndk_version); - - let ndk_package_xml = ndk_path.join("package.xml"); - - if !ndk_package_xml.is_file() { - info!("Installing NDK {}...", ndk_version); - let java_home = string_from_env("CARGOKIT_JAVA_HOME")?; - install_ndk(&sdk_path, &ndk_version, &java_home)?; - } - - if !ndk_package_xml.is_file() { - return Err(anyhow::format_err!( - "NDK version {} failed to install into {}", - ndk_version, - ndk_path.display() - )); - } - - let toolchain_path = ndk_path - .join("toolchains") - .join("llvm") - .join("prebuilt") - .join(ARCH) - .join("bin"); - - let ar_key = format!("AR_{}", target.rust_target()); - let ar_value = pick_existing(vec![ - toolchain_path.join(format!("{}-ar", target.rust_target())), - toolchain_path.join("llvm-ar"), - toolchain_path.join("llvm-ar.exe"), - ]) - .expect("Did not find ar tool"); - - let target_arg = format!("--target={}{}", target.rust_target(), min_version); - - let cc_key = format!("CC_{}", target.rust_target()); - let cc_value = toolchain_path.join("clang"); - let cflags_key = format!("CFLAGS_{}", target.rust_target()); - let cflags_value = target_arg.clone(); - - let cxx_key = format!("CXX_{}", target.rust_target()); - let cxx_value = toolchain_path.join("clang++"); - let cxx_flags_key = format!("CXXFLAGS_{}", target.rust_target()); - let cxx_flags_value = target_arg.clone(); - - let rustflags_key = "CARGO_ENCODED_RUSTFLAGS"; - - let linker_key = format!( - "cargo_target_{}_linker", - target.rust_target().replace('-', "_") - ) - .to_ascii_uppercase(); - - let ranlib_key = format!("RANLIB_{}", target.rust_target()); - let ranlib_value = toolchain_path.join("llvm-ranlib"); - - let build_dir = path_from_env("CARGOKIT_BUILD_DIR")?; - let output_dir = path_from_env("CARGOKIT_OUTPUT_DIR")?; - let lib_name = string_from_env("CARGOKIT_LIB_NAME")?; - - let ndk_version = Version::parse(&ndk_version)?; - let rust_flags_value = libgcc_workaround(&build_dir, &ndk_version)?; - - // Workaround for https://github.com/android/ndk/issues/1856 - // based on cargo-ndk solution. - // https://github.com/bbqsrc/cargo-ndk/commit/d6cdbf4feef48ebea5eee8958e9c98431c3c5f32 - let self_path = std::fs::canonicalize(std::env::args().next().unwrap()) - .expect("Failed to canonicalize absolute path to build_android"); - - debug!("ENV {}={}", ar_key, ar_value.display()); - debug!("ENV {}={}", cc_key, cc_value.display()); - debug!("ENV {}={}", cxx_key, cxx_value.display()); - debug!("ENV {}={}", linker_key, self_path.display()); - debug!("ENV {}={}", rustflags_key, rust_flags_value); - debug!("ENV {}={}", ranlib_key, ranlib_value.display()); - debug!("ENV {}={}", cflags_key, cflags_value); - debug!("ENV {}={}", cxx_flags_key, cxx_flags_value); - - let mut cmd = Command::new("cargo"); - cmd.arg("build"); - cmd.arg("--manifest-path"); - cmd.arg(path_from_env("CARGOKIT_MANIFEST_DIR")?.join("Cargo.toml")); - cmd.arg("-p"); - cmd.arg(&lib_name); - if is_release() { - cmd.arg("--release"); - } - cmd.arg("--target"); - cmd.arg(target.rust_target()); - cmd.arg("--target-dir"); - cmd.arg(&build_dir); - - cmd.env(ar_key, &ar_value); - cmd.env(cc_key, &cc_value); - cmd.env(cxx_key, &cxx_value); - cmd.env(linker_key, &self_path); - cmd.env(rustflags_key, &rust_flags_value); - cmd.env(cflags_key, &cflags_value); - cmd.env(cxx_flags_key, &cxx_flags_value); - cmd.env("_CARGOKIT_NDK_LINK_TARGET", target_arg); // Recognized by main() so we know when we're acting as a wrapper - cmd.env("_CARGOKIT_NDK_LINK_CLANG", &cc_value); - - run_command(cmd)?; - - let output_dir = output_dir.join(target.target_dir()); - fs::create_dir_all(&output_dir)?; - - let lib_name_full = format!("lib{}.so", lib_name); - let src = build_dir - .join(target.rust_target()) - .join(if is_release() { "release" } else { "debug" }) - .join(&lib_name_full); - let dst = output_dir.join(&lib_name_full); - fs::copy(&src, &dst) - .with_context(|| format!("dst: {:?}", dst)) - .with_context(|| format!("src: {:?}", src))?; - - Ok(()) -} - -pub fn clang_linker_wrapper() -> ! { - let args = std::env::args_os().skip(1); - let clang = std::env::var("_CARGOKIT_NDK_LINK_CLANG") - .expect("cargo-ndk rustc linker: didn't find _CARGOKIT_NDK_LINK_CLANG env var"); - let target = std::env::var("_CARGOKIT_NDK_LINK_TARGET") - .expect("cargo-ndk rustc linker: didn't find _CARGOKIT_NDK_LINK_TARGET env var"); - - let mut child = std::process::Command::new(&clang) - .arg(target) - .args(args) - .spawn() - .unwrap_or_else(|err| { - eprintln!("cargokit: Failed to spawn {clang:?} as linker: {err}"); - std::process::exit(1) - }); - let status = child.wait().unwrap_or_else(|err| { - eprintln!("cargokit (as linker): Failed to wait for {clang:?} to complete: {err}"); - std::process::exit(1); - }); - - std::process::exit(status.code().unwrap_or(1)) -} - -pub fn build_android() -> Result<()> { - let targets = get_targets(); - debug!("Building for targets: {:?}", targets); - - let installed_targets = installed_targets()?; - for target in &targets { - if !installed_targets.contains(&target.rust_target().to_owned()) { - info!("Installing target {}...", target.rust_target()); - install_target(target.rust_target())?; - } - } - - for target in &targets { - debug!("Building for {}...", target.rust_target()); - build_for_target(target)?; - } - - Ok(()) -} diff --git a/connectors/cargokit/build_tool/src/build_cmake.rs b/connectors/cargokit/build_tool/src/build_cmake.rs deleted file mode 100644 index 89770e2a..00000000 --- a/connectors/cargokit/build_tool/src/build_cmake.rs +++ /dev/null @@ -1,94 +0,0 @@ -use std::{fs, process::Command}; - -use anyhow::Result; - -use super::utils::*; -use log::info; - -enum Target { - WindowsX64, - LinuxX64, - LinuxArm64, -} - -impl Target { - fn rust_target(&self) -> &'static str { - match self { - Target::WindowsX64 => "x86_64-pc-windows-msvc", - Target::LinuxX64 => "x86_64-unknown-linux-gnu", - Target::LinuxArm64 => "aarch64-unknown-linux-gnu", - } - } - - fn from_flutter_target(s: &str) -> Option { - match s { - "windows-x64" => Some(Target::WindowsX64), - "linux-x64" => Some(Target::LinuxX64), - "linux-arm64" => Some(Target::LinuxArm64), - _ => None, - } - } -} - -fn is_release() -> bool { - let configuration = std::env::var("CARGOKIT_CONFIGURATION") - .ok() - .map(|s| s.to_ascii_lowercase()) - .unwrap_or_else(|| "release".into()); - configuration != "debug" -} - -pub fn build_cmake() -> Result<()> { - let target = string_from_env("CARGOKIT_TARGET_PLATFORM")?; - let target = Target::from_flutter_target(&target) - .ok_or_else(|| anyhow::anyhow!("Invalid target {:?}", target))?; - let installed_targets = installed_targets()?; - if !installed_targets.contains(&target.rust_target().to_owned()) { - info!("Installing target {}...", target.rust_target()); - install_target(target.rust_target())?; - } - - let build_dir = path_from_env("CARGOKIT_BUILD_DIR")?; - let output_dir = path_from_env("CARGOKIT_TARGET_DIR")?; - let lib_name = string_from_env("CARGOKIT_LIB_NAME")?; - let manifest_path = path_from_env("CARGOKIT_MANIFEST_DIR")? - .join("Cargo.toml") - .canonicalize()?; - - let mut cmd = Command::new("cargo"); - cmd.arg("build"); - cmd.arg("--manifest-path"); - cmd.arg(manifest_path); - cmd.arg("-p"); - cmd.arg(&lib_name); - if is_release() { - cmd.arg("--release"); - } - cmd.arg("--target"); - cmd.arg(target.rust_target()); - cmd.arg("--target-dir"); - cmd.arg(&build_dir); - - run_command(cmd)?; - - let src_dir = - build_dir - .join(target.rust_target()) - .join(if is_release() { "release" } else { "debug" }); - - let files = [ - format!("lib{}.so", lib_name), - format!("{}.dll", lib_name), - format!("{}.dll.lib", lib_name), - format!("{}.pdb", lib_name), - ]; - - for file in files { - let path = src_dir.join(&file); - if path.exists() { - fs::copy(path, output_dir.join(&file))?; - } - } - - Ok(()) -} diff --git a/connectors/cargokit/build_tool/src/build_pod.rs b/connectors/cargokit/build_tool/src/build_pod.rs deleted file mode 100644 index cc8ab4db..00000000 --- a/connectors/cargokit/build_tool/src/build_pod.rs +++ /dev/null @@ -1,158 +0,0 @@ -use anyhow::Result; -use log::info; -use std::{ - env::Args, - path::{Path, PathBuf}, - process::Command, -}; - -use super::utils::*; - -fn get_archs() -> Vec { - let archs = std::env::var("CARGOKIT_ARCHS") - .ok() - .unwrap_or_else(|| "x86_64".into()); - archs.split(' ').map(String::from).collect() -} - -fn target_for_arch(arch: &str) -> Result { - let platform_name = string_from_env("CARGOKIT_PLATFORM_NAME")?; - let suffix = match platform_name.as_str() { - "macosx" => "apple-darwin", - "iphonesimulator" => "apple-ios-sim", - "iphoneos" => "apple-ios", - platform => { - return Err(anyhow::format_err!("Unknown platform {}", platform)); - } - }; - let arch = match arch { - "arm64" => "aarch64", - "armv7" => "armv7", - "x86_64" => "x86_64", - arch => { - return Err(anyhow::format_err!("Unknown architecture {}", arch)); - } - }; - let res = format!("{}-{}", arch, suffix); - if res == "x86_64-apple-ios-sim" { - return Ok("x86_64-apple-ios".into()); - } - Ok(res) -} - -fn is_release() -> bool { - let configuration = std::env::var("CARGOKIT_CONFIGURATION") - .ok() - .unwrap_or_else(|| "Release".into()); - configuration != "Debug" -} - -fn manifest_path(src_path: &str) -> Result { - let src_root = path_from_env("CARGOKIT_SRCROOT")?; - // Resolve symlink so that crates with relative paths work properly - // when using as flutter plugin (which itself is symlinked) - Ok(src_root.join(src_path).join("Cargo.toml").canonicalize()?) -} - -fn temp_target_dir() -> Result { - let target_dir = string_from_env("CARGOKIT_TEMP_DIR")?; - Ok(target_dir.into()) -} - -fn final_target_dir() -> Result { - let product_name = string_from_env("CARGOKIT_PRODUCT_NAME")?; - let target_path = path_from_env("CARGOKIT_TARGET_DIR")?; - Ok(target_path.join(product_name)) -} - -pub fn build_pod(mut args: Args) -> Result<()> { - let src_path = args.next().unwrap(); - let lib_name = args.next().unwrap(); - - let archs = get_archs(); - let targets = installed_targets()?; - for arch in &archs { - let target = target_for_arch(arch)?; - if !targets.contains(&target) { - info!("Installing rust target {}...", target); - install_target(&target)?; - } - } - - for arch in &archs { - let mut cmd = Command::new("cargo"); - cmd.arg("build"); - cmd.arg("--manifest-path"); - cmd.arg(manifest_path(&src_path)?); - cmd.arg("-p"); - cmd.arg(&lib_name); - if is_release() { - cmd.arg("--release"); - } - cmd.arg("--target"); - cmd.arg(target_for_arch(arch)?); - cmd.arg("--target-dir"); - cmd.arg(temp_target_dir()?); - run_command(cmd)?; - } - - let lib_path = |lib_name: &str, arch: &str| -> Result { - let path = temp_target_dir()? - .join(target_for_arch(arch)?) - .join(if is_release() { "release" } else { "debug" }) - .join(lib_name); - Ok(path) - }; - - let perform_lipo = |target_file: &Path, lib_name: &str| -> Result<()> { - let mut cmd = Command::new("lipo"); - cmd.arg("-create"); - for arch in &archs { - let path = lib_path(lib_name, arch)?; - cmd.arg(path); - } - cmd.arg("-output"); - cmd.arg(target_file); - run_command(cmd)?; - Ok(()) - }; - - let static_lib_name = format!("lib{}.a", lib_name); - let is_static_lib = archs.iter().any(|a| { - lib_path(&static_lib_name, a) - .map(|a| a.exists()) - .unwrap_or(false) - }); - - // If the crate builds both staticlib and cdylib, we use static lib, assuming - // it will be linked with the rest of pod. - if is_static_lib { - let target_file = final_target_dir()?.join(&static_lib_name); - perform_lipo(&target_file, &static_lib_name)?; - Ok(()) - } else { - let bundle_paths = &[ - format!("{}.framework/Versions/A/{}", lib_name, lib_name), - format!("{}.framework/{}", lib_name, lib_name), // iOS - ]; - - // Dynamic library in a bundle. Replace bundle dylib with lipoed rust dylib. - for bundle_path in bundle_paths { - let target_file = final_target_dir()?.join(bundle_path); - if target_file.exists() { - let lib_name = format!("lib{}.dylib", lib_name); - perform_lipo(&target_file, &lib_name)?; - - // Replace absolute id with @rpath one so that it works properly - // when moved to Frameworks. - let mut cmd = Command::new("install_name_tool"); - cmd.arg("-id"); - cmd.arg(format!("@rpath/{}", bundle_path)); - cmd.arg(&target_file); - run_command(cmd)?; - return Ok(()); - } - } - Err(anyhow::anyhow!("Unable to find bundle for dynamic library")) - } -} diff --git a/connectors/cargokit/build_tool/src/build_tool.rs b/connectors/cargokit/build_tool/src/build_tool.rs deleted file mode 100644 index e4a2a18b..00000000 --- a/connectors/cargokit/build_tool/src/build_tool.rs +++ /dev/null @@ -1,66 +0,0 @@ -use std::{env::args, process::exit}; - -use anyhow::Result; -use build_android::clang_linker_wrapper; -use log::{debug, LevelFilter}; - -mod build_android; -mod build_cmake; -mod build_pod; -mod logger; -mod utils; - -fn init_logging() -> Result<()> { - let silent = std::env::var("CARGOKIT_SILENT") - .ok() - .unwrap_or_else(|| "".into()); - let level = if silent == "1" { - LevelFilter::Info - } else { - LevelFilter::Debug - }; - logger::init_with_level(level) - .map_err(|e| anyhow::format_err!("Failed to setup logger: {}", e))?; - Ok(()) -} - -fn dump_environment() -> Result<()> { - debug!("CargoKit environment:"); - for var in std::env::vars() { - if var.0.to_ascii_lowercase().starts_with("cargokit_") { - debug!("{}={}", var.0, var.1); - } - } - Ok(()) -} - -fn run() -> Result<()> { - init_logging()?; - dump_environment()?; - - if std::env::var("_CARGOKIT_NDK_LINK_TARGET").is_ok() { - clang_linker_wrapper(); - } - - let mut args = args(); - args.next(); // executable - - let command = args - .next() - .ok_or_else(|| anyhow::format_err!("Missing argument"))?; - - match command.as_str() { - "build_pod" => build_pod::build_pod(args), - "build_android" => build_android::build_android(), - "build_cmake" => build_cmake::build_cmake(), - command => Err(anyhow::format_err!("Invalid command: {}", command)), - } -} - -fn main() { - let res = run(); - if let Err(error) = res { - eprintln!("Build tool failed:\n{:?}", error); - exit(1); - } -} diff --git a/connectors/cargokit/build_tool/src/logger.rs b/connectors/cargokit/build_tool/src/logger.rs deleted file mode 100644 index a46932e6..00000000 --- a/connectors/cargokit/build_tool/src/logger.rs +++ /dev/null @@ -1,23 +0,0 @@ -use log::{Level, LevelFilter, Metadata, Record, SetLoggerError}; - -struct SimpleLogger; - -impl log::Log for SimpleLogger { - fn enabled(&self, metadata: &Metadata) -> bool { - metadata.level() <= Level::Info - } - - fn log(&self, record: &Record) { - if self.enabled(record.metadata()) { - println!("{} - {}", record.level(), record.args()); - } - } - - fn flush(&self) {} -} - -static LOGGER: SimpleLogger = SimpleLogger; - -pub fn init_with_level(level: LevelFilter) -> Result<(), SetLoggerError> { - log::set_logger(&LOGGER).map(|()| log::set_max_level(level)) -} diff --git a/connectors/cargokit/build_tool/src/utils.rs b/connectors/cargokit/build_tool/src/utils.rs deleted file mode 100644 index 9e9f6ff3..00000000 --- a/connectors/cargokit/build_tool/src/utils.rs +++ /dev/null @@ -1,50 +0,0 @@ -use std::{path::PathBuf, process::Command}; - -use anyhow::{Context, Result}; -use log::debug; - -pub fn run_command(mut command: Command) -> Result { - debug!("Running command ${:?}", command); - - let output = command - .output() - .with_context(|| format!("Failed to run command: {:?}", command.get_program()))?; - - #[allow(unused_mut)] - let mut success = output.status.success(); - let stdout = String::from_utf8_lossy(&output.stdout); - - if !success { - Err(anyhow::format_err!( - "Command {:?} failed with error {};\nstderr: {}\nstdout: {}", - command, - output.status, - String::from_utf8(output.stderr).unwrap(), - stdout - )) - } else { - Ok(stdout.into()) - } -} - -pub fn installed_targets() -> Result> { - let mut cmd = Command::new("rustup"); - cmd.args(["target", "list", "--installed"]); - let installed = run_command(cmd)?; - Ok(installed.split('\n').map(String::from).collect()) -} - -pub fn install_target(target: &str) -> Result<()> { - let mut cmd = Command::new("rustup"); - cmd.args(["target", "add", target]); - run_command(cmd)?; - Ok(()) -} - -pub fn string_from_env(var: &str) -> Result { - std::env::var(var).with_context(|| format!("Missing environment variable: {}", var)) -} - -pub fn path_from_env(var: &str) -> Result { - Ok(string_from_env(var)?.into()) -} diff --git a/connectors/cargokit/cmake/cargokit.cmake b/connectors/cargokit/cmake/cargokit.cmake deleted file mode 100644 index 39d5124d..00000000 --- a/connectors/cargokit/cmake/cargokit.cmake +++ /dev/null @@ -1,89 +0,0 @@ -SET(cargokit_cmake_root "${CMAKE_CURRENT_LIST_DIR}/..") - -# Arguments -# - target: CMAKE target to which rust library is linked -# - manifest_dir: relative path from current folder to directory containing cargo manifest -# - lib_name: cargo package name -# - any_symbol_name: name of any exported symbol from the library. -# used on windows to force linking with library. -function(apply_cargokit target manifest_dir lib_name any_symbol_name) - - set(CARGOKIT_LIB_NAME "${lib_name}") - set(CARGOKIT_LIB_FULL_NAME "${CMAKE_SHARED_MODULE_PREFIX}${CARGOKIT_LIB_NAME}${CMAKE_SHARED_MODULE_SUFFIX}") - if (CMAKE_CONFIGURATION_TYPES) - set(CARGOKIT_TARGET_DIR "${CMAKE_CURRENT_BINARY_DIR}/$") - set(OUTPUT_LIB "${CMAKE_CURRENT_BINARY_DIR}/$/${CARGOKIT_LIB_FULL_NAME}") - else() - set(CARGOKIT_TARGET_DIR "${CMAKE_CURRENT_BINARY_DIR}") - set(OUTPUT_LIB "${CMAKE_CURRENT_BINARY_DIR}/${CARGOKIT_LIB_FULL_NAME}") - endif() - set(CARGOKIT_TEMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/connectors/cargokit_build") - - if (FLUTTER_TARGET_PLATFORM) - set(CARGOKIT_TARGET_PLATFORM "${FLUTTER_TARGET_PLATFORM}") - else() - set(CARGOKIT_TARGET_PLATFORM "windows-x64") - endif() - - set(CARGOKIT_ENV - "CARGOKIT_CMAKE=${CMAKE_COMMAND}" - "CARGOKIT_CONFIGURATION=$" - "CARGOKIT_MANIFEST_DIR=${CMAKE_CURRENT_SOURCE_DIR}/${manifest_dir}" - "CARGOKIT_LIB_NAME=${CARGOKIT_LIB_NAME}" - "CARGOKIT_BUILD_DIR=${CARGOKIT_TEMP_DIR}" - "CARGOKIT_TARGET_DIR=${CARGOKIT_TARGET_DIR}" - "CARGOKIT_TARGET_PLATFORM=${CARGOKIT_TARGET_PLATFORM}" - "CARGOKIT_TOOL_TEMP_DIR=${CARGOKIT_TEMP_DIR}/tool" - ) - - if (WIN32) - set(SCRIPT_EXTENSION ".cmd") - set(IMPORT_LIB_EXTENSION ".lib") - else() - set(SCRIPT_EXTENSION ".sh") - set(IMPORT_LIB_EXTENSION "") - endif() - - # Using generators in custom command is only supported in CMake 3.20+ - if (CMAKE_CONFIGURATION_TYPES AND ${CMAKE_VERSION} VERSION_LESS "3.20.0") - foreach(CONFIG IN LISTS CMAKE_CONFIGURATION_TYPES) - add_custom_command( - OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/${CONFIG}/${CARGOKIT_LIB_FULL_NAME}" - "${CMAKE_CURRENT_BINARY_DIR}/_phony_" - COMMAND ${CMAKE_COMMAND} -E env ${CARGOKIT_ENV} - "${cargokit_cmake_root}/run_rust_tool${SCRIPT_EXTENSION}" build_cmake - VERBATIM - ) - endforeach() - else() - add_custom_command( - OUTPUT - ${OUTPUT_LIB} - "${CMAKE_CURRENT_BINARY_DIR}/_phony_" - COMMAND ${CMAKE_COMMAND} -E env ${CARGOKIT_ENV} - "${cargokit_cmake_root}/run_rust_tool${SCRIPT_EXTENSION}" build_cmake - VERBATIM - ) - endif() - - set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/_phony_" PROPERTIES SYMBOLIC TRUE) - - if (TARGET ${target}) - # If we have actual cmake target provided create target and make existing - # target depend on it - add_custom_target("${target}_cargokit" DEPENDS ${OUTPUT_LIB}) - add_dependencies("${target}" "${target}_cargokit") - target_link_libraries("${target}" PRIVATE "${OUTPUT_LIB}${IMPORT_LIB_EXTENSION}") - if(WIN32) - target_link_options(${target} PRIVATE "/INCLUDE:${any_symbol_name}") - endif() - else() - # Otherwise (FFI) just use ALL to force building always - add_custom_target("${target}_cargokit" ALL DEPENDS ${OUTPUT_LIB}) - endif() - - # Allow adding the output library to plugin bundled libraries - set("${target}_cargokit_lib" ${OUTPUT_LIB} PARENT_SCOPE) - -endfunction() \ No newline at end of file diff --git a/connectors/cargokit/gradle/plugin.gradle b/connectors/cargokit/gradle/plugin.gradle deleted file mode 100644 index 1ee1fb77..00000000 --- a/connectors/cargokit/gradle/plugin.gradle +++ /dev/null @@ -1,164 +0,0 @@ -import java.nio.file.Paths -import org.apache.tools.ant.taskdefs.condition.Os - -CargoKitPlugin.file = buildscript.sourceFile - -apply plugin: CargoKitPlugin - -class CargoKitExtension { - String manifestDir; // Relative path to folder containing Cargo.toml - String libname; // Library name within Cargo.toml. Must be a cdylib -} - -abstract class CargoKitBuildTask extends DefaultTask { - - @Input - String buildMode - - @Input - String buildDir - - @Input - String outputDir - - @Input - String ndkVersion - - @Input - String sdkDirectory - - @Input - int compileSdkVersion; - - @Input - int minSdkVersion; - - @Input - String pluginFile - - @Input - List targetPlatforms - - @TaskAction - def build() { - if (project.cargokit.manifestDir == null) { - throw new GradleException("Property 'manifestDir' must be set on cargokit extension"); - } - - if (project.cargokit.libname == null) { - throw new GradleException("Property 'libname' must be set on cargokit extension"); - } - - def executableName = Os.isFamily(Os.FAMILY_WINDOWS) ? "run_rust_tool.cmd" : "run_rust_tool.sh" - def path = Paths.get(new File(pluginFile).parent, "..", executableName); - - def manifestDir = project.cargokit.manifestDir - - project.exec { - executable path - args "build_android" - environment "CARGOKIT_TOOL_TEMP_DIR", "${buildDir}/rust_tool" - environment "CARGOKIT_MANIFEST_DIR", manifestDir - environment "CARGOKIT_LIB_NAME", project.cargokit.libname - environment "CARGOKIT_BUILD_MODE", buildMode - environment "CARGOKIT_BUILD_DIR", buildDir - environment "CARGOKIT_OUTPUT_DIR", outputDir - environment "CARGOKIT_NDK_VERSION", ndkVersion - environment "CARGOKIT_SDK_DIR", sdkDirectory - environment "CARGOKIT_COMPILE_SDK_VERSION", compileSdkVersion - environment "CARGOKIT_MIN_SDK_VERSION", minSdkVersion - environment "CARGOKIT_TARGET_PLATFORMS", targetPlatforms.join(",") - environment "CARGOKIT_JAVA_HOME", System.properties['java.home'] - } - } -} - -class CargoKitPlugin implements Plugin { - - static String file; - - private Plugin findFlutterPlugin(Project rootProject) { - _findFlutterPlugin(rootProject.childProjects) - } - - private Plugin _findFlutterPlugin(Map projects) { - for (project in projects) { - for (plugin in project.value.getPlugins()) { - if (plugin.class.name == "FlutterPlugin") { - return plugin; - } - } - def plugin = _findFlutterPlugin(project.value.childProjects); - if (plugin != null) { - return plugin; - } - } - return null; - } - - @Override - void apply(Project project) { - def plugin = findFlutterPlugin(project.rootProject); - - project.extensions.create("cargokit", CargoKitExtension) - - if (plugin == null) { - print("Flutter plugin not found, CargoKit plugin will not be applied.") - return; - } - - def cargoBuildDir = "${project.buildDir}/build" - - plugin.project.android.applicationVariants.all { variant -> - - final buildType = variant.buildType.name - - def cargoOutputDir = "${project.buildDir}/jniLibs/${buildType}"; - def jniLibs = project.android.sourceSets.maybeCreate(buildType).jniLibs; - jniLibs.srcDir(new File(cargoOutputDir)) - - def platforms = plugin.getTargetPlatforms().collect() - - // Same thing addFlutterDependencies does in flutter.gradle - if (buildType == "debug") { - platforms.add("android-x86") - platforms.add("android-x64") - } - - // The task name depends on plugin properties, which are not available - // at this point - project.getGradle().afterProject { - def taskName = "cargokitCargoBuild${project.cargokit.libname.capitalize()}${buildType.capitalize()}"; - - if (project.tasks.findByName(taskName)) { - return - } - - if (plugin.project.android.ndkVersion == null) { - throw new GradleException("Please set 'android.ndkVersion' in 'app/build.gradle'.") - } - - def task = project.tasks.create(taskName, CargoKitBuildTask.class) { - buildMode = variant.name - buildDir = cargoBuildDir - outputDir = cargoOutputDir - ndkVersion = plugin.project.android.ndkVersion - sdkDirectory = plugin.project.android.sdkDirectory - minSdkVersion = plugin.project.android.defaultConfig.minSdkVersion.apiLevel as int - compileSdkVersion = plugin.project.android.compileSdkVersion.substring(8) as int - targetPlatforms = platforms - pluginFile = CargoKitPlugin.file - } - def onTask = { newTask -> - if (newTask.name == "merge${buildType.capitalize()}NativeLibs") { - newTask.dependsOn task - // Fix gradle 7.4.2 not picking up JNI library changes - newTask.outputs.upToDateWhen { false } - } - } - project.tasks.each onTask - project.tasks.whenTaskAdded onTask - } - } - } -} diff --git a/connectors/cargokit/run_rust_tool.cmd b/connectors/cargokit/run_rust_tool.cmd deleted file mode 100644 index f3eb19c9..00000000 --- a/connectors/cargokit/run_rust_tool.cmd +++ /dev/null @@ -1,25 +0,0 @@ -@echo off -setlocal - -set Path=%HOME%\.cargo\bin;%Path% - -SET BASEDIR=%~dp0 - -WHERE cargo - -if errorlevel 1 ( - echo ================================================================ - echo == - echo == cargo not found! - @REM echo == - @REM echo == We looked in Path: "%Path%" - echo == - echo == Maybe you need to install Rust? It only takes a minute: - echo == - echo == https://www.rust-lang.org/tools/install - echo == - echo ================================================================ - exit 1 -) - -cargo run --manifest-path=%BASEDIR%/build_tool/Cargo.toml --bin build_tool --target-dir=%CARGOKIT_TOOL_TEMP_DIR% --quiet -- %* diff --git a/connectors/cargokit/run_rust_tool.sh b/connectors/cargokit/run_rust_tool.sh deleted file mode 100755 index 06b91ae7..00000000 --- a/connectors/cargokit/run_rust_tool.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -set -e - -BASEDIR=$(dirname "$0") - -# In case we're running in environment without PATH put the default location in there -# Put it at the front so that we don't accidentally pick up homebrew's cargo. -PATH="~/.cargo/bin:$PATH" - -if ! command -v cargo --version >/dev/null 2>&1 -then - echo "|" - echo "| cargo not found." - echo "|" - echo "| We looked in $PATH" - echo "|" - echo "| Maybe you need to install Rust? It only takes a minute:" - echo "|" - echo "> curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh" - echo "|" - exit 1 -fi - -cargo run --manifest-path=$BASEDIR/build_tool/Cargo.toml --bin build_tool --target-dir=$CARGOKIT_TOOL_TEMP_DIR --quiet -- $@ diff --git a/connectors/corrosion/.github/workflows/test.yaml b/connectors/corrosion/.github/workflows/test.yaml deleted file mode 100644 index c3d60e14..00000000 --- a/connectors/corrosion/.github/workflows/test.yaml +++ /dev/null @@ -1,321 +0,0 @@ -name: Tests -on: - push: - branches: - - master - pull_request: - branches: - - '**' -jobs: - test: - name: Test Corrosion - runs-on: ${{ matrix.os }} - continue-on-error: ${{ matrix.rust == 'nightly' }} - strategy: - fail-fast: false - matrix: - os: - - windows-2019 # windows-latest is currently not having a supported MSVC compiler - - ubuntu-latest - - macos-12 - arch: - - x86_64 - - i686 - - aarch64 - - powerpc64le - abi: - - gnu - - darwin - - msvc - cmake: - - 3.15.7 - - 3.19.0 - rust: - - 1.46.0 # MSRV Minimum supported rust version - - 1.54.0 # MSRV macos-12 - - stable - generator: - - default # This is just whatever the platform default is - - ninja - - include: - - rust: nightly - cmake: 3.19.0 - generator: ninja - arch: x86_64 - abi: msvc - os: windows-2019 - - rust: nightly - cmake: 3.19.0 - generator: ninja - arch: x86_64 - abi: gnu - os: ubuntu-latest - - rust: nightly - cmake: 3.19.0 - generator: ninja - arch: x86_64 - abi: darwin - os: macos-12 - - os: ubuntu-latest - arch: x86_64 - abi: gnu - cmake: 3.20.0 - rust: stable - generator: ninja-multiconfig - - os: windows-2022 - arch: aarch64 - abi: msvc - cmake: 3.21.5 # Earliest supported version for VS 17 in windows-2022 - rust: "1.54" # Minimum supported rust version for cross-compile with Windows MSVC - generator: default - - os: windows-2022 - arch: i686 - abi: msvc - cmake: 3.21.5 # Earliest supported version for VS 17 in windows-2022 - rust: "1.54" # Minimum supported rust version for cross-compile with Windows MSVC - generator: default - - exclude: - - # You cannot build with GNU using Visual Studio on Windows - - os: windows-2019 - abi: gnu - generator: default # Default generator is Visual Studio - - # ARCH - - os: windows-2019 - arch: i686 - abi: gnu - - os: windows-2019 - arch: aarch64 - abi: gnu - - os: windows-2019 - arch: i686 - generator: ninja - - os: windows-2019 - arch: aarch64 - generator: ninja - - os: windows-2019 - arch: powerpc64le - - os: macos-12 - arch: i686 - - os: macos-12 - arch: aarch64 - - os: macos-12 - arch: powerpc64le - - # Cross-compiling is broken on Windows with MSVC before 1.54, since build-scripts are cross-linked instead - # of being linked for the host platform. - - os: windows-2019 - abi: msvc - rust: 1.46.0 - arch: i686 - - os: windows-2019 - abi: msvc - rust: 1.46.0 - arch: aarch64 - - os: windows-2022 - abi: msvc - rust: 1.46.0 - arch: i686 - - os: windows-2022 - abi: msvc - rust: 1.46.0 - arch: aarch64 - - # ABI - - os: ubuntu-latest - abi: msvc - - os: ubuntu-latest - abi: darwin - - os: windows-2019 - abi: darwin - - os: macos-12 - abi: msvc - - os: macos-12 - abi: gnu - - # Rust: - - rust: 1.46.0 - os: macos-12 - - rust: 1.54.0 - os: windows-2019 - abi: gnu - - rust: 1.54.0 - os: windows-2019 - abi: msvc - arch: x86_64 - - rust: 1.54.0 - os: ubuntu-latest - - steps: - - name: Determine Rust OS - id: determine_rust_os - shell: bash - run: | - if [ "${{ runner.os }}" == "Windows" ]; then - echo "os=pc-windows" >> $GITHUB_OUTPUT - echo "host_abi=msvc" >> $GITHUB_OUTPUT - elif [ "${{ runner.os }}" == "Linux" ]; then - echo "os=unknown-linux" >> $GITHUB_OUTPUT - echo "host_abi=gnu" >> $GITHUB_OUTPUT - elif [ "${{ runner.os }}" == "macOS" ]; then - echo "os=apple" >> $GITHUB_OUTPUT - echo "host_abi=darwin" >> $GITHUB_OUTPUT - fi - - name: Pick Compiler - id: pick_compiler - shell: bash - run: | - if [ "${{ matrix.abi }}" == "gnu" ]; then - if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then - echo "c_compiler=-DCMAKE_C_COMPILER=${{matrix.arch}}-linux-gnu-gcc" >> $GITHUB_OUTPUT - echo "cxx_compiler=-DCMAKE_CXX_COMPILER=${{matrix.arch}}-linux-gnu-g++" >> $GITHUB_OUTPUT - # todo: only set this when cross-compiling - echo "system_name=-DCMAKE_SYSTEM_NAME=Linux" >> $GITHUB_OUTPUT - else - echo "c_compiler=-DCMAKE_C_COMPILER=gcc" >> $GITHUB_OUTPUT - echo "cxx_compiler=-DCMAKE_CXX_COMPILER=g++" >> $GITHUB_OUTPUT - fi - elif [ "${{ matrix.abi }}" == "darwin" ]; then - echo "c_compiler=-DCMAKE_C_COMPILER=clang" >> $GITHUB_OUTPUT - echo "cxx_compiler=-DCMAKE_CXX_COMPILER=clang++" >> $GITHUB_OUTPUT - elif [ "${{ matrix.abi }}" == "msvc" ]; then - echo "c_compiler=-DCMAKE_C_COMPILER=cl" >> $GITHUB_OUTPUT - echo "cxx_compiler=-DCMAKE_CXX_COMPILER=cl" >> $GITHUB_OUTPUT - fi - - name: Pick Generator - id: pick_generator - shell: bash - run: | - if [ "${{ matrix.generator }}" == "ninja" ]; then - echo "generator=-GNinja" >> $GITHUB_OUTPUT - elif [ "${{ matrix.generator }}" == "ninja-multiconfig" ];then - echo "generator=-GNinja Multi-Config" >> $GITHUB_OUTPUT - fi - - name: Arch Flags - id: arch_flags - shell: bash - run: | # Cross-compiling is currently only supported on Windows+MSVC with the default generator - if [ "${{ runner.os }}" == "Windows" ]; then - if [ "${{matrix.generator}}" == "default" ]; then - if [ "${{ matrix.arch }}" == "x86_64" ]; then - echo "msvc=amd64" >> $GITHUB_OUTPUT - echo "cmake=-Ax64" >> $GITHUB_OUTPUT - elif [ "${{ matrix.arch }}" == "i686" ]; then - echo "msvc=amd64_x86" >> $GITHUB_OUTPUT - echo "cmake=-AWin32" >> $GITHUB_OUTPUT - elif [ "${{ matrix.arch }}" == "aarch64" ]; then - echo "msvc=amd64_arm64" >> $GITHUB_OUTPUT - echo "cmake=-AARM64" >> $GITHUB_OUTPUT - fi - elif [ "${{matrix.generator}}" == "ninja" ]; then - # We don't do cross-compiling builds with Ninja - # Todo: Why not (cross-compile)? - echo "msvc=amd64" >> $GITHUB_OUTPUT - fi - elif [ "${{ matrix.os }}" == "ubuntu-latest" ]; then - echo "cmake=-DRust_CARGO_TARGET=${{matrix.arch}}-${{steps.determine_rust_os.outputs.os}}-${{matrix.abi}}" >> $GITHUB_OUTPUT - fi - - name: Setup MSVC Development Environment - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: ${{ steps.arch_flags.outputs.msvc }} - if: ${{ 'msvc' == matrix.abi }} - - uses: actions/checkout@v2 - - name: Install CMake - uses: corrosion-rs/install-cmake@v1.1 - with: - cmake: ${{matrix.cmake}} - ninja: 1.10.0 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{matrix.rust}} - target: ${{matrix.arch}}-${{steps.determine_rust_os.outputs.os}}-${{matrix.abi}} - - name: Install Cross Compiler - run: | - sudo apt-get update - sudo apt-get install -y g++-$(echo "${{matrix.arch}}" | tr _ -)-linux-gnu - if: ${{ 'ubuntu-latest' == matrix.os }} - - name: CMake Version - run: cmake --version - - name: Rust Version - run: rustc +${{matrix.rust}} --version - - name: Configure - run: > - cmake - "-S." - "-Bbuild" - "-DCORROSION_VERBOSE_OUTPUT=ON" - "${{steps.arch_flags.outputs.cmake}}" - "${{steps.pick_compiler.outputs.c_compiler}}" - "${{steps.pick_compiler.outputs.cxx_compiler}}" - "${{steps.pick_compiler.outputs.system_name}}" - "${{steps.pick_generator.outputs.generator}}" - "-DRust_TOOLCHAIN=${{matrix.rust}}" - - name: Run Tests - run: > - cd build - - ctest --verbose --build-config Debug - - install: - name: Test Corrosion as a Library - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - os: - - windows-2019 - - ubuntu-latest - - macos-12 - include: - - rust: 1.46.0 - - os: macos-12 - rust: 1.54.0 # On MacOS-12 linking fails before Rust 1.54 - steps: - - uses: actions/checkout@v2 - - name: Setup MSVC Development Environment - uses: ilammy/msvc-dev-cmd@v1 - if: runner.os == 'Windows' - - name: Install CMake - uses: corrosion-rs/install-cmake@v1.1 - with: - cmake: 3.18.0 - ninja: 1.10.0 - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{matrix.rust}} - default: true - - name: CMake Version - run: cmake --version - - name: Rust Version - run: rustc --version - - name: Test Corrosion as subdirectory - run: > - cmake - -S. - -Bbuild - -DCORROSION_VERBOSE_OUTPUT=ON - -DCORROSION_TESTS_INSTALL_CORROSION=OFF - - cd build - - ctest --output-on-failure -C Debug - - name: Test Corrosion as installed module - run: > - cmake -E remove_directory build - - cmake - -S. - -Bbuild - -DCORROSION_VERBOSE_OUTPUT=ON - -DCMAKE_BUILD_TYPE=Release - -DCORROSION_TESTS_INSTALL_CORROSION=ON - - cd build - - ctest --output-on-failure -C Release diff --git a/connectors/corrosion/.gitignore b/connectors/corrosion/.gitignore deleted file mode 100644 index c7125b0a..00000000 --- a/connectors/corrosion/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ - -**/target/ -**/*.rs.bk -build*/ -install*/ -.vscode -.idea -cmake-build-* -test/test_header.cmake diff --git a/connectors/corrosion/CMakeLists.txt b/connectors/corrosion/CMakeLists.txt deleted file mode 100644 index e2569e04..00000000 --- a/connectors/corrosion/CMakeLists.txt +++ /dev/null @@ -1,141 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(Corrosion - VERSION 0.3.5 - LANGUAGES NONE - HOMEPAGE_URL "https://corrosion-rs.github.io/corrosion/" -) - -# Default behavior: -# - If the project is being used as a subdirectory, then don't build tests and -# don't enable any languages. -# - If this is a top level project, then build tests and enable the C++ compiler -if (NOT CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) - set(_CORROSION_TOP_LEVEL OFF) -else() - set(_CORROSION_TOP_LEVEL ON) -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" - ${_CORROSION_TOP_LEVEL} -) - -set( - CORROSION_GENERATOR_EXECUTABLE CACHE STRING - "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) -# If corrosion is used as a subdirectory, the CMake version is recent enough and the option is not -# explicitly disabled, then we do not need to build the Rust based parser and use the CMake based -# parser instead. -elseif((NOT _CORROSION_TOP_LEVEL) - AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.19.0 - AND NOT CORROSION_NATIVE_TOOLING - ) - set(CORROSION_INSTALL_EXECUTABLE_DEFAULT OFF) -else() - set(CORROSION_INSTALL_EXECUTABLE_DEFAULT ON) -endif() - -option( - CORROSION_INSTALL_EXECUTABLE - "Controls whether corrosion-generator is installed with the package" - ${CORROSION_INSTALL_EXECUTABLE_DEFAULT} -) -mark_as_advanced(CORROSION_INSTALL_EXECUTABLE) - -if (_CORROSION_TOP_LEVEL) - # TODO: If we don't have a language enabled, corrosion_import_crate will - # attempt to enable a C compiler. Ideally, we could delay this somehow until - # after we've set link libraries. - enable_language(CXX) -endif() - -# This little bit self-hosts the Corrosion toolchain to build the generator -# tool. -# -# It is strongly encouraged to install Corrosion separately and use -# `find_package(Corrosion REQUIRED)` instead if that works with your workflow. -list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -include(Corrosion) - -# Testing -if (CORROSION_BUILD_TESTS) - include(CTest) - add_subdirectory(test) -endif() - -# If Corrosion is a subdirectory, do not enable its install code -if (NOT _CORROSION_TOP_LEVEL) - return() -endif() - -# Installation - -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}" - ) -else() - message(DEBUG "Not installing corrosion-generator since " - "`CORROSION_INSTALL_EXECUTABLE` is set to ${CORROSION_INSTALL_EXECUTABLE}" - ) -endif() - -# Generate the Config file -include(CMakePackageConfigHelpers) - -configure_package_config_file( - cmake/CorrosionConfig.cmake.in CorrosionConfig.cmake - INSTALL_DESTINATION - "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/Corrosion" -) - -write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfigVersion.cmake" - VERSION ${PROJECT_VERSION} - COMPATIBILITY - SameMinorVersion # TODO: Should be SameMajorVersion when 1.0 is released - ARCH_INDEPENDENT -) - -install( - FILES - "${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfig.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/CorrosionConfigVersion.cmake" - DESTINATION - "${CMAKE_INSTALL_FULL_LIBDIR}/cmake/Corrosion" -) - -# These CMake scripts are needed both for the install and as a subdirectory -install( - FILES - cmake/Corrosion.cmake - cmake/CorrosionGenerator.cmake - cmake/FindRust.cmake - DESTINATION - "${CMAKE_INSTALL_FULL_DATADIR}/cmake" -) diff --git a/connectors/corrosion/LICENSE b/connectors/corrosion/LICENSE deleted file mode 100644 index 5e30d776..00000000 --- a/connectors/corrosion/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2018 Andrew Gaspar - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/connectors/corrosion/README.md b/connectors/corrosion/README.md deleted file mode 100644 index 7c8fc6b2..00000000 --- a/connectors/corrosion/README.md +++ /dev/null @@ -1,432 +0,0 @@ -# Corrosion -[![Build Status](https://github.com/corrosion-rs/corrosion/actions/workflows/test.yaml/badge.svg)](https://github.com/corrosion-rs/corrosion/actions?query=branch%3Amaster) - -Corrosion, formerly known as cmake-cargo, is a tool for integrating Rust into an existing CMake -project. Corrosion is capable of importing executables, static libraries, and dynamic libraries -from a crate. - -## Features -- Automatic Import of Executable, Static, and Shared Libraries from Rust Crate -- Easy Installation of Rust Executables -- Trivially Link Rust Executables to C/C++ Libraries in Tree -- Multi-Config Generator Support -- Simple Cross-Compilation - -## Sample Usage -```cmake -cmake_minimum_required(VERSION 3.15) -project(MyCoolProject LANGUAGES CXX) - -find_package(Corrosion REQUIRED) - -corrosion_import_crate(MANIFEST_PATH rust-lib/Cargo.toml) - -add_executable(cpp-exe main.cpp) -target_link_libraries(cpp-exe PUBLIC rust-lib) -``` - -# Documentation - -## Table of Contents -- [Corrosion](#corrosion) - - [Features](#features) - - [Sample Usage](#sample-usage) -- [Documentation](#documentation) - - [Table of Contents](#table-of-contents) - - [Installation](#installation) - - [Package Manager](#package-manager) - - [CMake Install](#cmake-install) - - [FetchContent](#fetchcontent) - - [Subdirectory](#subdirectory) - - [Usage](#usage) - - [Corrosion Options](#corrosion-options) - - [Developer/Maintainer Options](#developermaintainer-options) - - [Information provided by Corrosion](#information-provided-by-corrosion) - - [Adding crate targets](#adding-crate-targets) - - [Per Target options](#per-target-options) - - [Selecting a custom cargo profile](#selecting-a-custom-cargo-profile) - - [Importing C-Style Libraries Written in Rust](#importing-c-style-libraries-written-in-rust) - - [Generate Bindings to Rust Library Automatically](#generate-bindings-to-rust-library-automatically) - - [Importing Libraries Written in C and C++ Into Rust](#importing-libraries-written-in-c-and-c-into-rust) - - [Cross Compiling](#cross-compiling) - - [Windows-to-Windows](#windows-to-windows) - - [Linux-to-Linux](#linux-to-linux) - - [Android](#android) - -## Installation -There are two fundamental installation methods that are supported by Corrosion - installation as a -CMake package or using it as a subdirectory in an existing CMake project. For CMake versions below -3.19 Corrosion strongly recommends installing the package, either via a package manager or manually -using CMake's installation facilities. - -Installation will pre-build all of Corrosion's native tooling (required only for CMake versions -below 3.19). -Using Corrosion as a subdirectory with CMake versions before 3.19 will result in the native -tooling for Corrosion to be re-built every time you configure a new build directory, which could -be a non-trivial cost for some projects. It also may result in issues with large, complex projects -with many git submodules that each individually may use Corrosion. This can unnecessarily exacerbate -diamond dependency problems that wouldn't otherwise occur using an externally installed Corrosion. -On CMake >= 3.19 installing Corrosion does not offer any advantages, unless the native -tooling option is explicitly enabled. - -### Package Manager - -Coming soon... - -### CMake Install - -First, download and install Corrosion: -```bash -git clone https://github.com/corrosion-rs/corrosion.git -# Optionally, specify -DCMAKE_INSTALL_PREFIX=. You can install Corrosion anyway -cmake -Scorrosion -Bbuild -DCMAKE_BUILD_TYPE=Release -cmake --build build --config Release -# This next step may require sudo or admin privileges if you're installing to a system location, -# which is the default. -cmake --install build --config Release -``` - -You'll want to ensure that the install directory is available in your `PATH` or `CMAKE_PREFIX_PATH` -environment variable. This is likely to already be the case by default on a Unix system, but on -Windows it will install to `C:\Program Files (x86)\Corrosion` by default, which will not be in your -`PATH` or `CMAKE_PREFIX_PATH` by default. - -Once Corrosion is installed and you've ensured the package is available in your `PATH`, you -can use it from your own project like any other package from your CMakeLists.txt: -```cmake -find_package(Corrosion REQUIRED) -``` - -### FetchContent -If you are using CMake >= 3.19 or installation is difficult or not feasible in -your environment, you can use the -[FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) module to include -Corrosion. This will download Corrosion and use it as if it were a subdirectory at configure time. - -In your CMakeLists.txt: -```cmake -include(FetchContent) - -FetchContent_Declare( - Corrosion - GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git - GIT_TAG v0.3.5 # Optionally specify a commit hash, version tag or branch here -) -# Set any global configuration variables such as `Rust_TOOLCHAIN` before this line! -FetchContent_MakeAvailable(Corrosion) -``` - -### Subdirectory -Corrosion can also be used directly as a subdirectory. This solution may work well for small -projects, but it's discouraged for large projects with many dependencies, especially those which may -themselves use Corrosion. Either copy the Corrosion library into your source tree, being sure to -preserve the `LICENSE` file, or add this repository as a git submodule: -```bash -git submodule add https://github.com/corrosion-rs/corrosion.git -``` - -From there, using Corrosion is easy. In your CMakeLists.txt: -```cmake -add_subdirectory(path/to/corrosion) -``` - -## Usage -### Corrosion Options -All of the following variables are evaluated automatically in most cases. In typical cases you -shouldn't need to alter any of these. If you do want to specify them manually, make sure to set -them **before** `find_package(Corrosion REQUIRED)`. - -- `Rust_TOOLCHAIN:STRING` - Specify a named rustup toolchain to use. Changes to this variable -resets all other options. Default: If the first-found `rustc` is a `rustup` proxy, then the default -rustup toolchain (see `rustup show`) is used. Otherwise, the variable is unset by default. -- `Rust_ROOT:STRING` - CMake provided. Path to a Rust toolchain to use. This is an alternative if -you want to select a specific Rust toolchain, but it's not managed by rustup. Default: Nothing -- `Rust_COMPILER:STRING` - Path to an actual `rustc`. If set to a `rustup` proxy, it will be -replaced by a path to an actual `rustc`. Default: The `rustc` in the first-found toolchain, either -from `rustup`, or from a toolchain available in the user's `PATH`. -- `Rust_CARGO:STRING` - Path to an actual `cargo`. Default: the `cargo` installed next to -`${Rust_COMPILER}`. -- `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 - -For your convenience, Corrosion sets a number of variables which contain information about the version of the rust -toolchain. You can use the CMake version comparison operators -(e.g. [`VERSION_GREATER_EQUAL`](https://cmake.org/cmake/help/latest/command/if.html#version-comparisons)) on the main -variable (e.g. `if(Rust_VERSION VERSION_GREATER_EQUAL "1.57.0")`), or you can inspect the major, minor and patch -versions individually. -- `Rust_VERSION<_MAJOR|_MINOR|_PATCH>` - The version of rustc. -- `Rust_CARGO_VERSION<_MAJOR|_MINOR|_PATCH>` - The cargo version. -- `Rust_LLVM_VERSION<_MAJOR|_MINOR|_PATCH>` - The LLVM version used by rustc. -- `Rust_IS_NIGHTLY` - 1 if a nightly toolchain is used, otherwise 0. Useful for selecting an unstable feature for a - crate, that is only available on nightly toolchains. - -### Adding crate targets - -In order to integrate a Rust crate into CMake, you first need to import a crate or Workspace: -```cmake -corrosion_import_crate(MANIFEST_PATH - # Equivalent to --all-features passed to cargo build - [ALL_FEATURES] - # Equivalent to --no-default-features passed to cargo build - [NO_DEFAULT_FEATURES] - # Disable linking of standard libraries (required for no_std crates). - [NO_STD] - # Will let Rust/Cargo determine which linker to use instead of corrosion (when linking is invoked by Rust) (Ignored with CMake < 3.19) - [NO_LINKER_OVERRIDE] - # Specify cargo build profile (e.g. release or a custom profile) - [PROFILE ] - # Retrieve the list of imported crates in the current scope - [IMPORTED_CRATES ] - # Build only the specified crate types (Ignored with CMake < 3.19) - [CRATE_TYPES ... ] - # Only import the specified crates from a workspace - [CRATES ... ] - # Enable the specified features - [FEATURES ... ] - # Pass additional arguments to `cargo build` - [FLAGS ... ] -) -``` - -This will add a cmake target for each imported crate. Many of the options can also be set per -target, see [Per Target options](#per-target-options) for details. - -### Per Target options - -Some configuration options can be specified individually for each target. You can set them via the -`corrosion_set_xxx()` functions specified below: - -- `corrosion_set_env_vars( [... ])`: Define environment variables - that should be set during the invocation of `cargo build` for the specified target. Please note that - the environment variable will only be set for direct builds of the target via cmake, and not for any - build where cargo built the crate in question as a dependency for another target. - The environment variables may contain generator expressions. -- `corrosion_add_target_rustflags( [... ])`: When building the target, - the `RUSTFLAGS` environment variable will contain the flags added via this function. Please note that any - dependencies (built by cargo) will also see these flags. In the future corrosion may offer a second function - to allow specifying flags only for the target in question, utilizing `cargo rustc` instead of `cargo build`. -- `corrosion_add_target_local_rustflags(target_name rustc_flag [more_flags ...])`: Support setting - rustflags for only the main target (crate ) and none of it's dependencies. - This is useful in cases where you only need rustflags on the main-crate, but need to set different - flags for different targets. Without "local" Rustflags this would require rebuilds of the - dependencies when switching targets. -- `corrosion_set_hostbuild()`: The target should be compiled for the Host target and ignore any - cross-compile configuration. -- `corrosion_set_features( [ALL_FEATURES ] [NO_DEFAULT_FEATURES] [FEATURES ... ])`: - For a given target, enable specific features via `FEATURES`, toggle `ALL_FEATURES` on or off or disable all features - via `NO_DEFAULT_FEATURES`. For more information on features, please see also the - [cargo reference](https://doc.rust-lang.org/cargo/reference/features.html). -- `corrosion_set_cargo_flags( ...])`: - For a given target, add options and flags at the end of `cargo build` invocation. This will be appended after any - arguments passed through the `FLAGS` during the crate import. -- `corrosion_set_linker(target_name linker)`: Use `linker` to link the target. - Please note that this only has an effect for targets where the final linker invocation is done - by cargo, i.e. targets where foreign code is linked into rust code and not the other way around. - Please also note that if you are cross-compiling and specify a linker such as `clang`, you are - responsible for also adding a rustflag which adds the necessary `--target=` argument for the - linker. - -### Selecting a custom cargo profile - -[Rust 1.57](https://blog.rust-lang.org/2021/12/02/Rust-1.57.0.html) stabilized the support for custom -[profiles](https://doc.rust-lang.org/cargo/reference/profiles.html). If you are using a sufficiently new rust toolchain, -you may select a custom profile by adding the optional argument `PROFILE ` to -`corrosion_import_crate()`. If you do not specify a profile, or you use an older toolchain, corrosion will select -the standard `dev` profile if the CMake config is either `Debug` or unspecified. In all other cases the `release` -profile is chosen for cargo. - -### Importing C-Style Libraries Written in Rust -Corrosion makes it completely trivial to import a crate into an existing CMake project. Consider -a project called [rust2cpp](test/rust2cpp/rust2cpp) with the following file structure: -``` -rust2cpp/ - rust/ - src/ - lib.rs - Cargo.lock - Cargo.toml - CMakeLists.txt - main.cpp -``` - -This project defines a simple Rust lib crate, like so, in [`rust2cpp/rust/Cargo.toml`](test/rust2cpp/rust2cpp/rust/Cargo.toml): -```toml -[package] -name = "rust-lib" -version = "0.1.0" -authors = ["Andrew Gaspar "] -license = "MIT" -edition = "2018" - -[dependencies] - -[lib] -crate-type=["staticlib"] -``` - -In addition to `"staticlib"`, you can also use `"cdylib"`. In fact, you can define both with a -single crate and switch between which is used using the standard -[`BUILD_SHARED_LIBS`](https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html) variable. - -This crate defines a simple crate called `rust-lib`. Importing this crate into your -[CMakeLists.txt](test/rust2cpp/CMakeLists.txt) is trivial: -```cmake -# Note: you must have already included Corrosion for `corrosion_import_crate` to be available. See # the `Installation` section above. - -corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml) -``` - -Now that you've imported the crate into CMake, all of the executables, static libraries, and dynamic -libraries defined in the Rust can be directly referenced. So, merely define your C++ executable as -normal in CMake and add your crate's library using target_link_libraries: -```cmake -add_executable(cpp-exe main.cpp) -target_link_libraries(cpp-exe PUBLIC rust-lib) -``` - -That's it! You're now linking your Rust library to your C++ library. - -#### Generate Bindings to Rust Library Automatically - -Currently, you must manually declare bindings in your C or C++ program to the exported routines and -types in your Rust project. You can see boths sides of this in -[the Rust code](test/rust2cpp/rust2cpp/rust/src/lib.rs) and in [the C++ code](test/rust2cpp/rust2cpp/main.cpp). - -Integration with [cbindgen](https://github.com/eqrion/cbindgen) is -planned for the future. - -### Importing Libraries Written in C and C++ Into Rust - -The rust targets can be imported with `corrosion_import_crate()` into CMake. -For targets where the linker should be invoked by Rust corrosion provides -`corrosion_link_libraries()` to link your C/C++ libraries with the Rust target. -For additional linker flags you may use `corrosion_add_target_local_rustflags()` -and pass linker arguments via the `-Clink-args` flag to rustc. These flags will -only be passed to the final rustc invocation and not affect any rust dependencies. - -C bindings can be generated via [bindgen](https://github.com/rust-lang/rust-bindgen). -Corrosion does not offer any direct integration yet, but you can either generate the -bindings in the build-script of your crate, or generate the bindings as a CMake build step -(e.g. a custom target) and add a dependency from `cargo-prebuild_` to your -custom target for generating the bindings. - -Example: - -```cmake -# Import your Rust targets -corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml) -# Link C/C++ libraries with your Rust target -corrosion_link_libraries(target_name c_library) -# Optionally explicitly define which linker to use. -corrosion_set_linker(target_name your_custom_linker) -# Optionally set linker arguments -corrosion_add_target_local_rustflags(target_name "-Clink-args=") -# Optionally tell CMake that the rust crate depends on another target (e.g. a code generator) -add_dependencies(cargo-prebuild_ custom_bindings_target) -``` - -### Cross Compiling -Corrosion attempts to support cross-compiling as generally as possible, though not all -configurations are tested. Cross-compiling is explicitly supported in the following scenarios. - -In all cases, you will need to install the standard library for the Rust target triple. When using -Rustup, you can use it to install the target standard library: - -```bash -rustup target add -``` - -If the target triple is automatically derived, Corrosion will print the target during configuration. -For example: - -``` --- Rust Target: aarch64-linux-android -``` - -#### Windows-to-Windows -Corrosion supports cross-compiling between arbitrary Windows architectures using the Visual Studio -Generator. For example, to cross-compile for ARM64 from any platform, simply set the `-A` -architecture flag: - -```bash -cmake -S. -Bbuild-arm64 -A ARM64 -cmake --build build-arm64 -``` - -Please note that for projects containing a build-script at least Rust 1.54 is required due to a bug -in previous cargo versions, which causes the build-script to incorrectly be built for the target -platform. - -#### Linux-to-Linux -In order to cross-compile on Linux, you will need to install a cross-compiler. For example, on -Ubuntu, to cross compile for 64-bit Little-Endian PowerPC Little-Endian, install -`g++-powerpc64le-linux-gnu` from apt-get: - -```bash -sudo apt install g++-powerpc64le-linux-gnu -``` - -Currently, Corrosion does not automatically determine the target triple while cross-compiling on -Linux, so you'll need to specify a matching `Rust_CARGO_TARGET`. - -```bash -cmake -S. -Bbuild-ppc64le -DRust_CARGO_TARGET=powerpc64le-unknown-linux-gnu -DCMAKE_CXX_COMPILER=powerpc64le-linux-gnu-g++ -cmake --build build-ppc64le -``` - -#### Android - -Cross-compiling for Android is supported on all platforms with the Makefile and Ninja generators, -and the Rust target triple will automatically be selected. The CMake -[cross-compiling instructions for Android](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-android) -apply here. For example, to build for ARM64: - -```bash -cmake -S. -Bbuild-android-arm64 -GNinja -DCMAKE_SYSTEM_NAME=Android \ - -DCMAKE_ANDROID_NDK=/path/to/android-ndk-rxxd -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -``` - -**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, -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). - -## Limitations - -### CMake `OUTPUT_DIRECTORY` target properties and `IMPORTED_LOCATION` - -Corrosion respects the following `OUTPUT_DIRECTORY` target properties on CMake >= 3.19: -- [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) -- [PDB_OUTPUT_DIRECTORY](https://cmake.org/cmake/help/latest/prop_tgt/PDB_OUTPUT_DIRECTORY.html) - -Due to limitations in CMake these target properties are evaluated in a deferred manner, to -support the user setting the target properties after the call to `corrosion_import_crate()`. -This has the side effect that `IMPORTED_LOCATION` will be set late, and users should not -use `get_property` to read `IMPORTED_LOCATION` at configure time. Instead, generator expressions -should be used to get the location of the target artifact. -If `IMPORTED_LOCATION` is needed at configure time users may use `cmake_language(DEFER CALL ...)` to defer -evaluation to after the `IMPORTED_LOCATION` property is set. diff --git a/connectors/corrosion/RELEASES.md b/connectors/corrosion/RELEASES.md deleted file mode 100644 index 71ef871a..00000000 --- a/connectors/corrosion/RELEASES.md +++ /dev/null @@ -1,248 +0,0 @@ -# 0.3.5 (2023-03-19) - -- Fix building the Legacy Generator on Rust toolchains < 1.56 ([#365]) - -[#365]: https://github.com/corrosion-rs/corrosion/pull/365 - -# 0.3.4 (2023-03-02) - -## Fixes - -- Fix hostbuild (when CMake/Cargo is configured for cross-compiling) if clang is used ([#338]). - -## Other - -- Pass `--no-deps` to cargo metadata ([#334]). -- Bump the legacy generator dependencies - -[#334]: https://github.com/corrosion-rs/corrosion/pull/334 -[#338]: https://github.com/corrosion-rs/corrosion/pull/338 - -# 0.3.3 (2023-02-17) - -## New features (Only available on CMake >= 3.19) - -- 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)). - -## Fixes - -- Fix imported location target property when the rust target name contains dashes - and a custom OUTPUT_DIRECTORY was specified by the user ([#322](https://github.com/corrosion-rs/corrosion/pull/322)). -- Fix building for custom rust target-triples ([#316](https://github.com/corrosion-rs/corrosion/pull/316)) - -# 0.3.2 (2023-01-11) - -## New features (Only available on CMake >= 3.19) - -- Add new `CRATE_TYPES` flag to `corrosion_import_crate()` to restrict which - crate types should be imported ([#269](https://github.com/corrosion-rs/corrosion/pull/269)). -- Add `NO_LINKER_OVERRIDE` flag to let Rust choose the default linker for the target - instead of what Corrosion thinks is the appropriate linker driver ([#272](https://github.com/corrosion-rs/corrosion/pull/272)). - -## Fixes - -- Fix clean target when cross-compiling ([#291](https://github.com/corrosion-rs/corrosion/pull/291)). -- Don't set the linker for Rust static libraries ([#275](https://github.com/corrosion-rs/corrosion/pull/275)). -- Minor fixes in FindRust [#297](https://github.com/corrosion-rs/corrosion/pull/297): - - fix a logic error in the version detection - - fix a logic error in `QUIET` mode when rustup is not found. - -# 0.3.1 (2022-12-13) - -### Fixes - -- Fix a regression in detecting the MSVC abi ([#256]) -- Fix an issue on macOS 13 which affected rust crates compiling C++ code in build scripts ([#254]). -- Fix corrosion not respecting `CMAKE__OUTPUT_DIRECTORY` values ([#268]). -- Don't override rusts linker choice for the msvc abi (previously this was only skipped for msvc generators) ([#271]) - -[#254]: https://github.com/corrosion-rs/corrosion/pull/254 -[#256]: https://github.com/corrosion-rs/corrosion/pull/256 -[#268]: https://github.com/corrosion-rs/corrosion/pull/268 -[#271]: https://github.com/corrosion-rs/corrosion/pull/271 - -# 0.3.0 (2022-10-31) - -## Breaking - -- The minimum supported rust version (MSRV) was increased to 1.46, due to a cargo issue that recently - surfaced on CI when using crates.io. On MacOS 12 and Windows-2022 at least Rust 1.54 is required. -- MacOS 10 and 11 are no longer officially supported and untested in CI. -- The minimum required CMake version is now 3.15. -- Adding a `PRE_BUILD` custom command on a `cargo-build_` CMake target will no - longer work as expected. To support executing user defined commands before cargo build is - invoked users should use the newly added targets `cargo-prebuild` (before all cargo build invocations) - or `cargo-prebuild_` as a dependency target. - Example: `add_dependencies(cargo-prebuild code_generator_target)` - -### Breaking: Removed previously deprecated functionality -- Removed `add_crate()` function. Use `corrosio_import_crate()` instead. -- Removed `cargo_link_libraries()` function. Use `corrosion_link_libraries()` instead. -- Removed experimental CMake option `CORROSION_EXPERIMENTAL_PARSER`. - The corresponding stable option is `CORROSION_NATIVE_TOOLING` albeit with inverted semantics. -- Previously Corrosion would set the `HOST_CC` and `HOST_CXX` environment variables when invoking - cargo build, if the environment variables `CC` and `CXX` outside of CMake where set. - However this did not work as expected in all cases and sometimes the `HOST_CC` variable would be set - to a cross-compiler for unknown reasons. For this reason `HOST_CC` and `HOST_CXX` are not set by - corrosion anymore, but users can still set them manually if required via `corrosion_set_env_vars()`. -- The `CARGO_RUST_FLAGS` family of cache variables were removed. Corrosion does not internally use them - anymore. - -## Potentially breaking - -- The working directory when invoking `cargo build` was changed to the directory of the Manifest - file. This now allows cargo to pick up `.cargo/config.toml` files located in the source tree. - ([205](https://github.com/corrosion-rs/corrosion/pull/205)) -- Corrosion internally invokes `cargo build`. When passing arguments to `cargo build`, Corrosion - now uses the CMake `VERBATIM` option. In rare cases this may require you to change how you quote - parameters passed to corrosion (e.g. via `corrosion_add_target_rustflags()`). - For example setting a `cfg` option previously required double escaping the rustflag like this - `"--cfg=something=\\\"value\\\""`, but now it can be passed to corrosion without any escapes: - `--cfg=something="value"`. -- Corrosion now respects the CMake `OUTPUT_DIRECTORY` target properties. More details in the "New features" section. - -## New features - -- Support setting rustflags for only the main target and none of its dependencies ([215](https://github.com/corrosion-rs/corrosion/pull/215)). - A new function `corrosion_add_target_local_rustflags(target_name rustc_flag [more_flags ...])` - is added for this purpose. - This is useful in cases where you only need rustflags on the main-crate, but need to set different - flags for different targets. Without "local" Rustflags this would require rebuilds of the - dependencies when switching targets. -- Support explicitly selecting a linker ([208](https://github.com/corrosion-rs/corrosion/pull/208)). - The linker can be selected via `corrosion_set_linker(target_name linker)`. - Please note that this only has an effect for targets, where the final linker invocation is done - by cargo, i.e. targets where foreign code is linked into rust code and not the other way around. -- Corrosion now respects the CMake `OUTPUT_DIRECTORY` target properties and copies build artifacts to the expected - locations ([217](https://github.com/corrosion-rs/corrosion/pull/217)), if the properties are set. - This feature requires at least CMake 3.19 and is enabled by default if supported. Please note that the `OUTPUT_NAME` - target properties are currently not supported. - Specifically, the following target properties are now respected: - - [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) - - [PDB_OUTPUT_DIRECTORY](https://cmake.org/cmake/help/latest/prop_tgt/PDB_OUTPUT_DIRECTORY.html) -- Corrosion now supports packages with potentially multiple binaries (bins) and a library (lib) at the - same time. The only requirement is that the names of all `bin`s and `lib`s in the whole project must be unique. - Users can set the names in the `Cargo.toml` by adding `name = ` in the `[[bin]]` and `[lib]` tables. -- FindRust now has improved support for the `VERSION` option of `find_package` and will now attempt to find a matching - toolchain version. Previously it was only checked if the default toolchain matched to required version. -- For rustup managed toolchains a CMake error is issued with a helpful message if the required target for - the selected toolchain is not installed. - -## Fixes - -- Fix a CMake developer Warning when a Multi-Config Generator and Rust executable targets - ([#213](https://github.com/corrosion-rs/corrosion/pull/213)). -- FindRust now respects the `QUIET` option to `find_package()` in most cases. - -## Deprecation notice - -- Support for the MSVC Generators with CMake toolchains before 3.20 is deprecated and will be removed in the next - release (v0.4). All other Multi-config Generators already require CMake 3.20. - -## Internal Changes - -- The CMake Generator written in Rust and `CorrosionGenerator.cmake` which are responsible for parsing - `cargo metadata` output to create corresponding CMake targets for all Rust targets now share most code. - This greatly simplified the CMake generator written in Rust and makes it much easier maintaining and adding - new features regardless of how `cargo metadata` is parsed. - -# 0.2.2 (2022-09-01) - -## Fixes - -- Do not use C++17 in the tests (makes tests work with older C++ compilers) ([184](https://github.com/corrosion-rs/corrosion/pull/184)) -- Fix finding cargo on NixOS ([192](https://github.com/corrosion-rs/corrosion/pull/192)) -- Fix issue with Rustflags test when using a Build type other than Debug and Release ([203](https://github.com/corrosion-rs/corrosion/pull/203)). - -# 0.2.1 (2022-05-07) - -## Fixes - -- Fix missing variables provided by corrosion, when corrosion is used as a subdirectory ([181](https://github.com/corrosion-rs/corrosion/pull/181)): - Public [Variables](https://github.com/corrosion-rs/corrosion#information-provided-by-corrosion) set - by Corrosion were not visible when using Corrosion as a subdirectory, due to the wrong scope of - the variables. This was fixed by promoting the respective variables to Cache variables. - -# 0.2.0 (2022-05-05) - -## Breaking changes - -- Removed the integrator build script ([#156](https://github.com/corrosion-rs/corrosion/pull/156)). - The build script provided by corrosion (for rust code that links in foreign code) is no longer necessary, - so users can just remove the dependency. - -## Deprecations - -- Direct usage of the following target properties has been deprecated. The names of the custom properties are - no longer considered part of the public API and may change in the future. Instead, please use the functions - provided by corrosion. Internally different property names are used depending on the CMake version. - - `CORROSION_FEATURES`, `CORROSION_ALL_FEATURES`, `CORROSION_NO_DEFAULT_FEATURES`. Instead please use - `corrosion_set_features()`. See the updated Readme for details. - - `CORROSION_ENVIRONMENT_VARIABLES`. Please use `corrosion_set_env_vars()` instead. - - `CORROSION_USE_HOST_BUILD`. Please use `corrosion_set_hostbuild()` instead. -- The Minimum CMake version will likely be increased for the next major release. At the very least we want to drop - support for CMake 3.12, but requiring CMake 3.16 or even 3.18 is also on the table. If you are using a CMake version - that would be no longer supported by corrosion, please comment on issue - [#168](https://github.com/corrosion-rs/corrosion/issues/168), so that we can gauge the number of affected users. - -## New features - -- Add `NO_STD` option to `corrosion_import_crate` ([#154](https://github.com/corrosion-rs/corrosion/pull/154)). -- Remove the requirement of building the Rust based generator crate for CMake >= 3.19. This makes using corrosion as - a subdirectory as fast as the installed version (since everything is done in CMake). - ([#131](https://github.com/corrosion-rs/corrosion/pull/131), [#161](https://github.com/corrosion-rs/corrosion/pull/161)) - If you do choose to install Corrosion, then by default the old Generator is still compiled and installed, so you can - fall back to using it in case you use multiple cmake versions on the same machine for different projects. - -## Fixes - -- Fix Corrosion on MacOS 11 and 12 ([#167](https://github.com/corrosion-rs/corrosion/pull/167) and - [#164](https://github.com/corrosion-rs/corrosion/pull/164)). -- Improve robustness of parsing the LLVM version (exported in `Rust_LLVM_VERSION`). It now also works for - Rust versions, where the LLVM version is reported as `MAJOR.MINOR`. ([#148](https://github.com/corrosion-rs/corrosion/pull/148)) -- Fix a bug which occurred when Corrosion was added multiple times via `add_subdirectory()` - ([#143](https://github.com/corrosion-rs/corrosion/pull/143)). -- Set `CC_` and `CXX_` environment variables for the invocation of - `cargo build` to the compilers selected by CMake (if any) - ([#138](https://github.com/corrosion-rs/corrosion/pull/138) and [#161](https://github.com/corrosion-rs/corrosion/pull/161)). - This should ensure that C dependencies built in cargo buildscripts via [cc-rs](https://github.com/alexcrichton/cc-rs) - use the same compiler as CMake built dependencies. Users can override the compiler by specifying the higher - priority environment variable variants with dashes instead of underscores (See cc-rs documentation for details). -- Fix Ninja-Multiconfig Generator support for CMake versions >= 3.20. Previous CMake versions are missing a feature, - which prevents us from supporting the Ninja-Multiconfig generator. ([#137](https://github.com/corrosion-rs/corrosion/pull/137)) - - -# 0.1.0 (2022-02-01) - -This is the first release of corrosion after it was moved to the new corrosion-rs organization. -Since there are no previous releases, this is not a complete changelog but only lists changes since -September 2021. - -## New features -- [Add --profile support for rust >= 1.57](https://github.com/corrosion-rs/corrosion/pull/130): - Allows users to specify a custom cargo profile with - `corrosion_import_crate(... PROFILE )`. -- [Add support for specifying per-target Rustflags](https://github.com/corrosion-rs/corrosion/pull/127): - Rustflags can be added via `corrosion_add_target_rustflags( [rustflags1...])` -- [Add `Rust_IS_NIGHTLY` and `Rust_LLVM_VERSION` variables](https://github.com/corrosion-rs/corrosion/pull/123): - This may be useful if you want to conditionally enabled features when using a nightly toolchain - or a specific LLVM Version. -- [Let `FindRust` fail gracefully if rustc is not found](https://github.com/corrosion-rs/corrosion/pull/111): - This allows using `FindRust` in a more general setting (without corrosion). -- [Add support for cargo feature selection](https://github.com/corrosion-rs/corrosion/pull/108): - See the [README](https://github.com/corrosion-rs/corrosion#cargo-feature-selection) for details on - how to select features. - - -## Fixes -- [Fix the cargo-clean target](https://github.com/corrosion-rs/corrosion/pull/129) -- [Fix #84: CorrosionConfig.cmake looks in wrong place for Corrosion::Generator when CMAKE_INSTALL_LIBEXEC is an absolute path](https://github.com/corrosion-rs/corrosion/pull/122/commits/6f29af3ac53917ca2e0638378371e715a18a532d) -- [Fix #116: (Option CORROSION_INSTALL_EXECUTABLE not working)](https://github.com/corrosion-rs/corrosion/commit/97d44018fac1b1a2a7c095288c628f5bbd9b3184) -- [Fix building on Windows with rust >= 1.57](https://github.com/corrosion-rs/corrosion/pull/120) - -## Known issues: -- Corrosion is currently not working on macos-11 and newer. See issue [#104](https://github.com/corrosion-rs/corrosion/issues/104). - Contributions are welcome. diff --git a/connectors/corrosion/cmake/Corrosion.cmake b/connectors/corrosion/cmake/Corrosion.cmake deleted file mode 100644 index 28d27376..00000000 --- a/connectors/corrosion/cmake/Corrosion.cmake +++ /dev/null @@ -1,1457 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -if (CMAKE_GENERATOR STREQUAL "Ninja Multi-Config" AND CMAKE_VERSION VERSION_LESS 3.20.0) - message(FATAL_ERROR "Corrosion requires at least CMake 3.20 with the \"Ninja Multi-Config\" " - "generator. Please use a different generator or update to cmake >= 3.20.") -elseif(CMAKE_VERSION VERSION_LESS 3.20.0 AND CMAKE_CONFIGURATION_TYPES) - message(DEPRECATION "Corrosion will require at least CMake 3.20 for use with all Multi-Config" - "Generators starting with Corrosion 0.4. Please consider upgrading your CMake version" - " or using a different Generator." - ) -endif() - -option(CORROSION_VERBOSE_OUTPUT "Enables verbose output from Corrosion and Cargo" OFF) - -set(CORROSION_NATIVE_TOOLING_DESCRIPTION - "Use native tooling - Required on CMake < 3.19 and available as a fallback option for recent versions" - ) - -set(CORROSION_RESPECT_OUTPUT_DIRECTORY_DESCRIPTION - "Respect the CMake target properties specifying the output directory of a target, such as - `RUNTIME_OUTPUT_DIRECTORY`. This requires CMake >= 3.19, otherwise this option is forced off." -) - -option( - CORROSION_NATIVE_TOOLING - "${CORROSION_NATIVE_TOOLING_DESCRIPTION}" - OFF -) - -option(CORROSION_RESPECT_OUTPUT_DIRECTORY - "${CORROSION_RESPECT_OUTPUT_DIRECTORY_DESCRIPTION}" - ON -) - -option( - CORROSION_NO_WARN_PARSE_TARGET_TRIPLE_FAILED - "Surpresses a warning if the parsing the target triple failed." - OFF -) - -# The native tooling is required on CMAke < 3.19 so we override whatever the user may have set. -if (CMAKE_VERSION VERSION_LESS 3.19.0) - set(CORROSION_NATIVE_TOOLING ON CACHE INTERNAL "${CORROSION_NATIVE_TOOLING_DESCRIPTION}" FORCE) - set(CORROSION_RESPECT_OUTPUT_DIRECTORY OFF CACHE INTERNAL - "${CORROSION_RESPECT_OUTPUT_DIRECTORY_DESCRIPTION}" FORCE - ) -endif() - -find_package(Rust REQUIRED) - -if(Rust_TOOLCHAIN_IS_RUSTUP_MANAGED) - execute_process(COMMAND rustup target list --toolchain "${Rust_TOOLCHAIN}" - OUTPUT_VARIABLE AVAILABLE_TARGETS_RAW - ) - string(REPLACE "\n" ";" AVAILABLE_TARGETS_RAW "${AVAILABLE_TARGETS_RAW}") - string(REPLACE " (installed)" "" "AVAILABLE_TARGETS" "${AVAILABLE_TARGETS_RAW}") - set(INSTALLED_TARGETS_RAW "${AVAILABLE_TARGETS_RAW}") - list(FILTER INSTALLED_TARGETS_RAW INCLUDE REGEX " \\(installed\\)") - string(REPLACE " (installed)" "" "INSTALLED_TARGETS" "${INSTALLED_TARGETS_RAW}") - list(TRANSFORM INSTALLED_TARGETS STRIP) - if("${Rust_CARGO_TARGET}" IN_LIST AVAILABLE_TARGETS) - message(DEBUG "Cargo target ${Rust_CARGO_TARGET} is an official target-triple") - message(DEBUG "Installed targets: ${INSTALLED_TARGETS}") - if(NOT ("${Rust_CARGO_TARGET}" IN_LIST INSTALLED_TARGETS)) - message(FATAL_ERROR "Target ${Rust_CARGO_TARGET} is not installed for toolchain ${Rust_TOOLCHAIN}.\n" - "Help: Run `rustup target add --toolchain ${Rust_TOOLCHAIN} ${Rust_CARGO_TARGET}` to install " - "the missing target." - ) - endif() - endif() - -endif() - -if(CMAKE_GENERATOR MATCHES "Visual Studio" - AND (NOT CMAKE_VS_PLATFORM_NAME STREQUAL CMAKE_VS_PLATFORM_NAME_DEFAULT) - AND Rust_VERSION VERSION_LESS "1.54") - message(FATAL_ERROR "Due to a cargo issue, cross-compiling with a Visual Studio generator and rust versions" - " before 1.54 is not supported. Rust build scripts would be linked with the cross-compiler linker, which" - " 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() - -get_property( - RUSTC_EXECUTABLE - TARGET Rust::Rustc PROPERTY IMPORTED_LOCATION -) - -get_property( - CARGO_EXECUTABLE - TARGET Rust::Cargo PROPERTY IMPORTED_LOCATION -) - -# Note: Legacy function, used when respecting the `XYZ_OUTPUT_DIRECTORY` target properties is not -# possible. -function(_corrosion_set_imported_location_legacy target_name base_property filename) - if(CMAKE_CONFIGURATION_TYPES AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.20.0) - foreach(config_type ${CMAKE_CONFIGURATION_TYPES}) - set(binary_root "${CMAKE_CURRENT_BINARY_DIR}/${config_type}") - string(TOUPPER "${config_type}" config_type_upper) - message(DEBUG "Setting ${base_property}_${config_type_upper} for target ${target_name}" - " to `${binary_root}/${filename}`.") - # For Multiconfig we want to specify the correct location for each configuration - set_property( - TARGET ${target_name} - PROPERTY "${base_property}_${config_type_upper}" - "${binary_root}/${filename}" - ) - endforeach() - else() - set(binary_root "${CMAKE_CURRENT_BINARY_DIR}") - endif() - - message(DEBUG "Setting ${base_property} for target ${target_name}" - " to `${binary_root}/${filename}`.") - - # IMPORTED_LOCATION must be set regardless of possible overrides. In the multiconfig case, - # the last configuration "wins". - set_property( - TARGET ${target_name} - PROPERTY "${base_property}" "${binary_root}/${filename}" - ) -endfunction() - -# Do not call this function directly! -# -# This function should be called deferred to evaluate target properties late in the configure stage. -# IMPORTED_LOCATION does not support Generator expressions, so we must evaluate the output -# directory target property value at configure time. This function must be deferred to the end of -# the configure stage, so we can be sure that the output directory is not modified afterwards. -function(_corrosion_set_imported_location_deferred target_name base_property output_directory_property filename) - # The output directory property is expected to be set on the exposed target (without postfix), - # but we need to set the imported location on the actual library target with postfix. - if("${target_name}" MATCHES "^(.+)-(static|shared)$") - set(output_dir_prop_target_name "${CMAKE_MATCH_1}") - else() - set(output_dir_prop_target_name "${target_name}") - endif() - - get_target_property(output_directory "${output_dir_prop_target_name}" "${output_directory_property}") - message(DEBUG "Output directory property (target ${output_dir_prop_target_name}): ${output_directory_property} dir: ${output_directory}") - - if(CMAKE_CONFIGURATION_TYPES AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.20.0) - foreach(config_type ${CMAKE_CONFIGURATION_TYPES}) - string(TOUPPER "${config_type}" config_type_upper) - get_target_property(output_dir_curr_config "${output_dir_prop_target_name}" - "${output_directory_property}_${config_type_upper}" - ) - if(output_dir_curr_config) - set(curr_out_dir "${output_dir_curr_config}") - elseif(output_directory) - set(curr_out_dir "${output_directory}") - else() - set(curr_out_dir "${CMAKE_CURRENT_BINARY_DIR}/${config_type}") - endif() - message(DEBUG "Setting ${base_property}_${config_type_upper} for target ${target_name}" - " to `${curr_out_dir}/${filename}`.") - # For Multiconfig we want to specify the correct location for each configuration - set_property( - TARGET ${target_name} - PROPERTY "${base_property}_${config_type_upper}" - "${curr_out_dir}/${filename}" - ) - set(base_output_directory "${curr_out_dir}") - endforeach() - elseif(CMAKE_CONFIGURATION_TYPES) - # Fallback path needed for MSVC + CMake < 3.20 - if(output_directory) - string(GENEX_STRIP "${output_directory}" stripped_output_dir) - if("${stripped_output_dir}" STREQUAL "${output_directory}") - # Output directory does not contain a genex and can be respected. - set(base_output_directory "${output_directory}") - else() - # Fallback to default directory if output_dir contains a genex. - set(base_output_directory "${CMAKE_CURRENT_BINARY_DIR}") - endif() - else() - # Fallback to default directory. - set(base_output_directory "${CMAKE_CURRENT_BINARY_DIR}") - endif() - else() - if(output_directory) - set(base_output_directory "${output_directory}") - else() - set(base_output_directory "${CMAKE_CURRENT_BINARY_DIR}") - endif() - endif() - - message(DEBUG "Setting ${base_property} for target ${target_name}" - " to `${base_output_directory}/${filename}`.") - - # IMPORTED_LOCATION must be set regardless of possible overrides. In the multiconfig case, - # the last configuration "wins" (IMPORTED_LOCATION is not documented to have Genex support). - set_property( - TARGET ${target_name} - PROPERTY "${base_property}" "${base_output_directory}/${filename}" - ) -endfunction() - -# Helper function to call _corrosion_set_imported_location_deferred while eagerly -# evaluating arguments. -# Refer to https://cmake.org/cmake/help/latest/command/cmake_language.html#deferred-call-examples -function(_corrosion_call_set_imported_location_deferred target_name base_property output_directory_property filename) - cmake_language(EVAL CODE " - cmake_language(DEFER - CALL - _corrosion_set_imported_location_deferred - [[${target_name}]] - [[${base_property}]] - [[${output_directory_property}]] - [[${filename}]] - ) - ") -endfunction() - -# Set the imported location of a Rust target. -# -# Rust targets are built via custom targets / custom commands. The actual artifacts are exposed -# to CMake as imported libraries / executables that depend on the cargo_build command. For CMake -# to find the built artifact we need to set the IMPORTED location to the actual location on disk. -# Corrosion tries to copy the artifacts built by cargo to standard locations. The IMPORTED_LOCATION -# is set to point to the copy, and not the original from the cargo build directory. -# -# Parameters: -# - target_name: Name of the Rust target -# - base_property: Name of the base property - i.e. `IMPORTED_LOCATION` or `IMPORTED_IMPLIB`. -# - output_directory_property: Target property name that determines the standard location for the -# artifact. -# - filename of the artifact. -function(_corrosion_set_imported_location target_name base_property output_directory_property filename) - if(CORROSION_RESPECT_OUTPUT_DIRECTORY) - _corrosion_call_set_imported_location_deferred("${target_name}" "${base_property}" "${output_directory_property}" "${filename}") - else() - _corrosion_set_imported_location_legacy("${target_name}" "${base_property}" "${filename}") - endif() -endfunction() - -function(_corrosion_copy_byproduct_legacy target_name cargo_build_dir file_names) - if(ARGN) - message(FATAL_ERROR "Unexpected additional arguments") - endif() - - if(CMAKE_CONFIGURATION_TYPES AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.20.0) - set(output_dir "${CMAKE_CURRENT_BINARY_DIR}/$") - else() - set(output_dir "${CMAKE_CURRENT_BINARY_DIR}") - endif() - - list(TRANSFORM file_names PREPEND "${cargo_build_dir}/" OUTPUT_VARIABLE src_file_names) - list(TRANSFORM file_names PREPEND "${output_dir}/" OUTPUT_VARIABLE dst_file_names) - message(DEBUG "Adding command to copy byproducts `${file_names}` to ${dst_file_names}") - add_custom_command(TARGET _cargo-build_${target_name} - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory "${output_dir}" - COMMAND - ${CMAKE_COMMAND} -E copy_if_different - # tested to work with both multiple files and paths with spaces - ${src_file_names} - "${output_dir}" - BYPRODUCTS ${dst_file_names} - COMMENT "Copying byproducts `${file_names}` to ${output_dir}" - VERBATIM - COMMAND_EXPAND_LISTS - ) -endfunction() - -function(_corrosion_copy_byproduct_deferred target_name output_dir_prop_name cargo_build_dir file_names) - if(ARGN) - message(FATAL_ERROR "Unexpected additional arguments") - endif() - get_target_property(output_dir ${target_name} "${output_dir_prop_name}") - - # A Genex expanding to the output directory depending on the configuration. - set(multiconfig_out_dir_genex "") - - foreach(config_type ${CMAKE_CONFIGURATION_TYPES}) - string(TOUPPER "${config_type}" config_type_upper) - get_target_property(output_dir_curr_config ${target_name} "${output_dir_prop_name}_${config_type_upper}") - - if(output_dir_curr_config) - set(curr_out_dir "${output_dir_curr_config}") - elseif(output_dir) - # Fallback to `output_dir` if specified - # Note: Multi-configuration generators append a per-configuration subdirectory to the - # specified directory unless a generator expression is used (from CMake documentation). - set(curr_out_dir "${output_dir}") - else() - # Fallback to default directory. - set(curr_out_dir "${CMAKE_CURRENT_BINARY_DIR}/${config_type}") - endif() - set(multiconfig_out_dir_genex "${multiconfig_out_dir_genex}$<$:${curr_out_dir}>") - endforeach() - - if(CMAKE_CONFIGURATION_TYPES AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.20.0) - set(output_dir "${multiconfig_out_dir_genex}") - elseif(CMAKE_CONFIGURATION_TYPES) - # Fallback support for MSVC with CMake < 3.20.0 (byproducts may not contain genexes) - if(output_dir) - string(GENEX_STRIP "${output_dir}" stripped_output_dir) - if(NOT ("${stripped_output_dir}" STREQUAL "${output_dir}")) - # Fallback to default directory if output_dir contains a genex. - set(output_dir "${CMAKE_CURRENT_BINARY_DIR}") - endif() - else() - # Fallback to default directory. - set(output_dir "${CMAKE_CURRENT_BINARY_DIR}") - endif() - else() - if(NOT output_dir) - # Fallback to default directory. - set(output_dir "${CMAKE_CURRENT_BINARY_DIR}") - endif() - endif() - - list(TRANSFORM file_names PREPEND "${cargo_build_dir}/" OUTPUT_VARIABLE src_file_names) - list(TRANSFORM file_names PREPEND "${output_dir}/" OUTPUT_VARIABLE dst_file_names) - message(DEBUG "Adding command to copy byproducts `${file_names}` to ${dst_file_names}") - add_custom_command(TARGET _cargo-build_${target_name} - POST_BUILD - # output_dir may contain a Generator expression. - COMMAND ${CMAKE_COMMAND} -E make_directory "${output_dir}" - COMMAND - ${CMAKE_COMMAND} -E copy_if_different - # tested to work with both multiple files and paths with spaces - ${src_file_names} - "${output_dir}" - BYPRODUCTS ${dst_file_names} - COMMENT "Copying byproducts `${file_names}` to ${output_dir}" - VERBATIM - COMMAND_EXPAND_LISTS - ) -endfunction() - -function(_corrosion_call_copy_byproduct_deferred target_name output_dir_prop_name cargo_build_dir file_names) - cmake_language(EVAL CODE " - cmake_language(DEFER - CALL - _corrosion_copy_byproduct_deferred - [[${target_name}]] - [[${output_dir_prop_name}]] - [[${cargo_build_dir}]] - [[${file_names}]] - ) - ") -endfunction() - -# Copy the artifacts generated by cargo to the appropriate destination. -# -# Parameters: -# - target_name: The name of the Rust target -# - output_dir_prop_name: The property name controlling the destination (e.g. -# `RUNTIME_OUTPUT_DIRECTORY`) -# - cargo_build_dir: the directory cargo build places it's output artifacts in. -# - filenames: the file names of any output artifacts as a list. -function(_corrosion_copy_byproducts target_name output_dir_prop_name cargo_build_dir filenames) - if(CORROSION_RESPECT_OUTPUT_DIRECTORY) - _corrosion_call_copy_byproduct_deferred("${target_name}" "${output_dir_prop_name}" "${cargo_build_dir}" "${filenames}") - else() - _corrosion_copy_byproduct_legacy("${target_name}" "${cargo_build_dir}" "${filenames}") - endif() -endfunction() - -function(_corrosion_strip_target_triple input_triple_or_path output_triple) - # If the target_triple is a path to a custom target specification file, then strip everything - # except the filename from `target_triple`. - get_filename_component(target_triple_ext "${input_triple_or_path}" EXT) - set(target_triple "${input_triple_or_path}") - if(target_triple_ext) - if(target_triple_ext STREQUAL ".json") - get_filename_component(target_triple "${input_triple_or_path}" NAME_WE) - endif() - endif() - set(${output_triple} "${target_triple}" PARENT_SCOPE) -endfunction() - -# The Rust target triple and C target may mismatch (slightly) in some rare usecases. -# So instead of relying on CMake to provide System information, we parse the Rust target triple, -# since that is relevant for determining which libraries the Rust code requires for linking. -function(_corrosion_parse_platform manifest rust_version target_triple) - _corrosion_strip_target_triple(${target_triple} target_triple) - - # The vendor part may be left out from the target triple, and since `env` is also optional, - # we determine if vendor is present by matching against a list of known vendors. - set(known_vendors "apple" - "esp" # riscv32imc-esp-espidf - "fortanix" - "kmc" - "pc" - "nintendo" - "nvidia" - "openwrt" - "unknown" - "uwp" # aarch64-uwp-windows-msvc - "wrs" # e.g. aarch64-wrs-vxworks - "sony" - "sun" - ) - # todo: allow users to add additional vendors to the list via a cmake variable. - list(JOIN known_vendors "|" known_vendors_joined) - # vendor is optional - We detect if vendor is present by matching against a known list of - # vendors. The next field is the OS, which we assume to always be present, while the last field - # is again optional and contains the environment. - string(REGEX MATCH - "^([a-z0-9_\.]+)-((${known_vendors_joined})-)?([a-z0-9_]+)(-([a-z0-9_]+))?$" - whole_match - "${target_triple}" - ) - if((NOT whole_match) AND (NOT CORROSION_NO_WARN_PARSE_TARGET_TRIPLE_FAILED)) - message(WARNING "Failed to parse target-triple `${target_triple}`." - "Corrosion attempts to link required C libraries depending on the OS " - "specified in the Rust target-triple for Linux, MacOS and windows.\n" - "Note: If you are targeting a different OS you can surpress this warning by" - " setting the CMake cache variable " - "`CORROSION_NO_WARN_PARSE_TARGET_TRIPLE_FAILED`." - "Please consider opening an issue on github if you encounter this warning." - ) - endif() - - set(target_arch "${CMAKE_MATCH_1}") - set(target_vendor "${CMAKE_MATCH_3}") - set(os "${CMAKE_MATCH_4}") - set(env "${CMAKE_MATCH_6}") - - message(DEBUG "Parsed Target triple: arch: ${target_arch}, vendor: ${target_vendor}, " - "OS: ${os}, env: ${env}") - - set(libs "") - - set(is_windows FALSE) - set(is_windows_msvc FALSE) - set(is_windows_gnu FALSE) - set(is_macos FALSE) - - if(os STREQUAL "windows") - set(is_windows TRUE) - - if(NOT COR_NO_STD) - list(APPEND libs "advapi32" "userenv" "ws2_32") - endif() - - if(env STREQUAL "msvc") - set(is_windows_msvc TRUE) - - if(NOT COR_NO_STD) - list(APPEND libs "$<$:msvcrtd>") - # CONFIG takes a comma seperated list starting with CMake 3.19, but we still need to - # support older CMake versions. - set(config_is_release "$,$,$>") - list(APPEND libs "$<${config_is_release}:msvcrt>") - endif() - elseif(env STREQUAL "gnu") - set(is_windows_gnu TRUE) - - if(NOT COR_NO_STD) - list(APPEND libs "gcc_eh" "pthread") - endif() - endif() - - if(NOT COR_NO_STD) - if(rust_version VERSION_LESS "1.33.0") - list(APPEND libs "shell32" "kernel32") - endif() - - if(rust_version VERSION_GREATER_EQUAL "1.57.0") - list(APPEND libs "bcrypt") - endif() - endif() - elseif(target_vendor STREQUAL "apple" AND os STREQUAL "darwin") - set(is_macos TRUE) - - if(NOT COR_NO_STD) - list(APPEND libs "System" "resolv" "c" "m") - endif() - elseif(os STREQUAL "linux") - if(NOT COR_NO_STD) - list(APPEND libs "dl" "rt" "pthread" "gcc_s" "c" "m" "util") - endif() - endif() - - set_source_files_properties( - ${manifest} - PROPERTIES - CORROSION_PLATFORM_LIBS "${libs}" - - CORROSION_PLATFORM_IS_WINDOWS "${is_windows}" - CORROSION_PLATFORM_IS_WINDOWS_MSVC "${is_windows_msvc}" - CORROSION_PLATFORM_IS_WINDOWS_GNU "${is_windows_gnu}" - CORROSION_PLATFORM_IS_MACOS "${is_macos}" - ) -endfunction() - -# Add targets for the static and/or shared libraries of the rust target. -# The generated byproduct names are returned via the `out_lib_byproducts` variable name. -function(_corrosion_add_library_target workspace_manifest_path target_name has_staticlib has_cdylib - out_archive_output_byproducts out_shared_lib_byproduct out_pdb_byproduct) - - if(NOT (has_staticlib OR has_cdylib)) - message(FATAL_ERROR "Unknown library type") - endif() - - get_source_file_property(is_windows ${workspace_manifest_path} CORROSION_PLATFORM_IS_WINDOWS) - get_source_file_property(is_windows_msvc ${workspace_manifest_path} CORROSION_PLATFORM_IS_WINDOWS_MSVC) - get_source_file_property(is_windows_gnu ${workspace_manifest_path} CORROSION_PLATFORM_IS_WINDOWS_GNU) - get_source_file_property(is_macos ${workspace_manifest_path} CORROSION_PLATFORM_IS_MACOS) - - # target file names - string(REPLACE "-" "_" lib_name "${target_name}") - - if(is_windows_msvc) - set(static_lib_name "${lib_name}.lib") - else() - set(static_lib_name "lib${lib_name}.a") - endif() - - if(is_windows) - set(dynamic_lib_name "${lib_name}.dll") - elseif(is_macos) - set(dynamic_lib_name "lib${lib_name}.dylib") - else() - set(dynamic_lib_name "lib${lib_name}.so") - endif() - - if(is_windows_msvc) - set(implib_name "${lib_name}.dll.lib") - elseif(is_windows_gnu) - set(implib_name "lib${lib_name}.dll.a") - elseif(is_windows) - message(FATAL_ERROR "Unknown windows environment - Can't determine implib name") - endif() - - - set(pdb_name "${lib_name}.pdb") - - set(archive_output_byproducts "") - if(has_staticlib) - list(APPEND archive_output_byproducts ${static_lib_name}) - endif() - - if(has_cdylib) - set(${out_shared_lib_byproduct} "${dynamic_lib_name}" PARENT_SCOPE) - if(is_windows) - list(APPEND archive_output_byproducts ${implib_name}) - endif() - if(is_windows_msvc) - set(${out_pdb_byproduct} "${pdb_name}" PARENT_SCOPE) - endif() - endif() - set(${out_archive_output_byproducts} "${archive_output_byproducts}" PARENT_SCOPE) - - if(has_staticlib) - add_library(${target_name}-static STATIC IMPORTED GLOBAL) - add_dependencies(${target_name}-static cargo-build_${target_name}) - - _corrosion_set_imported_location("${target_name}-static" "IMPORTED_LOCATION" - "ARCHIVE_OUTPUT_DIRECTORY" - "${static_lib_name}") - - get_source_file_property(libs ${workspace_manifest_path} CORROSION_PLATFORM_LIBS) - - if(libs) - set_property( - TARGET ${target_name}-static - PROPERTY INTERFACE_LINK_LIBRARIES ${libs} - ) - if(is_macos) - set_property(TARGET ${target_name}-static - PROPERTY INTERFACE_LINK_DIRECTORIES "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib" - ) - endif() - endif() - endif() - - if(has_cdylib) - add_library(${target_name}-shared SHARED IMPORTED GLOBAL) - add_dependencies(${target_name}-shared cargo-build_${target_name}) - - # Todo: (Not new issue): What about IMPORTED_SONAME and IMPORTED_NO_SYSTEM? - _corrosion_set_imported_location("${target_name}-shared" "IMPORTED_LOCATION" - "LIBRARY_OUTPUT_DIRECTORY" - "${dynamic_lib_name}" - ) - - if(is_windows) - _corrosion_set_imported_location("${target_name}-shared" "IMPORTED_IMPLIB" - "ARCHIVE_OUTPUT_DIRECTORY" - "${implib_name}" - ) - endif() - - if(is_macos) - set_property(TARGET ${target_name}-shared - PROPERTY INTERFACE_LINK_DIRECTORIES "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib" - ) - endif() - endif() - - add_library(${target_name} INTERFACE) - - if(has_cdylib AND has_staticlib) - if(BUILD_SHARED_LIBS) - target_link_libraries(${target_name} INTERFACE ${target_name}-shared) - else() - target_link_libraries(${target_name} INTERFACE ${target_name}-static) - endif() - elseif(has_cdylib) - target_link_libraries(${target_name} INTERFACE ${target_name}-shared) - else() - target_link_libraries(${target_name} INTERFACE ${target_name}-static) - endif() -endfunction() - -function(_corrosion_add_bin_target workspace_manifest_path bin_name out_bin_byproduct out_pdb_byproduct) - if(NOT bin_name) - message(FATAL_ERROR "No bin_name in _corrosion_add_bin_target for target ${target_name}") - endif() - - string(REPLACE "-" "_" bin_name_underscore "${bin_name}") - - set(pdb_name "${bin_name_underscore}.pdb") - - get_source_file_property(is_windows ${workspace_manifest_path} CORROSION_PLATFORM_IS_WINDOWS) - get_source_file_property(is_windows_msvc ${workspace_manifest_path} CORROSION_PLATFORM_IS_WINDOWS_MSVC) - get_source_file_property(is_macos ${workspace_manifest_path} CORROSION_PLATFORM_IS_MACOS) - - if(is_windows_msvc) - set(${out_pdb_byproduct} "${pdb_name}" PARENT_SCOPE) - endif() - - if(is_windows) - set(bin_filename "${bin_name}.exe") - else() - set(bin_filename "${bin_name}") - endif() - set(${out_bin_byproduct} "${bin_filename}" PARENT_SCOPE) - - - # Todo: This is compatible with the way corrosion previously exposed the bin name, - # but maybe we want to prefix the exposed name with the package name? - add_executable(${bin_name} IMPORTED GLOBAL) - add_dependencies(${bin_name} cargo-build_${bin_name}) - - if(is_macos) - set_property(TARGET ${bin_name} - PROPERTY INTERFACE_LINK_DIRECTORIES "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib" - ) - endif() - - _corrosion_set_imported_location("${bin_name}" "IMPORTED_LOCATION" - "RUNTIME_OUTPUT_DIRECTORY" - "${bin_filename}" - ) - -endfunction() - - -if (NOT CORROSION_NATIVE_TOOLING) - include(CorrosionGenerator) -endif() - -if (CORROSION_VERBOSE_OUTPUT) - set(_CORROSION_VERBOSE_OUTPUT_FLAG --verbose) -endif() - -if(CORROSION_NATIVE_TOOLING) - if (NOT TARGET Corrosion::Generator ) - set(_CORROSION_GENERATOR_EXE - ${CARGO_EXECUTABLE} run --quiet --manifest-path "${CMAKE_CURRENT_LIST_DIR}/../generator/Cargo.toml" --) - 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() - else() - get_property( - _CORROSION_GENERATOR_EXE - TARGET Corrosion::Generator PROPERTY IMPORTED_LOCATION - ) - endif() - - 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") -set(_CORROSION_RUSTC "${RUSTC_EXECUTABLE}" CACHE INTERNAL "Path to rustc used by corrosion") -set(_CORROSION_CARGO "${CARGO_EXECUTABLE}" CACHE INTERNAL "Path to cargo used by corrosion") - -string(REPLACE "-" "_" _CORROSION_RUST_CARGO_TARGET_UNDERSCORE "${Rust_CARGO_TARGET}") -string(TOUPPER "${_CORROSION_RUST_CARGO_TARGET_UNDERSCORE}" _CORROSION_TARGET_TRIPLE_UPPER) -set(_CORROSION_RUST_CARGO_TARGET_UNDERSCORE ${Rust_CARGO_TARGET} CACHE INTERNAL "lowercase target triple with underscores") -set(_CORROSION_RUST_CARGO_TARGET_UPPER - "${_CORROSION_TARGET_TRIPLE_UPPER}" - CACHE INTERNAL - "target triple in uppercase with underscore" -) - -# We previously specified some Custom properties as part of our public API, however the chosen names prevented us from -# supporting CMake versions before 3.19. In order to both support older CMake versions and not break existing code -# 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() - -# Add custom command to build one target in a package (crate) -# -# A target may be either a specific bin -function(_add_cargo_build out_cargo_build_out_dir) - set(options NO_LINKER_OVERRIDE) - set(one_value_args PACKAGE TARGET MANIFEST_PATH PROFILE WORKSPACE_MANIFEST_PATH) - set(multi_value_args BYPRODUCTS TARGET_KINDS) - cmake_parse_arguments( - ACB - "${options}" - "${one_value_args}" - "${multi_value_args}" - ${ARGN} - ) - - set(package_name "${ACB_PACKAGE}") - set(target_name "${ACB_TARGET}") - set(path_to_toml "${ACB_MANIFEST_PATH}") - set(cargo_profile_name "${ACB_PROFILE}") - set(target_kinds "${ACB_TARGET_KINDS}") - set(workspace_manifest_path "${ACB_WORKSPACE_MANIFEST_PATH}") - - - if(NOT target_kinds) - message(FATAL_ERROR "TARGET_KINDS not specified") - elseif("staticlib" IN_LIST target_kinds OR "cdylib" IN_LIST target_kinds) - set(cargo_rustc_filter "--lib") - elseif("bin" IN_LIST target_kinds) - set(cargo_rustc_filter "--bin=${target_name}") - else() - message(FATAL_ERROR "TARGET_KINDS contained unknown kind `${target_kind}`") - endif() - - if (NOT IS_ABSOLUTE "${path_to_toml}") - set(path_to_toml "${CMAKE_SOURCE_DIR}/${path_to_toml}") - endif() - get_filename_component(workspace_toml_dir ${path_to_toml} DIRECTORY ) - - if (CMAKE_VS_PLATFORM_NAME) - set (build_dir "${CMAKE_VS_PLATFORM_NAME}/$") - elseif(CMAKE_CONFIGURATION_TYPES) - set (build_dir "$") - else() - set (build_dir .) - endif() - - unset(is_windows_msvc) - get_source_file_property(is_windows_msvc "${workspace_manifest_path}" CORROSION_PLATFORM_IS_WINDOWS_MSVC) - - # Corrosions currently attempts to select a correct linker, based on the enabled languages. - # This approach is flawed and should be revisited in the future. - # Currently we disable this approach for the MSVC abi, because it just doesn't work - # and for static libraries, because the linker shouldn't be invoked for those, but - # potentially could be if Rust side build scripts or proc macros etc. happened to be involved. - # Overriding the linker in those cases is probably unwanted. - if(is_windows_msvc) - set(determine_linker_preference FALSE) - elseif("staticlib" IN_LIST target_kinds AND NOT "cdylib" IN_LIST target_kinds) - set(determine_linker_preference FALSE) - else() - set(determine_linker_preference TRUE) - endif() - - if(determine_linker_preference) - set(languages C CXX Fortran) - - set(has_compiler OFF) - foreach(language ${languages}) - if (CMAKE_${language}_COMPILER) - set(has_compiler ON) - endif() - endforeach() - - # When cross-compiling a Rust crate, at the very least we need a C linker - if (NOT has_compiler AND CMAKE_CROSSCOMPILING) - message(STATUS "Enabling the C compiler for linking Rust programs") - enable_language(C) - endif() - - # Determine the linker CMake prefers based on the enabled languages. - set(_CORROSION_LINKER_PREFERENCE_SCORE "0") - foreach(language ${languages}) - if( ${CMAKE_${language}_LINKER_PREFERENCE} ) - if(NOT CORROSION_LINKER_PREFERENCE - OR (${CMAKE_${language}_LINKER_PREFERENCE} GREATER ${_CORROSION_LINKER_PREFERENCE_SCORE})) - set(CORROSION_LINKER_PREFERENCE "${CMAKE_${language}_COMPILER}") - set(CORROSION_LINKER_PREFERENCE_TARGET "${CMAKE_${language}_COMPILER_TARGET}") - set(CORROSION_LINKER_PREFERENCE_LANGUAGE "${language}") - set(_CORROSION_LINKER_PREFERENCE_SCORE "${CMAKE_${language}_LINKER_PREFERENCE}") - endif() - endif() - endforeach() - message(VERBOSE "CORROSION_LINKER_PREFERENCE for target ${target_name}: ${CORROSION_LINKER_PREFERENCE}") - endif() - - if (NOT CMAKE_CONFIGURATION_TYPES) - set(target_dir ${CMAKE_CURRENT_BINARY_DIR}) - if (CMAKE_BUILD_TYPE STREQUAL "" OR CMAKE_BUILD_TYPE STREQUAL Debug) - set(build_type_dir debug) - else() - set(build_type_dir release) - endif() - else() - set(target_dir ${CMAKE_CURRENT_BINARY_DIR}/$) - set(build_type_dir $,$>,debug,release>) - endif() - - # If a CMake sysroot is specified, forward it to the linker rustc invokes, too. CMAKE_SYSROOT is documented - # to be passed via --sysroot, so we assume that when it's set, the linker supports this option in that style. - if(CMAKE_CROSSCOMPILING AND CMAKE_SYSROOT) - set(corrosion_link_args "--sysroot=${CMAKE_SYSROOT}") - endif() - - if(COR_ALL_FEATURES) - set(all_features_arg --all-features) - endif() - if(COR_NO_DEFAULT_FEATURES) - set(no_default_features_arg --no-default-features) - endif() - if(COR_NO_STD) - set(no_default_libraries_arg --no-default-libraries) - endif() - - set(global_rustflags_target_property "$>") - set(local_rustflags_target_property "$>") - - set(features_target_property "$>") - set(features_genex "$<$:--features=$>>") - - # target property overrides corrosion_import_crate argument - set(all_features_target_property "$>") - set(all_features_property_exists_condition "$>") - set(all_features_property_arg "$,--all-features,>") - set(all_features_arg "$") - - set(no_default_features_target_property "$>") - set(no_default_features_property_exists_condition "$>") - set(no_default_features_property_arg "$,--no-default-features,>") - set(no_default_features_arg "$") - - set(build_env_variable_genex "$>") - set(if_not_host_build_condition "$>>") - - set(corrosion_link_args "$<${if_not_host_build_condition}:${corrosion_link_args}>") - set(cargo_target_option "$") - - # The target may be a filepath to custom target json file. For host targets we assume that they are built-in targets. - _corrosion_strip_target_triple(${_CORROSION_RUST_CARGO_TARGET} stripped_target_triple) - set(target_artifact_dir "$") - - set(flags_genex "$>") - - set(explicit_linker_property "$") - - - # Rust will add `-lSystem` as a flag for the linker on macOS. Adding the -L flag via RUSTFLAGS only fixes the - # problem partially - buildscripts still break, since they won't receive the RUSTFLAGS. This seems to only be a - # problem if we specify the linker ourselves (which we do, since this is necessary for e.g. linking C++ code). - # We can however set `LIBRARY_PATH`, which is propagated to the build-script-build properly. - if(NOT CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_NAME STREQUAL "Darwin") - # not needed anymore on macos 13 (and causes issues) - if(${CMAKE_SYSTEM_VERSION} VERSION_LESS 22) - set(cargo_library_path "LIBRARY_PATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib") - endif() - elseif(CMAKE_CROSSCOMPILING AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") - if(${CMAKE_HOST_SYSTEM_VERSION} VERSION_LESS 22) - set(cargo_library_path "$") - endif() - endif() - - if(cargo_profile_name) - set(cargo_profile "--profile=${cargo_profile_name}") - set(build_type_dir "${cargo_profile_name}") - else() - set(cargo_profile $<$,$>>:--release>) - endif() - - set(cargo_target_dir "${CMAKE_BINARY_DIR}/${build_dir}/cargo/build") - set(cargo_build_dir "${cargo_target_dir}/${target_artifact_dir}/${build_type_dir}") - set("${out_cargo_build_out_dir}" "${cargo_build_dir}" PARENT_SCOPE) - - set(features_args) - foreach(feature ${COR_FEATURES}) - list(APPEND features_args --features ${feature}) - endforeach() - - set(flag_args) - foreach(flag ${COR_FLAGS}) - list(APPEND flag_args ${flag}) - endforeach() - - set(corrosion_cc_rs_flags) - - if(CMAKE_C_COMPILER AND _CORROSION_RUST_CARGO_TARGET_UNDERSCORE) - # This variable is read by cc-rs (often used in build scripts) to determine the c-compiler. - # It can still be overridden if the user sets the non underscore variant via the environment variables - # on the target. - list(APPEND corrosion_cc_rs_flags "CC_${_CORROSION_RUST_CARGO_TARGET_UNDERSCORE}=${CMAKE_C_COMPILER}") - endif() - if(CMAKE_CXX_COMPILER AND _CORROSION_RUST_CARGO_TARGET_UNDERSCORE) - list(APPEND corrosion_cc_rs_flags "CXX_${_CORROSION_RUST_CARGO_TARGET_UNDERSCORE}=${CMAKE_CXX_COMPILER}") - endif() - # Since we instruct cc-rs to use the compiler found by CMake, it is likely one that requires also - # specifying the target sysroot to use. CMake's generator makes sure to pass --sysroot with - # CMAKE_OSX_SYSROOT. Fortunately the compilers Apple ships also respect the SDKROOT environment - # variable, which we can set for use when cc-rs invokes the compiler. - if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin" AND CMAKE_OSX_SYSROOT) - list(APPEND corrosion_cc_rs_flags "SDKROOT=${CMAKE_OSX_SYSROOT}") - endif() - - corrosion_add_target_local_rustflags("${target_name}" "$<$:-Clink-args=${corrosion_link_args}>") - - # todo: this should probably also be guarded by if_not_host_build_condition. - if(COR_NO_STD) - corrosion_add_target_local_rustflags("${target_name}" "-Cdefault-linker-libraries=no") - else() - corrosion_add_target_local_rustflags("${target_name}" "-Cdefault-linker-libraries=yes") - endif() - - set(global_joined_rustflags "$") - set(global_rustflags_genex "$<$:RUSTFLAGS=${global_joined_rustflags}>") - set(local_rustflags_delimiter "$<$:-->") - set(local_rustflags_genex "$<$:${local_rustflags_target_property}>") - - - # Used to set a linker for a specific target-triple. - set(cargo_target_linker_var "CARGO_TARGET_${_CORROSION_RUST_CARGO_TARGET_UPPER}_LINKER") - if(NOT ACB_NO_LINKER_OVERRIDE) - if(CORROSION_LINKER_PREFERENCE) - set(cargo_target_linker_arg "$,${explicit_linker_property},${CORROSION_LINKER_PREFERENCE}>") - set(cargo_target_linker "${cargo_target_linker_var}=${cargo_target_linker_arg}") - if(CMAKE_CROSSCOMPILING) - # CMake does not offer a host compiler we could select when configured for cross-compiling. This - # effectively means that by default cc will be selected for builds targeting host. The user can still - # override this by manually adding the appropriate rustflags to select the compiler for the target! - set(cargo_target_linker "$<${if_not_host_build_condition}:${cargo_target_linker}>") - endif() - # Will be only set for cross-compilers like clang, c.f. `CMAKE__COMPILER_TARGET`. - if(CORROSION_LINKER_PREFERENCE_TARGET) - set(rustflag_linker_arg "-Clink-args=--target=${CORROSION_LINKER_PREFERENCE_TARGET}") - set(rustflag_linker_arg "$<${if_not_host_build_condition}:${rustflag_linker_arg}>") - # Skip adding the linker argument, if the linker is explicitly set, since the - # explicit_linker_property will not be set when this function runs. - # Passing this rustflag is necessary for clang. - corrosion_add_target_local_rustflags("${target_name}" "$<$>:${rustflag_linker_arg}>") - endif() - else() - message(DEBUG "No linker preference for target ${target_name} could be detected.") - # Note: Adding quotes here introduces wierd errors when using MSVC. Since there are no spaces here at - # configure time, we can omit the quotes without problems - set(cargo_target_linker $<$:${cargo_target_linker_var}=${explicit_linker_property}>) - endif() - else() - # Disable the linker override by setting it to an empty string. - set(cargo_target_linker "") - endif() - - message(DEBUG "TARGET ${target_name} produces byproducts ${byproducts}") - - add_custom_target( - _cargo-build_${target_name} - # Build crate - COMMAND - ${CMAKE_COMMAND} -E env - "${build_env_variable_genex}" - "${global_rustflags_genex}" - "${cargo_target_linker}" - "${corrosion_cc_rs_flags}" - "${cargo_library_path}" - "CORROSION_BUILD_DIR=${CMAKE_CURRENT_BINARY_DIR}" - "CARGO_BUILD_RUSTC=${_CORROSION_RUSTC}" - "${_CORROSION_CARGO}" - rustc - ${cargo_rustc_filter} - ${cargo_target_option} - ${_CORROSION_VERBOSE_OUTPUT_FLAG} - # Global --features arguments added via corrosion_import_crate() - ${features_args} - ${all_features_arg} - ${no_default_features_arg} - # Target specific features added via corrosion_set_features(). - ${features_genex} - --package ${package_name} - --manifest-path "${path_to_toml}" - --target-dir "${cargo_target_dir}" - ${cargo_profile} - ${flag_args} - ${flags_genex} - # Any arguments to cargo must be placed before this line - ${local_rustflags_delimiter} - ${local_rustflags_genex} - - # Note: Adding `build_byproducts` (the byproducts in the cargo target directory) here - # causes CMake to fail during the Generate stage, because the target `target_name` was not - # found. I don't know why this happens, so we just don't specify byproducts here and - # only specify the actual byproducts in the `POST_BUILD` custom command that copies the - # byproducts to the final destination. - # BYPRODUCTS ${build_byproducts} - # The build is conducted in the directory of the Manifest, so that configuration files such as - # `.cargo/config.toml` or `toolchain.toml` are applied as expected. - WORKING_DIRECTORY "${workspace_toml_dir}" - USES_TERMINAL - COMMAND_EXPAND_LISTS - VERBATIM - ) - - # User exposed custom target, that depends on the internal target. - # Corrosion post build steps are added on the internal target, which - # ensures that they run before any user defined post build steps on this - # target. - add_custom_target( - cargo-build_${target_name} - ALL - ) - add_dependencies(cargo-build_${target_name} _cargo-build_${target_name}) - - # Add custom target before actual build that user defined custom commands (e.g. code generators) can - # use as a hook to do something before the build. This mainly exists to not expose the `_cargo-build` targets. - add_custom_target(cargo-prebuild_${target_name}) - add_dependencies(_cargo-build_${target_name} cargo-prebuild_${target_name}) - if(NOT TARGET cargo-prebuild) - add_custom_target(cargo-prebuild) - endif() - add_dependencies(cargo-prebuild cargo-prebuild_${target_name}) - - add_custom_target( - cargo-clean_${target_name} - COMMAND - $ clean ${cargo_target_option} - -p ${package_name} --manifest-path ${path_to_toml} - WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${build_dir} - USES_TERMINAL - ) - - if (NOT TARGET cargo-clean) - add_custom_target(cargo-clean) - endif() - add_dependencies(cargo-clean cargo-clean_${target_name}) -endfunction() - -function(corrosion_import_crate) - set(OPTIONS ALL_FEATURES NO_DEFAULT_FEATURES NO_STD NO_LINKER_OVERRIDE) - 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}) - - if (NOT DEFINED COR_MANIFEST_PATH) - message(FATAL_ERROR "MANIFEST_PATH is a required keyword to corrosion_add_crate") - endif() - - if(COR_PROFILE) - if(Rust_VERSION VERSION_LESS 1.57.0) - message(FATAL_ERROR "Selecting custom profiles via `PROFILE` requires at least rust 1.57.0, but you " - "have ${Rust_VERSION}." - ) - else() - set(cargo_profile --profile=${COR_PROFILE}) - endif() - endif() - - if (NOT IS_ABSOLUTE "${COR_MANIFEST_PATH}") - 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) - if(COR_IMPORTED_CRATES) - message(FATAL_ERROR "corrosion_import_crate option `IMPORTED_CRATES` may not be selected when " - "CORROSION_NATIVE_TOOLING is ON." - ) - endif() - execute_process( - COMMAND - ${_CORROSION_GENERATOR} - --manifest-path ${COR_MANIFEST_PATH} - print-root - OUTPUT_VARIABLE toml_dir - RESULT_VARIABLE ret) - - if (NOT ret EQUAL "0") - message(FATAL_ERROR "corrosion-generator failed: ${ret}") - endif() - - string(STRIP "${toml_dir}" toml_dir) - - get_filename_component(toml_dir_name ${toml_dir} 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() - - execute_process( - COMMAND - ${_CORROSION_GENERATOR} - --manifest-path ${COR_MANIFEST_PATH} - gen-cmake - ${_CORROSION_CONFIGURATION_ROOT} - ${crates_args} - ${cargo_profile} - -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( - COR_NO_LINKER_OVERRIDE - MANIFEST_PATH - "${COR_MANIFEST_PATH}" - CRATES - "${COR_CRATES}" - CRATE_TYPES - "${COR_CRATE_TYPES}" - PROFILE - "${COR_PROFILE}" - IMPORTED_CRATES - imported_crates - ) - - if (DEFINED COR_IMPORTED_CRATES) - set(${COR_IMPORTED_CRATES} ${imported_crates} PARENT_SCOPE) - endif() - endif() -endfunction(corrosion_import_crate) - -function(corrosion_set_linker_language target_name language) - message(DEPRECATION "corrosion_set_linker_language is deprecated." - "Please use corrosion_set_linker and set a specific linker.") - set_property( - TARGET _cargo-build_${target_name} - PROPERTY LINKER_LANGUAGE ${language} - ) -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") - endif() - if(MSVC) - message(WARNING "Explicitly setting the linker with the MSVC toolchain is currently not supported and ignored") - endif() - - set_property( - TARGET ${target_name} - PROPERTY INTERFACE_CORROSION_LINKER "${linker}" - ) -endfunction() - -function(corrosion_set_hostbuild target_name) - # Configure the target to be compiled for the Host target and ignore any cross-compile configuration. - set_property( - TARGET ${target_name} - PROPERTY ${_CORR_PROP_HOST_BUILD} 1 - ) -endfunction() - -# Add flags for rustc (RUSTFLAGS) which affect the target and all of it's Rust dependencies -# -# Additional rustflags may be passed as optional parameters after rustflag. -# Please note, that if you import multiple targets from a package or workspace, but set different -# Rustflags via this function, the Rust dependencies will have to be rebuilt when changing targets. -# Consider `corrosion_add_target_local_rustflags()` as an alternative to avoid this. -function(corrosion_add_target_rustflags target_name rustflag) - # Additional rustflags may be passed as optional parameters after rustflag. - set_property( - TARGET ${target_name} - APPEND - PROPERTY INTERFACE_CORROSION_RUSTFLAGS ${rustflag} ${ARGN} - ) -endfunction() - -# Add flags for rustc (RUSTFLAGS) which only affect the target, but none of it's (Rust) dependencies -# -# Additional rustflags may be passed as optional parameters after rustc_flag. -function(corrosion_add_target_local_rustflags target_name rustc_flag) - # Set Rustflags via `cargo rustc` which only affect the current crate, but not dependencies. - set_property( - TARGET ${target_name} - APPEND - PROPERTY INTERFACE_CORROSION_LOCAL_RUSTFLAGS ${rustc_flag} ${ARGN} - ) -endfunction() - -function(corrosion_set_env_vars target_name env_var) - # Additional environment variables may be passed as optional parameters after env_var. - set_property( - TARGET ${target_name} - APPEND - PROPERTY ${_CORR_PROP_ENV_VARS} ${env_var} ${ARGN} - ) -endfunction() - -function(corrosion_set_cargo_flags target_name) - # corrosion_set_cargo_flags( [ ... ]) - - set_property( - TARGET ${target_name} - APPEND - PROPERTY INTERFACE_CORROSION_CARGO_FLAGS ${ARGN} - ) -endfunction() - -function(corrosion_set_features target_name) - # corrosion_set_features( [ALL_FEATURES=Bool] [NO_DEFAULT_FEATURES] [FEATURES ... ]) - set(options NO_DEFAULT_FEATURES) - set(one_value_args ALL_FEATURES) - set(multi_value_args FEATURES) - cmake_parse_arguments( - PARSE_ARGV 1 - SET - "${options}" - "${one_value_args}" - "${multi_value_args}" - ) - - if(DEFINED SET_ALL_FEATURES) - set_property( - TARGET ${target_name} - PROPERTY ${_CORR_PROP_ALL_FEATURES} ${SET_ALL_FEATURES} - ) - endif() - if(SET_NO_DEFAULT_FEATURES) - set_property( - TARGET ${target_name} - PROPERTY ${_CORR_PROP_NO_DEFAULT_FEATURES} 1 - ) - endif() - if(SET_FEATURES) - set_property( - TARGET ${target_name} - APPEND - PROPERTY ${_CORR_PROP_FEATURES} ${SET_FEATURES} - ) - endif() -endfunction() - -function(corrosion_link_libraries target_name) - add_dependencies(_cargo-build_${target_name} ${ARGN}) - foreach(library ${ARGN}) - set_property( - TARGET _cargo-build_${target_name} - APPEND - PROPERTY CARGO_DEPS_LINKER_LANGUAGES - $ - ) - - corrosion_add_target_local_rustflags(${target_name} "-L$") - corrosion_add_target_local_rustflags(${target_name} "-l$") - endforeach() -endfunction(corrosion_link_libraries) - -function(corrosion_install) - # Default install dirs - include(GNUInstallDirs) - - # Parse arguments to corrosion_install - list(GET ARGN 0 INSTALL_TYPE) - list(REMOVE_AT ARGN 0) - - # The different install types that are supported. Some targets may have more than one of these - # types. For example, on Windows, a shared library will have both an ARCHIVE component and a - # RUNTIME component. - set(INSTALL_TARGET_TYPES ARCHIVE LIBRARY RUNTIME PRIVATE_HEADER PUBLIC_HEADER) - - # Arguments to each install target type - set(OPTIONS) - set(ONE_VALUE_ARGS DESTINATION) - set(MULTI_VALUE_ARGS PERMISSIONS CONFIGURATIONS) - set(TARGET_ARGS ${OPTIONS} ${ONE_VALUE_ARGS} ${MULTI_VALUE_ARGS}) - - if (INSTALL_TYPE STREQUAL "TARGETS") - # corrosion_install(TARGETS ... [EXPORT ] - # [[ARCHIVE|LIBRARY|RUNTIME|PRIVATE_HEADER|PUBLIC_HEADER] - # [DESTINATION ] - # [PERMISSIONS permissions...] - # [CONFIGURATIONS [Debug|Release|...]] - # ] [...]) - - # Extract targets - set(INSTALL_TARGETS) - list(LENGTH ARGN ARGN_LENGTH) - set(DELIMITERS EXPORT ${INSTALL_TARGET_TYPES} ${TARGET_ARGS}) - while(ARGN_LENGTH) - # If we hit another keyword, stop - we've found all the targets - list(GET ARGN 0 FRONT) - if (FRONT IN_LIST DELIMITERS) - break() - endif() - - list(APPEND INSTALL_TARGETS ${FRONT}) - list(REMOVE_AT ARGN 0) - - # Update ARGN_LENGTH - list(LENGTH ARGN ARGN_LENGTH) - endwhile() - - # Check if there are any args left before proceeding - list(LENGTH ARGN ARGN_LENGTH) - if (ARGN_LENGTH) - list(GET ARGN 0 FRONT) - if (FRONT STREQUAL "EXPORT") - list(REMOVE_AT ARGN 0) # Pop "EXPORT" - - list(GET ARGN 0 EXPORT_NAME) - list(REMOVE_AT ARGN 0) # Pop - message(FATAL_ERROR "EXPORT keyword not yet implemented!") - endif() - endif() - - # Loop over all arguments and get options for each install target type - list(LENGTH ARGN ARGN_LENGTH) - while(ARGN_LENGTH) - # Check if we're dealing with arguments for a specific install target type, or with - # default options for all target types. - list(GET ARGN 0 FRONT) - if (FRONT IN_LIST INSTALL_TARGET_TYPES) - set(INSTALL_TARGET_TYPE ${FRONT}) - list(REMOVE_AT ARGN 0) - else() - set(INSTALL_TARGET_TYPE DEFAULT) - endif() - - # Gather the arguments to this install type - set(ARGS) - while(ARGN_LENGTH) - # If the next keyword is an install target type, then break - arguments have been - # gathered. - list(GET ARGN 0 FRONT) - if (FRONT IN_LIST INSTALL_TARGET_TYPES) - break() - endif() - - list(APPEND ARGS ${FRONT}) - list(REMOVE_AT ARGN 0) - - list(LENGTH ARGN ARGN_LENGTH) - endwhile() - - # Parse the arguments and register the file install - cmake_parse_arguments( - COR "${OPTIONS}" "${ONE_VALUE_ARGS}" "${MULTI_VALUE_ARGS}" ${ARGS}) - - if (COR_DESTINATION) - set(COR_INSTALL_${INSTALL_TARGET_TYPE}_DESTINATION ${COR_DESTINATION}) - endif() - - if (COR_PERMISSIONS) - set(COR_INSTALL_${INSTALL_TARGET_TYPE}_PERMISSIONS ${COR_PERMISSIONS}) - endif() - - if (COR_CONFIGURATIONS) - set(COR_INSTALL_${INSTALL_TARGET_TYPE}_CONFIGURATIONS ${COR_CONFIGURATIONS}) - endif() - - # Update ARG_LENGTH - list(LENGTH ARGN ARGN_LENGTH) - endwhile() - - # Default permissions for all files - set(DEFAULT_PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ) - - # Loop through each install target and register file installations - foreach(INSTALL_TARGET ${INSTALL_TARGETS}) - # Don't both implementing target type differentiation using generator expressions since - # TYPE cannot change after target creation - get_property( - TARGET_TYPE - TARGET ${INSTALL_TARGET} PROPERTY TYPE - ) - - # Install executable files first - if (TARGET_TYPE STREQUAL "EXECUTABLE") - if (DEFINED COR_INSTALL_RUNTIME_DESTINATION) - set(DESTINATION ${COR_INSTALL_RUNTIME_DESTINATION}) - elseif (DEFINED COR_INSTALL_DEFAULT_DESTINATION) - set(DESTINATION ${COR_INSTALL_DEFAULT_DESTINATION}) - else() - set(DESTINATION ${CMAKE_INSTALL_BINDIR}) - endif() - - if (DEFINED COR_INSTALL_RUNTIME_PERMISSIONS) - set(PERMISSIONS ${COR_INSTALL_RUNTIME_PERMISSIONS}) - elseif (DEFINED COR_INSTALL_DEFAULT_PERMISSIONS) - set(PERMISSIONS ${COR_INSTALL_DEFAULT_PERMISSIONS}) - else() - set( - PERMISSIONS - ${DEFAULT_PERMISSIONS} OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE) - endif() - - if (DEFINED COR_INSTALL_RUNTIME_CONFIGURATIONS) - set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_RUNTIME_CONFIGURATIONS}) - elseif (DEFINED COR_INSTALL_DEFAULT_CONFIGURATIONS) - set(CONFIGURATIONS CONFIGURATIONS ${COR_INSTALL_DEFAULT_CONFIGURATIONS}) - else() - set(CONFIGURATIONS) - endif() - - install( - FILES $ - DESTINATION ${DESTINATION} - PERMISSIONS ${PERMISSIONS} - ${CONFIGURATIONS} - ) - endif() - endforeach() - - elseif(INSTALL_TYPE STREQUAL "EXPORT") - message(FATAL_ERROR "install(EXPORT ...) not yet implemented") - endif() -endfunction() diff --git a/connectors/corrosion/cmake/CorrosionConfig.cmake.in b/connectors/corrosion/cmake/CorrosionConfig.cmake.in deleted file mode 100644 index abf099c3..00000000 --- a/connectors/corrosion/cmake/CorrosionConfig.cmake.in +++ /dev/null @@ -1,18 +0,0 @@ -@PACKAGE_INIT@ - -if (Corrosion_FOUND) - return() -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/connectors/corrosion/cmake/CorrosionGenerator.cmake b/connectors/corrosion/cmake/CorrosionGenerator.cmake deleted file mode 100644 index 2540d39a..00000000 --- a/connectors/corrosion/cmake/CorrosionGenerator.cmake +++ /dev/null @@ -1,243 +0,0 @@ -function(_cargo_metadata out manifest) - get_property( - RUSTC_EXECUTABLE - TARGET Rust::Rustc PROPERTY IMPORTED_LOCATION - ) - get_property( - CARGO_EXECUTABLE - TARGET Rust::Cargo PROPERTY IMPORTED_LOCATION - ) - execute_process( - COMMAND - ${CMAKE_COMMAND} -E env - CARGO_BUILD_RUSTC=${RUSTC_EXECUTABLE} - ${CARGO_EXECUTABLE} - metadata - --manifest-path "${manifest}" - --format-version 1 - # We don't care about non-workspace dependencies - --no-deps - - OUTPUT_VARIABLE json - COMMAND_ERROR_IS_FATAL ANY - ) - - set(${out} ${json} PARENT_SCOPE) -endfunction() - -# Add targets (crates) of one package -function(_generator_add_package_targets workspace_manifest_path package_manifest_path package_name targets profile no_linker_override out_created_targets crate_types) - # target types - set(has_staticlib FALSE) - set(has_cdylib FALSE) - set(corrosion_targets "") - - - # Add a custom target with the package (crate) name, as a convenience to build everything in a - # crate. - # Note: may cause problems if package_name == bin_name... - #add_custom_target("${package_name}") - # todo: verify on windows if this actually needs to be done... - string(REPLACE "\\" "/" manifest_path "${package_manifest_path}") - - string(JSON targets_len LENGTH "${targets}") - math(EXPR targets_len-1 "${targets_len} - 1") - - if(${no_linker_override}) - set(_NO_LINKER_OVERRIDE "NO_LINKER_OVERRIDE") - else() - set(_NO_LINKER_OVERRIDE "") - endif() - - foreach(ix RANGE ${targets_len-1}) - # - string(JSON target GET "${targets}" ${ix}) - string(JSON target_name GET "${target}" "name") - string(JSON target_kind GET "${target}" "kind") - string(JSON target_kind_len LENGTH "${target_kind}") - string(JSON target_name GET "${target}" "name") - - math(EXPR target_kind_len-1 "${target_kind_len} - 1") - set(kinds) - foreach(ix RANGE ${target_kind_len-1}) - string(JSON kind GET "${target_kind}" ${ix}) - if(NOT crate_types OR ${kind} IN_LIST crate_types) - list(APPEND kinds ${kind}) - endif() - endforeach() - - if(TARGET "${target_name}" - AND ("staticlib" IN_LIST kinds OR "cdylib" IN_LIST kinds OR "bin" IN_LIST kinds) - ) - message(WARNING "Failed to import Rust crate ${target_name} (kind: `${target_kind}`) because a target " - "with the same name already exists. Skipping this target.\n" - "Help: If you are importing a package which exposes both a `lib` and " - "a `bin` target, please consider explicitly naming the targets in your `Cargo.toml` manifest.\n" - "Note: If you have multiple different packages which have targets with the same name, please note that " - "this is currently not supported by Corrosion. Feel free to open an issue on Github to request " - "supporting this scenario." - ) - # Skip this target to prevent a hard error. - continue() - endif() - - if("staticlib" IN_LIST kinds OR "cdylib" IN_LIST kinds) - if("staticlib" IN_LIST kinds) - set(has_staticlib TRUE) - endif() - - if("cdylib" IN_LIST kinds) - set(has_cdylib TRUE) - endif() - set(archive_byproducts "") - set(shared_lib_byproduct "") - set(pdb_byproduct "") - - _corrosion_add_library_target("${workspace_manifest_path}" "${target_name}" "${has_staticlib}" "${has_cdylib}" - archive_byproducts shared_lib_byproduct pdb_byproduct) - - set(byproducts "") - list(APPEND byproducts "${archive_byproducts}" "${shared_lib_byproduct}" "${pdb_byproduct}") - - set(cargo_build_out_dir "") - _add_cargo_build( - cargo_build_out_dir - ${_NO_LINKER_OVERRIDE} - PACKAGE ${package_name} - TARGET ${target_name} - MANIFEST_PATH "${manifest_path}" - WORKSPACE_MANIFEST_PATH "${workspace_manifest_path}" - PROFILE "${profile}" - TARGET_KINDS "${kinds}" - BYPRODUCTS "${byproducts}" - ) - 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() - list(APPEND corrosion_targets ${target_name}) - - elseif("bin" IN_LIST kinds) - set(pdb_byproduct "") - _corrosion_add_bin_target("${workspace_manifest_path}" "${target_name}" - "bin_byproduct" "pdb_byproduct" - ) - - set(byproducts "") - list(APPEND byproducts "${bin_byproduct}" "${pdb_byproduct}") - - set(cargo_build_out_dir "") - _add_cargo_build( - cargo_build_out_dir - ${_NO_LINKER_OVERRIDE} - PACKAGE "${package_name}" - TARGET "${target_name}" - MANIFEST_PATH "${manifest_path}" - WORKSPACE_MANIFEST_PATH "${workspace_manifest_path}" - PROFILE "${profile}" - TARGET_KINDS "bin" - BYPRODUCTS "${byproducts}" - ) - _corrosion_copy_byproducts( - ${target_name} RUNTIME_OUTPUT_DIRECTORY "${cargo_build_out_dir}" "${bin_byproduct}" - ) - if(pdb_byproduct) - _corrosion_copy_byproducts( - ${target_name} PDB_OUTPUT_DIRECTORY "${cargo_build_out_dir}" "${pdb_byproduct}" - ) - endif() - list(APPEND corrosion_targets ${target_name}) - else() - # ignore other kinds (like examples, tests, build scripts, ...) - endif() - endforeach() - - if(NOT corrosion_targets) - message(DEBUG "No relevant targets found in package ${package_name} - Ignoring") - endif() - set(${out_created_targets} "${corrosion_targets}" PARENT_SCOPE) - -endfunction() - - -function(_generator_add_cargo_targets no_linker_override) - set(options "") - set(one_value_args MANIFEST_PATH PROFILE IMPORTED_CRATES) - set(multi_value_args CRATES CRATE_TYPES) - cmake_parse_arguments( - GGC - "${options}" - "${one_value_args}" - "${multi_value_args}" - ${ARGN} - ) - - _cargo_metadata(json ${GGC_MANIFEST_PATH}) - string(JSON packages GET "${json}" "packages") - string(JSON workspace_members GET "${json}" "workspace_members") - - string(JSON pkgs_len LENGTH "${packages}") - math(EXPR pkgs_len-1 "${pkgs_len} - 1") - - string(JSON ws_mems_len LENGTH ${workspace_members}) - math(EXPR ws_mems_len-1 "${ws_mems_len} - 1") - - set(created_targets "") - foreach(ix RANGE ${pkgs_len-1}) - string(JSON pkg GET "${packages}" ${ix}) - string(JSON pkg_id GET "${pkg}" "id") - string(JSON pkg_name GET "${pkg}" "name") - string(JSON pkg_manifest_path GET "${pkg}" "manifest_path") - string(JSON targets GET "${pkg}" "targets") - - string(JSON targets_len LENGTH "${targets}") - math(EXPR targets_len-1 "${targets_len} - 1") - foreach(ix RANGE ${ws_mems_len-1}) - string(JSON ws_mem GET "${workspace_members}" ${ix}) - if(ws_mem STREQUAL pkg_id AND ((NOT GGC_CRATES) OR (pkg_name IN_LIST GGC_CRATES))) - message(DEBUG "Found ${targets_len} targets in package ${pkg_name}") - - _generator_add_package_targets("${GGC_MANIFEST_PATH}" "${pkg_manifest_path}" "${pkg_name}" "${targets}" "${GGC_PROFILE}" "${no_linker_override}" curr_created_targets "${GGC_CRATE_TYPES}") - list(APPEND created_targets "${curr_created_targets}") - endif() - endforeach() - endforeach() - - if(NOT created_targets) - message(FATAL_ERROR "found no targets in ${pkgs_len} packages") - else() - message(DEBUG "Corrosion created the following CMake targets: ${created_targets}") - endif() - - if(GGC_IMPORTED_CRATES) - set(${GGC_IMPORTED_CRATES} "${created_targets}" PARENT_SCOPE) - endif() - - 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}") - if (NOT output_dir AND DEFINED "CMAKE_${output_var}") - set_property(TARGET ${target_name} PROPERTY ${output_var} "${CMAKE_${output_var}}") - endif() - - foreach(config_type ${CMAKE_CONFIGURATION_TYPES}) - string(TOUPPER "${config_type}" config_type_upper) - get_target_property(output_dir ${target_name} "${output_var}_${config_type_upper}") - if (NOT output_dir AND DEFINED "CMAKE_${output_var}_${config_type_upper}") - set_property(TARGET ${target_name} PROPERTY "${output_var}_${config_type_upper}" "${CMAKE_${output_var}_${config_type_upper}}") - endif() - endforeach() - endforeach() - endforeach() -endfunction() diff --git a/connectors/corrosion/cmake/FindRust.cmake b/connectors/corrosion/cmake/FindRust.cmake deleted file mode 100644 index 86dfc243..00000000 --- a/connectors/corrosion/cmake/FindRust.cmake +++ /dev/null @@ -1,518 +0,0 @@ -#[=======================================================================[.rst: -FindRust --------- - -Find Rust - -This module finds an installed rustc compiler and the cargo build tool. If Rust -is managed by rustup it determines the available toolchains and returns a -concrete Rust version, not a rustup proxy. - -#]=======================================================================] - -cmake_minimum_required(VERSION 3.12) - -# search for Cargo here and set up a bunch of cool flags and stuff -include(FindPackageHandleStandardArgs) - -# Print error message and return. -macro(_findrust_failed) - if("${Rust_FIND_REQUIRED}") - message(FATAL_ERROR ${ARGN}) - elseif(NOT "${Rust_FIND_QUIETLY}") - message(WARNING ${ARGN}) - endif() - # Note: PARENT_SCOPE is the scope of the caller of the caller of this macro. - set(Rust_FOUND "" PARENT_SCOPE) - return() -endmacro() - -# Checks if the actual version of a Rust toolchain matches the VERSION requirements specified in find_package. -function(_findrust_version_ok ACTUAL_VERSION OUT_IS_OK) - if(DEFINED Rust_FIND_VERSION_RANGE) - if(Rust_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE") - set(COMPARSION_OPERATOR "VERSION_LESS_EQUAL") - elseif(Rust_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE") - set(COMPARSION_OPERATOR "VERSION_LESS") - else() - message(FATAL_ERROR "Unexpected value in `_FIND_VERSION_RANGE_MAX`: " - "`${Rust_FIND_VERSION_RANGE_MAX}`.") - endif() - if(("${ACTUAL_VERSION}" VERSION_GREATER_EQUAL "${Rust_FIND_VERSION_RANGE_MIN}") - AND - ( "${ACTUAL_VERSION}" ${COMPARSION_OPERATOR} "${Rust_FIND_VERSION_RANGE_MAX}" ) - ) - set("${OUT_IS_OK}" TRUE PARENT_SCOPE) - else() - set("${OUT_IS_OK}" FALSE PARENT_SCOPE) - endif() - elseif(DEFINED Rust_FIND_VERSION) - if(Rust_VERSION_EXACT) - set(COMPARISON_OPERATOR VERSION_EQUAL) - else() - set(COMPARISON_OPERATOR VERSION_GREATER_EQUAL) - endif() - if(_TOOLCHAIN_${_TOOLCHAIN_SELECTED}_VERSION "${COMPARISON_OPERATOR}" Rust_FIND_VERSION) - set("${OUT_IS_OK}" TRUE PARENT_SCOPE) - else() - set("${OUT_IS_OK}" FALSE PARENT_SCOPE) - endif() - else() - # if no VERSION requirement was specified, the version is always okay. - set("${OUT_IS_OK}" TRUE PARENT_SCOPE) - endif() -endfunction() - -if (NOT "${Rust_TOOLCHAIN}" STREQUAL "$CACHE{Rust_TOOLCHAIN}") - # Promote Rust_TOOLCHAIN to a cache variable if it is not already a cache variable - set(Rust_TOOLCHAIN ${Rust_TOOLCHAIN} CACHE STRING "Requested rustup toolchain" FORCE) -endif() - -# This block checks to see if we're prioritizing a rustup-managed toolchain. -if (DEFINED Rust_TOOLCHAIN) - # If the user specifies `Rust_TOOLCHAIN`, then look for `rustup` first, rather than `rustc`. - find_program(Rust_RUSTUP rustup PATHS "$ENV{HOME}/.cargo/bin") - if(Rust_RUSTUP) - set(_RESOLVE_RUSTUP_TOOLCHAINS ON) - else() - set(_RESOLVE_RUSTUP_TOOLCHAINS OFF) - if(NOT "${Rust_FIND_QUIETLY}") - message( - WARNING "CMake variable `Rust_TOOLCHAIN` specified, but `rustup` was not found. " - "Ignoring toolchain and looking for a Rust toolchain not managed by rustup.") - endif() - endif() -else() - # If we aren't definitely using a rustup toolchain, look for rustc first - the user may have - # a toolchain installed via a method other than rustup higher in the PATH, which should be - # preferred. However, if the first-found rustc is a rustup proxy, then we'll revert to - # finding the preferred toolchain via rustup. - - # Uses `Rust_COMPILER` to let user-specified `rustc` win. But we will still "override" the - # user's setting if it is pointing to `rustup`. Default rustup install path is provided as a - # backup if a toolchain cannot be found in the user's PATH. - - if (DEFINED Rust_COMPILER) - set(_Rust_COMPILER_TEST "${Rust_COMPILER}") - set(_USER_SPECIFIED_RUSTC ON) - if(NOT (EXISTS "${_Rust_COMPILER_TEST}" AND NOT IS_DIRECTORY "${_Rust_COMPILER_TEST}")) - set(_ERROR_MESSAGE "Rust_COMPILER was set to `${Rust_COMPILER}`, but this file does " - "not exist." - ) - _findrust_failed(${_ERROR_MESSAGE}) - return() - endif() - else() - find_program(_Rust_COMPILER_TEST rustc PATHS "$ENV{HOME}/.cargo/bin") - if(NOT EXISTS "${_Rust_COMPILER_TEST}") - set(_ERROR_MESSAGE "`rustc` not found in PATH or `$ENV{HOME}/.cargo/bin`.\n" - "Hint: Check if `rustc` is in PATH or manually specify the location " - "by setting `Rust_COMPILER` to the path to `rustc`.") - _findrust_failed(${_ERROR_MESSAGE}) - endif() - endif() - - # Check if the discovered rustc is actually a "rustup" proxy. - execute_process( - COMMAND - ${CMAKE_COMMAND} -E env - RUSTUP_FORCE_ARG0=rustup - "${_Rust_COMPILER_TEST}" --version - OUTPUT_VARIABLE _RUSTC_VERSION_RAW - ERROR_VARIABLE _RUSTC_VERSION_STDERR - RESULT_VARIABLE _RUSTC_VERSION_RESULT - ) - - if(NOT (_RUSTC_VERSION_RESULT EQUAL "0")) - _findrust_failed("`${_Rust_COMPILER_TEST} --version` failed with ${_RUSTC_VERSION_RESULT}\n" - "rustc stderr:\n${_RUSTC_VERSION_STDERR}" - ) - endif() - - if (_RUSTC_VERSION_RAW MATCHES "rustup [0-9\\.]+") - if (_USER_SPECIFIED_RUSTC) - message( - WARNING "User-specified Rust_COMPILER pointed to rustup's rustc proxy. Corrosion's " - "FindRust will always try to evaluate to an actual Rust toolchain, and so the " - "user-specified Rust_COMPILER will be discarded in favor of the default " - "rustup-managed toolchain." - ) - - unset(Rust_COMPILER) - unset(Rust_COMPILER CACHE) - endif() - - set(_RESOLVE_RUSTUP_TOOLCHAINS ON) - - # Get `rustup` next to the `rustc` proxy - get_filename_component(_RUST_PROXIES_PATH "${_Rust_COMPILER_TEST}" DIRECTORY) - find_program(Rust_RUSTUP rustup HINTS "${_RUST_PROXIES_PATH}" NO_DEFAULT_PATH) - endif() - - unset(_Rust_COMPILER_TEST CACHE) -endif() - -# At this point, the only thing we should have evaluated is a path to `rustup` _if that's what the -# best source for a Rust toolchain was determined to be_. - -# List of user variables that will override any toolchain-provided setting -set(_Rust_USER_VARS Rust_COMPILER Rust_CARGO Rust_CARGO_TARGET Rust_CARGO_HOST_TARGET) -foreach(_VAR ${_Rust_USER_VARS}) - if (DEFINED "${_VAR}") - set(${_VAR}_CACHED "${${_VAR}}" CACHE INTERNAL "Internal cache of ${_VAR}") - else() - unset(${_VAR}_CACHED CACHE) - endif() -endforeach() - -# Discover what toolchains are installed by rustup, if the discovered `rustc` is a proxy from -# `rustup`, then select either the default toolchain, or the requested toolchain Rust_TOOLCHAIN -if (_RESOLVE_RUSTUP_TOOLCHAINS) - execute_process( - COMMAND - "${Rust_RUSTUP}" toolchain list --verbose - OUTPUT_VARIABLE _TOOLCHAINS_RAW - ) - - string(REPLACE "\n" ";" _TOOLCHAINS_RAW "${_TOOLCHAINS_RAW}") - - foreach(_TOOLCHAIN_RAW ${_TOOLCHAINS_RAW}) - if (_TOOLCHAIN_RAW MATCHES "([a-zA-Z0-9\\._\\-]+)[ \t\r\n]?(\\(default\\) \\(override\\)|\\(default\\)|\\(override\\))?[ \t\r\n]+(.+)") - set(_TOOLCHAIN "${CMAKE_MATCH_1}") - set(_TOOLCHAIN_TYPE "${CMAKE_MATCH_2}") - list(APPEND _DISCOVERED_TOOLCHAINS "${_TOOLCHAIN}") - - set(_TOOLCHAIN_PATH "${CMAKE_MATCH_3}") - set(_TOOLCHAIN_${_TOOLCHAIN}_PATH "${CMAKE_MATCH_3}") - - if (_TOOLCHAIN_TYPE MATCHES ".*\\(default\\).*") - set(_TOOLCHAIN_DEFAULT "${_TOOLCHAIN}") - endif() - - if (_TOOLCHAIN_TYPE MATCHES ".*\\(override\\).*") - set(_TOOLCHAIN_OVERRIDE "${_TOOLCHAIN}") - endif() - - execute_process( - COMMAND - "${_TOOLCHAIN_PATH}/bin/rustc" --version - OUTPUT_VARIABLE _TOOLCHAIN_RAW_VERSION - ) - if (_TOOLCHAIN_RAW_VERSION MATCHES "rustc ([0-9]+)\\.([0-9]+)\\.([0-9]+)(-nightly)?") - # todo: maybe needs to be advanced cache variable... - set(_TOOLCHAIN_${_TOOLCHAIN}_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}") - if(CMAKE_MATCH_4) - set(_TOOLCHAIN_${_TOOLCHAIN}_IS_NIGHTLY "TRUE") - else() - set(_TOOLCHAIN_${_TOOLCHAIN}_IS_NIGHTLY "FALSE") - endif() - endif() - - else() - message(WARNING "Didn't recognize toolchain: ${_TOOLCHAIN_RAW}") - endif() - endforeach() - - # Rust_TOOLCHAIN is preferred over a requested version if it is set. - if (NOT DEFINED Rust_TOOLCHAIN) - if (NOT DEFINED _TOOLCHAIN_OVERRIDE) - set(_TOOLCHAIN_SELECTED "${_TOOLCHAIN_DEFAULT}") - else() - set(_TOOLCHAIN_SELECTED "${_TOOLCHAIN_OVERRIDE}") - endif() - # Check default toolchain first. - _findrust_version_ok("_TOOLCHAIN_${_TOOLCHAIN_SELECTED}_VERSION" _VERSION_OK) - if(NOT "${_VERSION_OK}") - foreach(_TOOLCHAIN "${_DISCOVERED_TOOLCHAINS}") - _findrust_version_ok("_TOOLCHAIN_${_TOOLCHAIN}_VERSION" _VERSION_OK) - if("${_VERSION_OK}") - set(_TOOLCHAIN_SELECTED "${_TOOLCHAIN}") - break() - endif() - endforeach() - # Check if we found a suitable version in the for loop. - if(NOT "${_VERSION_OK}") - string(REPLACE ";" "\n" _DISCOVERED_TOOLCHAINS "${_DISCOVERED_TOOLCHAINS}") - _findrust_failed("Failed to find a Rust toolchain matching the version requirements of " - "${Rust_FIND_VERSION}. Available toolchains: ${_DISCOVERED_TOOLCHAINS}") - endif() - endif() - endif() - - set(Rust_TOOLCHAIN "${_TOOLCHAIN_SELECTED}" CACHE STRING "The rustup toolchain to use") - set_property(CACHE Rust_TOOLCHAIN PROPERTY STRINGS "${_DISCOVERED_TOOLCHAINS}") - - if(NOT Rust_FIND_QUIETLY) - message(STATUS "Rust Toolchain: ${Rust_TOOLCHAIN}") - endif() - - if (NOT Rust_TOOLCHAIN IN_LIST _DISCOVERED_TOOLCHAINS) - # If the precise toolchain wasn't found, try appending the default host - execute_process( - COMMAND - "${Rust_RUSTUP}" show - RESULT_VARIABLE _SHOW_RESULT - OUTPUT_VARIABLE _SHOW_RAW - ) - if(NOT "${_SHOW_RESULT}" EQUAL "0") - _findrust_failed("Command `${Rust_RUSTUP} show` failed") - endif() - - if (_SHOW_RAW MATCHES "Default host: ([a-zA-Z0-9_\\-]*)\n") - set(_DEFAULT_HOST "${CMAKE_MATCH_1}") - else() - _findrust_failed("Failed to parse \"Default host\" from `${Rust_RUSTUP} show`. Got: ${_SHOW_RAW}") - endif() - - if (NOT "${Rust_TOOLCHAIN}-${_DEFAULT_HOST}" IN_LIST _DISCOVERED_TOOLCHAINS) - set(_NOT_FOUND_MESSAGE "Could not find toolchain '${Rust_TOOLCHAIN}'\n" - "Available toolchains:\n" - ) - foreach(_TOOLCHAIN ${_DISCOVERED_TOOLCHAINS}) - list(APPEND _NOT_FOUND_MESSAGE " `${_TOOLCHAIN}`\n") - endforeach() - _findrust_failed(${_NOT_FOUND_MESSAGE}) - endif() - - set(_RUSTUP_TOOLCHAIN_FULL "${Rust_TOOLCHAIN}-${_DEFAULT_HOST}") - else() - set(_RUSTUP_TOOLCHAIN_FULL "${Rust_TOOLCHAIN}") - endif() - - set(_RUST_TOOLCHAIN_PATH "${_TOOLCHAIN_${_RUSTUP_TOOLCHAIN_FULL}_PATH}") - if(NOT "${Rust_FIND_QUIETLY}") - message(VERBOSE "Rust toolchain ${_RUSTUP_TOOLCHAIN_FULL}") - message(VERBOSE "Rust toolchain path ${_RUST_TOOLCHAIN_PATH}") - endif() - - # Is overridden if the user specifies `Rust_COMPILER` explicitly. - find_program( - Rust_COMPILER_CACHED - rustc - HINTS "${_RUST_TOOLCHAIN_PATH}/bin" - NO_DEFAULT_PATH) -else() - find_program(Rust_COMPILER_CACHED rustc) - if (EXISTS "${Rust_COMPILER_CACHED}") - # rustc is expected to be at `/bin/rustc`. - get_filename_component(_RUST_TOOLCHAIN_PATH "${Rust_COMPILER_CACHED}" DIRECTORY) - get_filename_component(_RUST_TOOLCHAIN_PATH "${_RUST_TOOLCHAIN_PATH}" DIRECTORY) - endif() -endif() - -if (NOT EXISTS "${Rust_COMPILER_CACHED}") - set(_NOT_FOUND_MESSAGE "The rustc executable was not found. " - "Rust not installed or ~/.cargo/bin not added to path?\n" - "Hint: Consider setting `Rust_COMPILER` to the absolute path of `rustc`." - ) - _findrust_failed(${_NOT_FOUND_MESSAGE}) -endif() - -if (_RESOLVE_RUSTUP_TOOLCHAINS) - set(_NOT_FOUND_MESSAGE "Rust was detected to be managed by rustup, but failed to find `cargo` " - "next to `rustc` in `${_RUST_TOOLCHAIN_PATH}/bin`. This can happen for custom toolchains, " - "if cargo was not built. " - "Please manually specify the path to a compatible `cargo` by setting `Rust_CARGO`." - ) - find_program( - Rust_CARGO_CACHED - cargo - HINTS "${_RUST_TOOLCHAIN_PATH}/bin" - NO_DEFAULT_PATH - ) - # note: maybe can use find_package_handle_standard_args here, if we remove the _CACHED postfix. - # not sure why that is here... - if(NOT EXISTS "${Rust_CARGO_CACHED}") - _findrust_failed(${_NOT_FOUND_MESSAGE}) - endif() - set(Rust_TOOLCHAIN_IS_RUSTUP_MANAGED TRUE CACHE INTERNAL "" FORCE) -else() - set(_NOT_FOUND_MESSAGE "Failed to find `cargo` in PATH and `${_RUST_TOOLCHAIN_PATH}/bin`.\n" - "Please ensure cargo is in PATH or manually specify the path to a compatible `cargo` by " - "setting `Rust_CARGO`." - ) - # On some systems (e.g. NixOS) cargo is not managed by rustup and also not next to rustc. - find_program( - Rust_CARGO_CACHED - cargo - HINTS "${_RUST_TOOLCHAIN_PATH}/bin" - ) - # note: maybe can use find_package_handle_standard_args here, if we remove the _CACHED postfix. - # not sure why that is here... - if(NOT EXISTS "${Rust_CARGO_CACHED}") - _findrust_failed(${_NOT_FOUND_MESSAGE}) - endif() -endif() - -execute_process( - COMMAND "${Rust_CARGO_CACHED}" --version --verbose - OUTPUT_VARIABLE _CARGO_VERSION_RAW - RESULT_VARIABLE _CARGO_VERSION_RESULT -) -# todo: check if cargo is a required component! -if(NOT ( "${_CARGO_VERSION_RESULT}" EQUAL "0" )) - _findrust_failed("Failed to get cargo version.\n" - "`${Rust_CARGO_CACHED} --version` failed with error: `${_CARGO_VERSION_RESULT}" -) -endif() - -# todo: don't set cache variables here, but let find_package_handle_standard_args do the promotion -# later. -if (_CARGO_VERSION_RAW MATCHES "cargo ([0-9]+)\\.([0-9]+)\\.([0-9]+)") - set(Rust_CARGO_VERSION_MAJOR "${CMAKE_MATCH_1}" CACHE INTERNAL "" FORCE) - set(Rust_CARGO_VERSION_MINOR "${CMAKE_MATCH_2}" CACHE INTERNAL "" FORCE) - set(Rust_CARGO_VERSION_PATCH "${CMAKE_MATCH_3}" CACHE INTERNAL "" FORCE) - set(Rust_CARGO_VERSION "${Rust_CARGO_VERSION_MAJOR}.${Rust_CARGO_VERSION_MINOR}.${Rust_CARGO_VERSION_PATCH}" CACHE INTERNAL "" FORCE) -# Workaround for the version strings where the `cargo ` prefix is missing. -elseif(_CARGO_VERSION_RAW MATCHES "([0-9]+)\\.([0-9]+)\\.([0-9]+)") - set(Rust_CARGO_VERSION_MAJOR "${CMAKE_MATCH_1}" CACHE INTERNAL "" FORCE) - set(Rust_CARGO_VERSION_MINOR "${CMAKE_MATCH_2}" CACHE INTERNAL "" FORCE) - set(Rust_CARGO_VERSION_PATCH "${CMAKE_MATCH_3}" CACHE INTERNAL "" FORCE) - set(Rust_CARGO_VERSION "${Rust_CARGO_VERSION_MAJOR}.${Rust_CARGO_VERSION_MINOR}.${Rust_CARGO_VERSION_PATCH}" CACHE INTERNAL "" FORCE) -else() - _findrust_failed( - "Failed to parse cargo version. `cargo --version` evaluated to (${_CARGO_VERSION_RAW}). " - "Expected a .. version triple." - ) -endif() - -execute_process( - COMMAND "${Rust_COMPILER_CACHED}" --version --verbose - OUTPUT_VARIABLE _RUSTC_VERSION_RAW - RESULT_VARIABLE _RUSTC_VERSION_RESULT -) - -if(NOT ( "${_RUSTC_VERSION_RESULT}" EQUAL "0" )) - _findrust_failed("Failed to get rustc version.\n" - "${Rust_COMPILER_CACHED} --version failed with error: `${_RUSTC_VERSION_RESULT}`") -endif() - -if (_RUSTC_VERSION_RAW MATCHES "rustc ([0-9]+)\\.([0-9]+)\\.([0-9]+)(-nightly)?") - set(Rust_VERSION_MAJOR "${CMAKE_MATCH_1}" CACHE INTERNAL "" FORCE) - set(Rust_VERSION_MINOR "${CMAKE_MATCH_2}" CACHE INTERNAL "" FORCE) - set(Rust_VERSION_PATCH "${CMAKE_MATCH_3}" CACHE INTERNAL "" FORCE) - set(Rust_VERSION "${Rust_VERSION_MAJOR}.${Rust_VERSION_MINOR}.${Rust_VERSION_PATCH}" CACHE INTERNAL "" FORCE) - if(CMAKE_MATCH_4) - set(Rust_IS_NIGHTLY 1 CACHE INTERNAL "" FORCE) - else() - set(Rust_IS_NIGHTLY 0 CACHE INTERNAL "" FORCE) - endif() -else() - _findrust_failed("Failed to parse rustc version. `${Rust_COMPILER_CACHED} --version --verbose` " - "evaluated to:\n`${_RUSTC_VERSION_RAW}`" - ) -endif() - -if (_RUSTC_VERSION_RAW MATCHES "host: ([a-zA-Z0-9_\\-]*)\n") - set(Rust_DEFAULT_HOST_TARGET "${CMAKE_MATCH_1}") - set(Rust_CARGO_HOST_TARGET_CACHED "${Rust_DEFAULT_HOST_TARGET}" CACHE STRING "Host triple") -else() - _findrust_failed( - "Failed to parse rustc host target. `rustc --version --verbose` evaluated to:\n${_RUSTC_VERSION_RAW}" - ) -endif() - -if (_RUSTC_VERSION_RAW MATCHES "LLVM version: ([0-9]+)\\.([0-9]+)(\\.([0-9]+))?") - set(Rust_LLVM_VERSION_MAJOR "${CMAKE_MATCH_1}" CACHE INTERNAL "" FORCE) - set(Rust_LLVM_VERSION_MINOR "${CMAKE_MATCH_2}" CACHE INTERNAL "" FORCE) - # With the Rust toolchain 1.44.1 the reported LLVM version is 9.0, i.e. without a patch version. - # Since cmake regex does not support non-capturing groups, just ignore Match 3. - set(Rust_LLVM_VERSION_PATCH "${CMAKE_MATCH_4}" CACHE INTERNAL "" FORCE) - set(Rust_LLVM_VERSION "${Rust_LLVM_VERSION_MAJOR}.${Rust_LLVM_VERSION_MINOR}.${Rust_LLVM_VERSION_PATCH}" CACHE INTERNAL "" FORCE) -elseif(NOT Rust_FIND_QUIETLY) - message( - WARNING - "Failed to parse rustc LLVM version. `rustc --version --verbose` evaluated to:\n${_RUSTC_VERSION_RAW}" - ) -endif() - -if (NOT Rust_CARGO_TARGET_CACHED) - if (WIN32) - if (CMAKE_VS_PLATFORM_NAME) - if ("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") - set(_CARGO_ARCH i686) - elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") - set(_CARGO_ARCH x86_64) - elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM64") - set(_CARGO_ARCH aarch64) - else() - message(WARNING "VS Platform '${CMAKE_VS_PLATFORM_NAME}' not recognized") - endif() - else () - if (NOT DEFINED CMAKE_SIZEOF_VOID_P) - # todo: this should only be best effort instead of failure - message( - FATAL_ERROR "Compiler hasn't been enabled yet - can't determine the target architecture") - endif() - - if (CMAKE_SIZEOF_VOID_P EQUAL 8) - set(_CARGO_ARCH x86_64) - else() - set(_CARGO_ARCH i686) - endif() - endif() - - set(_CARGO_VENDOR "pc-windows") - - if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(_CARGO_ABI gnu) - else() - set(_CARGO_ABI msvc) - endif() - - set(Rust_CARGO_TARGET_CACHED "${_CARGO_ARCH}-${_CARGO_VENDOR}-${_CARGO_ABI}" - CACHE STRING "Target triple") - elseif (ANDROID) - if (CMAKE_ANDROID_ARCH_ABI STREQUAL armeabi-v7a) - if (CMAKE_ANDROID_ARM_MODE) - set(_Rust_ANDROID_TARGET armv7-linux-androideabi) - else () - set(_Rust_ANDROID_TARGET thumbv7neon-linux-androideabi) - endif() - elseif (CMAKE_ANDROID_ARCH_ABI STREQUAL arm64-v8a) - set(_Rust_ANDROID_TARGET aarch64-linux-android) - elseif (CMAKE_ANDROID_ARCH_ABI STREQUAL x86) - set(_Rust_ANDROID_TARGET i686-linux-android) - elseif (CMAKE_ANDROID_ARCH_ABI STREQUAL x86_64) - set(_Rust_ANDROID_TARGET x86_64-linux-android) - endif() - - if (_Rust_ANDROID_TARGET) - set(Rust_CARGO_TARGET_CACHED "${_Rust_ANDROID_TARGET}" CACHE STRING "Target triple") - endif() - else() - set(Rust_CARGO_TARGET_CACHED "${Rust_DEFAULT_HOST_TARGET}" CACHE STRING "Target triple") - endif() - - message(STATUS "Rust Target: ${Rust_CARGO_TARGET_CACHED}") -endif() - -# Set the input variables as non-cache variables so that the variables are available after -# `find_package`, even if the values were evaluated to defaults. -foreach(_VAR ${_Rust_USER_VARS}) - set(${_VAR} "${${_VAR}_CACHED}") - # Ensure cached variables have type INTERNAL - set(${_VAR}_CACHED "${${_VAR}_CACHED}" CACHE INTERNAL "Internal cache of ${_VAR}") -endforeach() - -find_package_handle_standard_args( - Rust - REQUIRED_VARS Rust_COMPILER Rust_VERSION Rust_CARGO Rust_CARGO_VERSION Rust_CARGO_TARGET Rust_CARGO_HOST_TARGET - VERSION_VAR Rust_VERSION -) - - -if(NOT TARGET Rust::Rustc) - add_executable(Rust::Rustc IMPORTED GLOBAL) - set_property( - TARGET Rust::Rustc - PROPERTY IMPORTED_LOCATION "${Rust_COMPILER_CACHED}" - ) - - add_executable(Rust::Cargo IMPORTED GLOBAL) - set_property( - TARGET Rust::Cargo - PROPERTY IMPORTED_LOCATION "${Rust_CARGO_CACHED}" - ) - set(Rust_FOUND true) -endif() diff --git a/connectors/corrosion/generator/Cargo.toml b/connectors/corrosion/generator/Cargo.toml deleted file mode 100644 index 4097d969..00000000 --- a/connectors/corrosion/generator/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/connectors/corrosion/generator/src/main.rs b/connectors/corrosion/generator/src/main.rs deleted file mode 100644 index cc67024d..00000000 --- a/connectors/corrosion/generator/src/main.rs +++ /dev/null @@ -1,80 +0,0 @@ -use std::path::PathBuf; - -use cargo_metadata::Metadata; -use clap::{App, Arg}; - -mod subcommands { - pub mod gen_cmake; - pub mod print_root; -} - -use subcommands::*; - -// common options -const MANIFEST_PATH: &str = "manifest-path"; -const CARGO_EXECUTABLE: &str = "cargo-executable"; -const VERBOSE: &str = "verbose"; - -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"), - ) - .subcommand(print_root::subcommand()) - .subcommand(gen_cmake::subcommand()) - .get_matches(); - - let mut cmd = cargo_metadata::MetadataCommand::new(); - cmd.no_deps(); - - 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() { - (print_root::PRINT_ROOT, _) => print_root::invoke(&shared_args)?, - (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/connectors/corrosion/generator/src/subcommands/gen_cmake.rs b/connectors/corrosion/generator/src/subcommands/gen_cmake.rs deleted file mode 100644 index ddc23e8d..00000000 --- a/connectors/corrosion/generator/src/subcommands/gen_cmake.rs +++ /dev/null @@ -1,114 +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 PROFILE: &str = "profile"; -const CRATES: &str = "crates"; - -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(PROFILE) - .long(PROFILE) - .value_name("PROFILE") - .required(false) - .help("Custom cargo profile to select."), - ) - .arg( - Arg::with_name(OUT_FILE) - .short("o") - .long("out-file") - .value_name("FILE") - .help("Output CMake file name. Defaults to stdout."), - ) -} - -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 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| { - let package2 = package.clone(); - let ws_manifest_path = workspace_manifest_path.clone(); - package.targets.clone().into_iter().filter_map(move |t| { - target::CargoTarget::from_metadata(package2.clone(), t, ws_manifest_path.clone()) - }) - }) - .collect(); - - let cargo_profile = matches.value_of(PROFILE); - - for target in &targets { - target - .emit_cmake_target(&mut out_file, cargo_profile) - .unwrap(); - } - - writeln!(out_file)?; - - std::process::exit(0); -} diff --git a/connectors/corrosion/generator/src/subcommands/gen_cmake/target.rs b/connectors/corrosion/generator/src/subcommands/gen_cmake/target.rs deleted file mode 100644 index 9060a459..00000000 --- a/connectors/corrosion/generator/src/subcommands/gen_cmake/target.rs +++ /dev/null @@ -1,194 +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, - ) -> Option { - let target_type = if cargo_target - .kind - .iter() - .any(|k| k == "staticlib" || k == "cdylib") - { - CargoTargetType::Library { - has_staticlib: cargo_target.kind.iter().any(|k| k == "staticlib"), - has_cdylib: cargo_target.kind.iter().any(|k| k == "cdylib"), - } - } else if cargo_target.kind.iter().any(|k| k == "bin") { - CargoTargetType::Executable - } else { - return None; - }; - - Some(Self { - cargo_package, - cargo_target, - target_type, - workspace_manifest_path, - }) - } - - pub fn emit_cmake_target( - &self, - out_file: &mut dyn std::io::Write, - cargo_profile: Option<&str>, - ) -> Result<(), Box> { - let cargo_build_profile_option = if let Some(profile) = cargo_profile { - format!("PROFILE \"{}\"", profile) - } else { - String::default() - }; - - 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("\\", "/"); - - writeln!( - out_file, - " - _corrosion_add_library_target(\"{workspace_manifest_path}\" - \"{target_name}\" - \"{has_staticlib}\" - \"{has_cdylib}\" - archive_byproducts - shared_lib_byproduct - pdb_byproduct - ) - list(APPEND byproducts - \"${{archive_byproducts}}\" - \"${{shared_lib_byproduct}}\" - \"${{pdb_byproduct}}\" - ) - ", - workspace_manifest_path = ws_manifest, - target_name = self.cargo_target.name, - has_staticlib = has_staticlib, - has_cdylib = has_cdylib, - )?; - } - 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}\" - {profile_option} - TARGET_KINDS {target_kinds} - BYPRODUCTS \"${{byproducts}}\" - ) - - 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, - profile_option = cargo_build_profile_option, - target_kinds = target_kinds, - - )?; - Ok(()) - } -} diff --git a/connectors/corrosion/generator/src/subcommands/print_root.rs b/connectors/corrosion/generator/src/subcommands/print_root.rs deleted file mode 100644 index 938e534d..00000000 --- a/connectors/corrosion/generator/src/subcommands/print_root.rs +++ /dev/null @@ -1,14 +0,0 @@ -use clap::{App, SubCommand}; - -// Subcommand Name -pub const PRINT_ROOT: &str = "print-root"; - -pub fn subcommand() -> App<'static, 'static> { - SubCommand::with_name(PRINT_ROOT) -} - -pub fn invoke(args: &crate::GeneratorSharedArgs) -> Result<(), Box> { - println!("{}", args.metadata.workspace_root); - - std::process::exit(0); -} diff --git a/connectors/corrosion/test/CMakeLists.txt b/connectors/corrosion/test/CMakeLists.txt deleted file mode 100644 index f344cb5c..00000000 --- a/connectors/corrosion/test/CMakeLists.txt +++ /dev/null @@ -1,124 +0,0 @@ -# This option is currently used to prevent recursion -option(CORROSION_TESTS "Enable Corrosion tests" ON) -mark_as_advanced(CORROSION_TESTS) -if(NOT CORROSION_TESTS) - return() -endif() - -set(test_install_path "${CMAKE_CURRENT_BINARY_DIR}/test-install-corrosion") - -set(test_header_contents - "option(CORROSION_TESTS_FIND_CORROSION \"Use Corrosion as a subdirectory\" OFF)" - "if (CORROSION_TESTS_FIND_CORROSION)" - " set(CMAKE_PREFIX_PATH \"${test_install_path}\" CACHE INTERNAL \"\" FORCE)" - " find_package(Corrosion REQUIRED PATHS \"${test_install_path}\" NO_CMAKE_SYSTEM_PATH)" - "else()" - " add_subdirectory(\"${CMAKE_CURRENT_SOURCE_DIR}/..\" corrosion)" - "endif()" -) - -string(REPLACE ";" "\n" test_header_contents "${test_header_contents}") - -file(WRITE test_header.cmake "${test_header_contents}") - -option(CORROSION_TESTS_INSTALL_CORROSION - "Install Corrosion to a test directory and let tests use the installed Corrosion" - OFF) -if(CORROSION_TESTS_INSTALL_CORROSION) - add_test(NAME "install_corrosion_configure" - COMMAND - ${CMAKE_COMMAND} - -S "${CMAKE_CURRENT_SOURCE_DIR}/.." - -B "${CMAKE_CURRENT_BINARY_DIR}/build-corrosion" - -DCORROSION_VERBOSE_OUTPUT=ON - -DCORROSION_TESTS=OFF - -DCMAKE_BUILD_TYPE=Release - "-DCMAKE_INSTALL_PREFIX=${test_install_path}" - ) - add_test(NAME "install_corrosion_build" - COMMAND - ${CMAKE_COMMAND} --build "${CMAKE_CURRENT_BINARY_DIR}/build-corrosion" --config Release - ) - add_test(NAME "install_corrosion_install" - COMMAND - ${CMAKE_COMMAND} --install "${CMAKE_CURRENT_BINARY_DIR}/build-corrosion" --config Release - ) - set_tests_properties("install_corrosion_configure" PROPERTIES FIXTURES_SETUP "fixture_corrosion_configure") - set_tests_properties("install_corrosion_build" PROPERTIES FIXTURES_SETUP "fixture_corrosion_build") - set_tests_properties("install_corrosion_build" PROPERTIES FIXTURES_REQUIRED "fixture_corrosion_configure") - set_tests_properties("install_corrosion_install" PROPERTIES FIXTURES_REQUIRED "install_corrosion_build") - set_tests_properties("install_corrosion_install" PROPERTIES FIXTURES_SETUP "fixture_corrosion_install") -endif() - -function(corrosion_tests_add_test test_name bin_names) -# In the future we could add multiple tests here for different configurations (generator, build mode, rust version ...) -# which would allow us to simplify the github job matrix - - if(CMAKE_C_COMPILER) - set(TEST_C_COMPILER "C_COMPILER" "${CMAKE_C_COMPILER}") - endif() - if(CMAKE_CXX_COMPILER) - set(TEST_CXX_COMPILER "CXX_COMPILER" "${CMAKE_CXX_COMPILER}") - endif() - if(CMAKE_GENERATOR_PLATFORM) - set(TEST_GENERATOR_PLATFORM "GENERATOR_PLATFORM" "${CMAKE_GENERATOR_PLATFORM}") - endif() - - add_test(NAME "${test_name}_build" - COMMAND - ${CMAKE_COMMAND} - -P "${CMAKE_SOURCE_DIR}/test/ConfigureAndBuild.cmake" - SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/${test_name}" - BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/build" - GENERATOR "${CMAKE_GENERATOR}" - RUST_TOOLCHAIN "${Rust_TOOLCHAIN}" - CARGO_TARGET "${Rust_CARGO_TARGET}" - SYSTEM_NAME "${CMAKE_SYSTEM_NAME}" - "${TEST_C_COMPILER}" - "${TEST_CXX_COMPILER}" - "${TEST_GENERATOR_PLATFORM}" - - COMMAND_EXPAND_LISTS - ) - set_tests_properties("${test_name}_build" PROPERTIES FIXTURES_SETUP "build_fixture_${test_name}") - if(CORROSION_TESTS_INSTALL_CORROSION) - set_tests_properties("${test_name}_build" PROPERTIES FIXTURES_REQUIRED "fixture_corrosion_install") - endif() - foreach(bin ${bin_names}) - if(WIN32) - set(bin_filename "${bin}.exe") - else() - set(bin_filename "${bin}") - endif() - add_test(NAME "${test_name}_run_${bin}" COMMAND "${CMAKE_CURRENT_BINARY_DIR}/build/${bin_filename}") - set_tests_properties("${test_name}_run_${bin}" PROPERTIES FIXTURES_REQUIRED "build_fixture_${test_name}") - # CMAKE_CROSSCOMPILING is not set when cross-compiling with VS (via -A flag). - # Todo: We could run x86 binaries on x64 hosts. - if(CMAKE_CROSSCOMPILING OR CMAKE_VS_PLATFORM_NAME) - # Todo: In the future we could potentially run some tests with qemu. - set_tests_properties("${test_name}_run_${bin}" PROPERTIES DISABLED TRUE) - endif() - endforeach() -endfunction() - -# Please keep this in alphabetical order. -add_subdirectory(cargo_flags) -add_subdirectory(cpp2rust) -if(Rust_VERSION VERSION_GREATER_EQUAL "1.64.0" AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.19.0") - # Flag `--crate-type` is only supported since Rust 1.64.0 - add_subdirectory(crate_type) -endif() -add_subdirectory(custom_profiles) -add_subdirectory(envvar) -add_subdirectory(external_corrosion_generator) -add_subdirectory(features) -add_subdirectory(find_rust) -add_subdirectory(gensource) -add_subdirectory(hostbuild) -add_subdirectory(multitarget) -add_subdirectory(nostd) -add_subdirectory("output directory") -add_subdirectory(parse_target_triple) -add_subdirectory(rust2cpp) -add_subdirectory(rustflags) -add_subdirectory(workspace) diff --git a/connectors/corrosion/test/ConfigureAndBuild.cmake b/connectors/corrosion/test/ConfigureAndBuild.cmake deleted file mode 100644 index ff310e83..00000000 --- a/connectors/corrosion/test/ConfigureAndBuild.cmake +++ /dev/null @@ -1,107 +0,0 @@ -# CMake script to configure and build a test project - -set(TEST_ARG_LIST) - -# Expect actual arguments to start at index 3 (cmake -P ) -foreach(ARG_INDEX RANGE 3 ${CMAKE_ARGC}) - list(APPEND TEST_ARG_LIST "${CMAKE_ARGV${ARG_INDEX}}") -endforeach() - -set(options "USE_INSTALLED_CORROSION") -set(oneValueArgs - SOURCE_DIR - BINARY_DIR - GENERATOR - GENERATOR_PLATFORM - RUST_TOOLCHAIN - CARGO_TARGET - C_COMPILER - CXX_COMPILER - SYSTEM_NAME - EXTERNAL_CORROSION_GENERATOR -) -set(multiValueArgs "") -cmake_parse_arguments(TEST "${options}" "${oneValueArgs}" - "${multiValueArgs}" ${TEST_ARG_LIST} ) - -if(TEST_CARGO_TARGET) - set(TEST_Rust_CARGO_TARGET "-DRust_CARGO_TARGET=${TEST_CARGO_TARGET}") -endif() -if(TEST_USE_INSTALLED_CORROSION) - set(TEST_CORROSION_INSTALL "-DCORROSION_TESTS_FIND_CORROSION=ON") -endif() -if(TEST_GENERATOR_PLATFORM) - set(TEST_GENERATOR_PLATFORM "-A${TEST_GENERATOR_PLATFORM}") -endif() -if(TEST_C_COMPILER) - set(TEST_C_COMPILER "-DCMAKE_C_COMPILER=${TEST_C_COMPILER}") -endif() -if(TEST_CXX_COMPILER) - set(TEST_CXX_COMPILER "-DCMAKE_CXX_COMPILER=${TEST_CXX_COMPILER}") -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() - -# Remove old binary directory -file(REMOVE_RECURSE "${TEST_BINARY_DIR}") - -file(MAKE_DIRECTORY "${TEST_BINARY_DIR}") - -message(STATUS "TEST_BINARY_DIRECTORY: ${TEST_BINARY_DIR}") - -execute_process( - COMMAND - "${CMAKE_COMMAND}" - "-G${TEST_GENERATOR}" - "-DRust_TOOLCHAIN=${TEST_RUST_TOOLCHAIN}" - ${TEST_Rust_CARGO_TARGET} - ${TEST_CORROSION_INSTALL} - ${TEST_GENERATOR_PLATFORM} - ${TEST_C_COMPILER} - ${TEST_CXX_COMPILER} - ${TEST_SYSTEM_NAME} - ${TEST_EXTERNAL_CORROSION_GENERATOR} - -S "${TEST_SOURCE_DIR}" - -B "${TEST_BINARY_DIR}" - COMMAND_ECHO STDOUT - RESULT_VARIABLE EXIT_CODE -) - -if (NOT "${EXIT_CODE}" EQUAL 0) - message(FATAL_ERROR "Configure step failed. Exit code: `${EXIT_CODE}`") -endif() - -if ("${TEST_GENERATOR}" STREQUAL "Ninja Multi-Config" - OR "${TEST_GENERATOR}" MATCHES "Visual Studio" - ) - foreach(config Debug Release RelWithDebInfo) - execute_process( - COMMAND "${CMAKE_COMMAND}" - --build "${TEST_BINARY_DIR}" - --config "${config}" - COMMAND_ECHO STDOUT - RESULT_VARIABLE EXIT_CODE - ) - if (NOT "${EXIT_CODE}" EQUAL 0) - message(FATAL_ERROR "Build step failed for config `${config}`. " - "Exit code: `${EXIT_CODE}`") - endif() - endforeach() -else() - execute_process( - COMMAND "${CMAKE_COMMAND}" --build "${TEST_BINARY_DIR}" - COMMAND_ECHO STDOUT - RESULT_VARIABLE EXIT_CODE - ) - if (NOT "${EXIT_CODE}" EQUAL 0) - message(FATAL_ERROR "Build step failed. Exit code: `${EXIT_CODE}`") - endif() -endif() - - diff --git a/connectors/corrosion/test/README.md b/connectors/corrosion/test/README.md deleted file mode 100644 index df481588..00000000 --- a/connectors/corrosion/test/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Corrosion Tests - -Corrosions tests are run via ctest. The tests themselves utilize CMake script mode -to configure and build a test project, which allows for great flexibility. -Using ctest properties such as `PASS_REGULAR_EXPRESSION` or `FAIL_REGULAR_EXPRESSION` -can be used to confirm that built executable targets run as expected, but can also -be used to fail tests if Corrosion warnings appear in the configure output. \ No newline at end of file diff --git a/connectors/corrosion/test/cargo_flags/CMakeLists.txt b/connectors/corrosion/test/cargo_flags/CMakeLists.txt deleted file mode 100644 index 0707f3a5..00000000 --- a/connectors/corrosion/test/cargo_flags/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -corrosion_tests_add_test(cargo_flags "flags-exe") - -set_tests_properties("cargo_flags_run_flags-exe" PROPERTIES PASS_REGULAR_EXPRESSION [[Hello, Cxx! I am Rust!]]) diff --git a/connectors/corrosion/test/cargo_flags/cargo_flags/CMakeLists.txt b/connectors/corrosion/test/cargo_flags/cargo_flags/CMakeLists.txt deleted file mode 100644 index 90b3d248..00000000 --- a/connectors/corrosion/test/cargo_flags/cargo_flags/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml FLAGS --features one) - -add_executable(flags-exe main.cpp) -target_link_libraries(flags-exe PUBLIC flags-lib) -corrosion_set_cargo_flags(flags-lib --features two) -corrosion_set_cargo_flags(flags-lib $) - -set_property( - TARGET flags-lib - APPEND - PROPERTY more_flags --features three -) diff --git a/connectors/corrosion/test/cargo_flags/cargo_flags/main.cpp b/connectors/corrosion/test/cargo_flags/cargo_flags/main.cpp deleted file mode 100644 index b5fde3cf..00000000 --- a/connectors/corrosion/test/cargo_flags/cargo_flags/main.cpp +++ /dev/null @@ -1,6 +0,0 @@ -extern "C" void rust_function(char const *name); - - -int main(int argc, char **argv) { - rust_function("Cxx"); -} diff --git a/connectors/corrosion/test/cargo_flags/cargo_flags/rust/Cargo.toml b/connectors/corrosion/test/cargo_flags/cargo_flags/rust/Cargo.toml deleted file mode 100644 index 479ff413..00000000 --- a/connectors/corrosion/test/cargo_flags/cargo_flags/rust/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "flags-lib" -version = "0.1.0" -edition = "2018" - -[lib] -crate-type=["staticlib"] - -[features] - -one = [] -two = [] -three = [] diff --git a/connectors/corrosion/test/cargo_flags/cargo_flags/rust/src/lib.rs b/connectors/corrosion/test/cargo_flags/cargo_flags/rust/src/lib.rs deleted file mode 100644 index 7afea31a..00000000 --- a/connectors/corrosion/test/cargo_flags/cargo_flags/rust/src/lib.rs +++ /dev/null @@ -1,14 +0,0 @@ -use std::os::raw::c_char; - -#[no_mangle] -pub extern "C" fn rust_function(name: *const c_char) { - let name = unsafe { std::ffi::CStr::from_ptr(name).to_str().unwrap() }; - println!("Hello, {}! I am Rust!", name); - - #[cfg(not(feature = "one"))] - compile_error!("Feature one is not enabled"); - #[cfg(not(feature = "two"))] - compile_error!("Feature two is not enabled"); - #[cfg(not(feature = "three"))] - compile_error!("Feature three is not enabled"); -} diff --git a/connectors/corrosion/test/cpp2rust/CMakeLists.txt b/connectors/corrosion/test/cpp2rust/CMakeLists.txt deleted file mode 100644 index 5b4cb46d..00000000 --- a/connectors/corrosion/test/cpp2rust/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -corrosion_tests_add_test(cpp2rust "rust-exe") - -set_tests_properties("cpp2rust_run_rust-exe" PROPERTIES PASS_REGULAR_EXPRESSION - "Hello, Rust! I am Cpp!\r?\nHello, Rust! I am Cpp library Number 2!\r?\nHello, Rust! I am Cpp library Number 3!" - ) diff --git a/connectors/corrosion/test/cpp2rust/cpp2rust/CMakeLists.txt b/connectors/corrosion/test/cpp2rust/cpp2rust/CMakeLists.txt deleted file mode 100644 index 2a6fe134..00000000 --- a/connectors/corrosion/test/cpp2rust/cpp2rust/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml) - -add_library(cpp-lib lib.cpp) -target_compile_features(cpp-lib PRIVATE cxx_std_14) -set_target_properties( - cpp-lib - PROPERTIES - POSITION_INDEPENDENT_CODE ON -) - -add_library(cpp-lib2 lib2.cpp) -target_compile_features(cpp-lib2 PRIVATE cxx_std_14) -set_target_properties( - cpp-lib2 - PROPERTIES - POSITION_INDEPENDENT_CODE ON - OUTPUT_NAME cpp-lib-renamed -) - -add_library(cpp-lib3 "path with space/lib3.cpp" ) -target_compile_features(cpp-lib3 PRIVATE cxx_std_14) -set_target_properties( - cpp-lib3 - PROPERTIES - POSITION_INDEPENDENT_CODE ON -) - -corrosion_link_libraries(rust-exe cpp-lib cpp-lib2 cpp-lib3) diff --git a/connectors/corrosion/test/cpp2rust/cpp2rust/lib.cpp b/connectors/corrosion/test/cpp2rust/cpp2rust/lib.cpp deleted file mode 100644 index df7642d2..00000000 --- a/connectors/corrosion/test/cpp2rust/cpp2rust/lib.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include - -extern "C" void cpp_function(char const *name) { - std::cout << "Hello, " << name << "! I am Cpp!\n"; -} diff --git a/connectors/corrosion/test/cpp2rust/cpp2rust/lib2.cpp b/connectors/corrosion/test/cpp2rust/cpp2rust/lib2.cpp deleted file mode 100644 index 63a33518..00000000 --- a/connectors/corrosion/test/cpp2rust/cpp2rust/lib2.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -extern "C" void cpp_function2(char const *name) { - std::cout << "Hello, " << name << "! I am Cpp library Number 2!\n"; -} - -extern "C" uint32_t get_42() { - uint32_t v = 42; - return v; -} diff --git a/connectors/corrosion/test/cpp2rust/cpp2rust/path with space/lib3.cpp b/connectors/corrosion/test/cpp2rust/cpp2rust/path with space/lib3.cpp deleted file mode 100644 index d09ddc87..00000000 --- a/connectors/corrosion/test/cpp2rust/cpp2rust/path with space/lib3.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// Check that libraries located at a path containing a space can also be linked. - -#include - -extern "C" void cpp_function3(char const *name) { - std::cout << "Hello, " << name << "! I am Cpp library Number 3!\n"; -} - diff --git a/connectors/corrosion/test/cpp2rust/cpp2rust/rust/Cargo.toml b/connectors/corrosion/test/cpp2rust/cpp2rust/rust/Cargo.toml deleted file mode 100644 index 21bfb64f..00000000 --- a/connectors/corrosion/test/cpp2rust/cpp2rust/rust/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "rust-exe" -version = "0.1.0" -authors = ["Andrew Gaspar "] -license = "MIT" -edition = "2018" - -[dependencies] -rust-dependency = { path = "rust_dependency" } diff --git a/connectors/corrosion/test/cpp2rust/cpp2rust/rust/rust_dependency/Cargo.toml b/connectors/corrosion/test/cpp2rust/cpp2rust/rust/rust_dependency/Cargo.toml deleted file mode 100644 index 89acbbea..00000000 --- a/connectors/corrosion/test/cpp2rust/cpp2rust/rust/rust_dependency/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "rust-dependency" -version = "0.1.0" -license = "MIT" -edition = "2018" - -[dependencies] - diff --git a/connectors/corrosion/test/cpp2rust/cpp2rust/rust/rust_dependency/src/lib.rs b/connectors/corrosion/test/cpp2rust/cpp2rust/rust/rust_dependency/src/lib.rs deleted file mode 100644 index 304cfb90..00000000 --- a/connectors/corrosion/test/cpp2rust/cpp2rust/rust/rust_dependency/src/lib.rs +++ /dev/null @@ -1,8 +0,0 @@ - -extern "C" { - fn get_42() -> u32; -} -pub fn calls_ffi() { - let res = unsafe { get_42()}; - assert_eq!(res, 42); -} diff --git a/connectors/corrosion/test/cpp2rust/cpp2rust/rust/src/bin/rust-exe.rs b/connectors/corrosion/test/cpp2rust/cpp2rust/rust/src/bin/rust-exe.rs deleted file mode 100644 index 43950e7e..00000000 --- a/connectors/corrosion/test/cpp2rust/cpp2rust/rust/src/bin/rust-exe.rs +++ /dev/null @@ -1,27 +0,0 @@ -use std::os::raw::c_char; - -extern "C" { - fn cpp_function(name: *const c_char); - fn cpp_function2(name: *const c_char); - fn cpp_function3(name: *const c_char); - -} - -fn greeting(name: &str) { - let name = std::ffi::CString::new(name).unwrap(); - unsafe { - cpp_function(name.as_ptr()); - cpp_function2(name.as_ptr()); - cpp_function3(name.as_ptr()); - } -} - -fn main() { - let args = std::env::args().skip(1).collect::>(); - if args.len() >= 1 { - greeting(&args[0]); - } else { - greeting("Rust"); - } - rust_dependency::calls_ffi(); -} diff --git a/connectors/corrosion/test/crate_type/CMakeLists.txt b/connectors/corrosion/test/crate_type/CMakeLists.txt deleted file mode 100644 index 771cc197..00000000 --- a/connectors/corrosion/test/crate_type/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -corrosion_tests_add_test(crate_type "cpp-exe") - - -set_tests_properties("crate_type_run_cpp-exe" PROPERTIES PASS_REGULAR_EXPRESSION - "Hello from lib 1!\r?\nHello from lib 2!" - ) diff --git a/connectors/corrosion/test/crate_type/crate_type/CMakeLists.txt b/connectors/corrosion/test/crate_type/crate_type/CMakeLists.txt deleted file mode 100644 index 281d5c4f..00000000 --- a/connectors/corrosion/test/crate_type/crate_type/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -# Add --crate-type to ensure that only the specified type of library is built and no error is thrown -corrosion_import_crate(MANIFEST_PATH proj1/Cargo.toml CRATE_TYPES staticlib FLAGS --crate-type=staticlib) -corrosion_import_crate(MANIFEST_PATH proj2/Cargo.toml CRATE_TYPES cdylib FLAGS --crate-type=cdylib) - -add_executable(cpp-exe main.cpp) -target_link_libraries(cpp-exe proj1) -target_link_libraries(cpp-exe proj2) diff --git a/connectors/corrosion/test/crate_type/crate_type/main.cpp b/connectors/corrosion/test/crate_type/crate_type/main.cpp deleted file mode 100644 index 65113193..00000000 --- a/connectors/corrosion/test/crate_type/crate_type/main.cpp +++ /dev/null @@ -1,8 +0,0 @@ -extern "C" void rust_function1(); -extern "C" void rust_function2(); - -int main() { - rust_function1(); - rust_function2(); - return 0; -} diff --git a/connectors/corrosion/test/crate_type/crate_type/proj1/Cargo.toml b/connectors/corrosion/test/crate_type/crate_type/proj1/Cargo.toml deleted file mode 100644 index 81ad88ff..00000000 --- a/connectors/corrosion/test/crate_type/crate_type/proj1/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "proj1" -version = "0.1.0" -edition = "2018" - -[dependencies] - -[lib] -crate-type=["staticlib", "cdylib"] - diff --git a/connectors/corrosion/test/crate_type/crate_type/proj1/src/lib.rs b/connectors/corrosion/test/crate_type/crate_type/proj1/src/lib.rs deleted file mode 100644 index 43352190..00000000 --- a/connectors/corrosion/test/crate_type/crate_type/proj1/src/lib.rs +++ /dev/null @@ -1,4 +0,0 @@ -#[no_mangle] -pub extern "C" fn rust_function1() { - println!("Hello from lib 1!"); -} diff --git a/connectors/corrosion/test/crate_type/crate_type/proj2/Cargo.toml b/connectors/corrosion/test/crate_type/crate_type/proj2/Cargo.toml deleted file mode 100644 index 74c7d617..00000000 --- a/connectors/corrosion/test/crate_type/crate_type/proj2/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "proj2" -version = "0.1.0" -edition = "2018" - -[dependencies] - -[lib] -crate-type=["staticlib", "cdylib"] diff --git a/connectors/corrosion/test/crate_type/crate_type/proj2/src/lib.rs b/connectors/corrosion/test/crate_type/crate_type/proj2/src/lib.rs deleted file mode 100644 index 23048680..00000000 --- a/connectors/corrosion/test/crate_type/crate_type/proj2/src/lib.rs +++ /dev/null @@ -1,4 +0,0 @@ -#[no_mangle] -pub extern "C" fn rust_function2() { - println!("Hello from lib 2!"); -} diff --git a/connectors/corrosion/test/custom_profiles/CMakeLists.txt b/connectors/corrosion/test/custom_profiles/CMakeLists.txt deleted file mode 100644 index e43b140a..00000000 --- a/connectors/corrosion/test/custom_profiles/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -corrosion_tests_add_test(custom_profiles "custom-profile-exe") - -set_tests_properties("custom_profiles_run_custom-profile-exe" PROPERTIES PASS_REGULAR_EXPRESSION - "^Hello, Cpp! I'm Rust!\r?\n$" - ) -if(Rust_VERSION VERSION_LESS 1.57.0) - set_tests_properties(custom_profiles_build custom_profiles_run_custom-profile-exe PROPERTIES - DISABLED TRUE - ) -endif() diff --git a/connectors/corrosion/test/custom_profiles/custom_profiles/CMakeLists.txt b/connectors/corrosion/test/custom_profiles/custom_profiles/CMakeLists.txt deleted file mode 100644 index 9a959fcf..00000000 --- a/connectors/corrosion/test/custom_profiles/custom_profiles/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -set(_release_profile $,release-without-dbg,custom-without-dbg>) -set(custom_profile $,dev-without-dbg,${_release_profile}>) - -corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml PROFILE ${custom_profile}) - -add_executable(custom-profile-exe main.cpp) -target_link_libraries(custom-profile-exe PUBLIC custom-profiles-lib) diff --git a/connectors/corrosion/test/custom_profiles/custom_profiles/main.cpp b/connectors/corrosion/test/custom_profiles/custom_profiles/main.cpp deleted file mode 100644 index b714e76e..00000000 --- a/connectors/corrosion/test/custom_profiles/custom_profiles/main.cpp +++ /dev/null @@ -1,6 +0,0 @@ -extern "C" void rust_function(char const *name); - - -int main(int argc, char **argv) { - rust_function("Cpp"); -} diff --git a/connectors/corrosion/test/custom_profiles/custom_profiles/rust/Cargo.toml b/connectors/corrosion/test/custom_profiles/custom_profiles/rust/Cargo.toml deleted file mode 100644 index 93e3c759..00000000 --- a/connectors/corrosion/test/custom_profiles/custom_profiles/rust/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "custom-profiles-lib" -version = "0.1.0" -edition = "2021" - -[lib] -crate-type=["staticlib"] - -# Test if neither release or debug where selected by only disabling debug-assertions in the inherited profile. -[profile.release] -debug-assertions = true - -[profile.dev-without-dbg] -inherits = "dev" -debug-assertions = false - -[profile.release-without-dbg] -inherits = "release" -debug-assertions = false - -[profile.custom-without-dbg] -inherits = "release" -opt-level = 1 -debug-assertions = false diff --git a/connectors/corrosion/test/custom_profiles/custom_profiles/rust/src/lib.rs b/connectors/corrosion/test/custom_profiles/custom_profiles/rust/src/lib.rs deleted file mode 100644 index ee3f4b01..00000000 --- a/connectors/corrosion/test/custom_profiles/custom_profiles/rust/src/lib.rs +++ /dev/null @@ -1,11 +0,0 @@ -use std::os::raw::c_char; - -#[no_mangle] -pub extern "C" fn rust_function(name: *const c_char) { - let name = unsafe { std::ffi::CStr::from_ptr(name).to_str().unwrap() }; - println!("Hello, {}! I'm Rust!", name); -} - - -#[cfg(debug_assertions)] -const _: () = assert!(false, "Debug assertions where not disabled via custom profile!"); diff --git a/connectors/corrosion/test/envvar/CMakeLists.txt b/connectors/corrosion/test/envvar/CMakeLists.txt deleted file mode 100644 index 8762eda6..00000000 --- a/connectors/corrosion/test/envvar/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -corrosion_tests_add_test(envvar "program_requiring_rust_lib_with_envvar") - -set_tests_properties("envvar_run_program_requiring_rust_lib_with_envvar" PROPERTIES PASS_REGULAR_EXPRESSION - "Ok" - ) diff --git a/connectors/corrosion/test/envvar/envvar/CMakeLists.txt b/connectors/corrosion/test/envvar/envvar/CMakeLists.txt deleted file mode 100644 index 20cdd655..00000000 --- a/connectors/corrosion/test/envvar/envvar/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -corrosion_import_crate(MANIFEST_PATH Cargo.toml) - -corrosion_set_env_vars(rust-lib-requiring-envvar - "ANOTHER_VARIABLE=ANOTHER_VALUE" - "$" - "COR_CARGO_VERSION_MAJOR=${Rust_CARGO_VERSION_MAJOR}" - "COR_CARGO_VERSION_MINOR=${Rust_CARGO_VERSION_MINOR}" -) - -add_executable(program_requiring_rust_lib_with_envvar main.cpp) - -set_property( - TARGET program_requiring_rust_lib_with_envvar - APPEND - PROPERTY INDIRECT_VAR_TEST - "REQUIRED_VARIABLE=EXPECTED_VALUE" -) - -target_link_libraries(program_requiring_rust_lib_with_envvar PUBLIC rust-lib-requiring-envvar) diff --git a/connectors/corrosion/test/envvar/envvar/Cargo.toml b/connectors/corrosion/test/envvar/envvar/Cargo.toml deleted file mode 100644 index e74e08bf..00000000 --- a/connectors/corrosion/test/envvar/envvar/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "rust-lib-requiring-envvar" -version = "0.1.0" -authors = ["Olivier Goffart "] -edition = "2018" -build = "build.rs" - -[lib] -crate-type = [ "lib", "cdylib" ] diff --git a/connectors/corrosion/test/envvar/envvar/build.rs b/connectors/corrosion/test/envvar/envvar/build.rs deleted file mode 100644 index 4c173db3..00000000 --- a/connectors/corrosion/test/envvar/envvar/build.rs +++ /dev/null @@ -1,18 +0,0 @@ -fn main() { - assert_eq!(env!("REQUIRED_VARIABLE"), "EXPECTED_VALUE"); - assert_eq!(std::env::var("ANOTHER_VARIABLE").unwrap(), "ANOTHER_VALUE"); - let cargo_major = env!("COR_CARGO_VERSION_MAJOR") - .parse::() - .expect("Invalid Major version"); - let cargo_minor = env!("COR_CARGO_VERSION_MINOR") - .parse::() - .expect("Invalid Minor version"); - - // The `[env]` section in `.cargo/config.toml` was added in version 1.56. - if cargo_major > 1 || (cargo_major == 1 && cargo_minor >= 56) { - // Check if cargo picks up the config.toml, which sets this additional env variable. - let env_value = option_env!("COR_CONFIG_TOML_ENV_VAR") - .expect("Test failure! Cargo >= 1.56.0 should set this environment variable"); - assert_eq!(env_value, "EnvVariableSetViaConfig.toml"); - } -} diff --git a/connectors/corrosion/test/envvar/envvar/main.cpp b/connectors/corrosion/test/envvar/envvar/main.cpp deleted file mode 100644 index 5af40544..00000000 --- a/connectors/corrosion/test/envvar/envvar/main.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include - -int main() { - std::cout << "Ok"; -} diff --git a/connectors/corrosion/test/envvar/envvar/src/lib.rs b/connectors/corrosion/test/envvar/envvar/src/lib.rs deleted file mode 100644 index 31e1bb20..00000000 --- a/connectors/corrosion/test/envvar/envvar/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } -} diff --git a/connectors/corrosion/test/external_corrosion_generator/CMakeLists.txt b/connectors/corrosion/test/external_corrosion_generator/CMakeLists.txt deleted file mode 100644 index 954f21f8..00000000 --- a/connectors/corrosion/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/connectors/corrosion/test/external_corrosion_generator/ExternalCorrosionGenerator/CMakeLists.txt b/connectors/corrosion/test/external_corrosion_generator/ExternalCorrosionGenerator/CMakeLists.txt deleted file mode 100644 index 69f9b283..00000000 --- a/connectors/corrosion/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/connectors/corrosion/test/external_corrosion_generator/ExternalCorrosionGenerator/Test.cmake b/connectors/corrosion/test/external_corrosion_generator/ExternalCorrosionGenerator/Test.cmake deleted file mode 100644 index e92b812e..00000000 --- a/connectors/corrosion/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/connectors/corrosion/test/features/CMakeLists.txt b/connectors/corrosion/test/features/CMakeLists.txt deleted file mode 100644 index d1d0a7a0..00000000 --- a/connectors/corrosion/test/features/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -corrosion_tests_add_test(features "features-cpp-exe") - -set_tests_properties("features_run_features-cpp-exe" PROPERTIES PASS_REGULAR_EXPRESSION - "Hello, Cpp! I'm Rust!\r?\nHello, Cpp again! I'm Rust again!\r?\nHello, Cpp again! I'm Rust again, third time the charm!" - ) diff --git a/connectors/corrosion/test/features/features/CMakeLists.txt b/connectors/corrosion/test/features/features/CMakeLists.txt deleted file mode 100644 index a3d5b865..00000000 --- a/connectors/corrosion/test/features/features/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml FEATURES thirdfeature ALL_FEATURES) - -add_executable(features-cpp-exe main.cpp) -target_link_libraries(features-cpp-exe PUBLIC rust-feature-lib) - -corrosion_set_features(rust-feature-lib - ALL_FEATURES OFF - NO_DEFAULT_FEATURES - FEATURES - $ -) - -set_property( - TARGET features-cpp-exe - APPEND - PROPERTY app_features myfeature -) -set_property( - TARGET features-cpp-exe - APPEND - PROPERTY app_features secondfeature -) - diff --git a/connectors/corrosion/test/features/features/main.cpp b/connectors/corrosion/test/features/features/main.cpp deleted file mode 100644 index 0b9b1b92..00000000 --- a/connectors/corrosion/test/features/features/main.cpp +++ /dev/null @@ -1,13 +0,0 @@ -extern "C" void rust_function(char const *name); -extern "C" void rust_second_function(char const *name); -extern "C" void rust_third_function(char const *name); - -int main(int argc, char **argv) { - if (argc < 2) { - rust_function("Cpp"); - rust_second_function("Cpp again"); - rust_third_function("Cpp again"); - } else { - rust_function(argv[1]); - } -} diff --git a/connectors/corrosion/test/features/features/rust/Cargo.toml b/connectors/corrosion/test/features/features/rust/Cargo.toml deleted file mode 100644 index 977dc534..00000000 --- a/connectors/corrosion/test/features/features/rust/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "rust-feature-lib" -version = "0.1.0" -authors = ["Andrew Gaspar "] -license = "MIT" -edition = "2018" - -[dependencies] - -[lib] -crate-type=["staticlib"] - -[features] -default = ["compile-breakage"] -myfeature = [] -secondfeature = [] -thirdfeature = [] -compile-breakage = [] \ No newline at end of file diff --git a/connectors/corrosion/test/features/features/rust/src/lib.rs b/connectors/corrosion/test/features/features/rust/src/lib.rs deleted file mode 100644 index 7c5c6d64..00000000 --- a/connectors/corrosion/test/features/features/rust/src/lib.rs +++ /dev/null @@ -1,26 +0,0 @@ -#[cfg(feature = "myfeature")] -use std::os::raw::c_char; - -#[no_mangle] -#[cfg(feature = "myfeature")] -pub extern "C" fn rust_function(name: *const c_char) { - let name = unsafe { std::ffi::CStr::from_ptr(name).to_str().unwrap() }; - println!("Hello, {}! I'm Rust!", name); -} - -#[no_mangle] -#[cfg(feature = "secondfeature")] -pub extern "C" fn rust_second_function(name: *const c_char) { - let name = unsafe { std::ffi::CStr::from_ptr(name).to_str().unwrap() }; - println!("Hello, {}! I'm Rust again!", name); -} - -#[no_mangle] -#[cfg(feature = "thirdfeature")] -pub extern "C" fn rust_third_function(name: *const c_char) { - let name = unsafe { std::ffi::CStr::from_ptr(name).to_str().unwrap() }; - println!("Hello, {}! I'm Rust again, third time the charm!", name); -} - -#[cfg(feature = "compile-breakage")] -const _: [(); 1] = [(); 2]; // Trigger a compile error to make sure that we succeeded in de-activating this feature diff --git a/connectors/corrosion/test/find_rust/CMakeLists.txt b/connectors/corrosion/test/find_rust/CMakeLists.txt deleted file mode 100644 index 4b558b7c..00000000 --- a/connectors/corrosion/test/find_rust/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -corrosion_tests_add_test(find_rust "") - diff --git a/connectors/corrosion/test/find_rust/find_rust/CMakeLists.txt b/connectors/corrosion/test/find_rust/find_rust/CMakeLists.txt deleted file mode 100644 index bdd0cb7e..00000000 --- a/connectors/corrosion/test/find_rust/find_rust/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ - -cmake_minimum_required(VERSION 3.15) -project(FindRust LANGUAGES CXX) - -set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../../cmake" ${CMAKE_MODULE_PATH}) - -# make sure find_package(Rust) can be used more than once -find_package(Rust REQUIRED) -find_package(Rust REQUIRED) diff --git a/connectors/corrosion/test/gensource/CMakeLists.txt b/connectors/corrosion/test/gensource/CMakeLists.txt deleted file mode 100644 index b38a9877..00000000 --- a/connectors/corrosion/test/gensource/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -corrosion_tests_add_test(gensource "") - -#set_tests_properties("features_run_features-cpp-exe" PROPERTIES PASS_REGULAR_EXPRESSION -# "Hello, Cpp! I'm Rust!\r?\nHello, Cpp again! I'm Rust again!\r?\nHello, Cpp again! I'm Rust again, third time the charm!" -# ) \ No newline at end of file diff --git a/connectors/corrosion/test/gensource/gensource/.gitignore b/connectors/corrosion/test/gensource/gensource/.gitignore deleted file mode 100644 index b4878a28..00000000 --- a/connectors/corrosion/test/gensource/gensource/.gitignore +++ /dev/null @@ -1 +0,0 @@ -src/foo.rs diff --git a/connectors/corrosion/test/gensource/gensource/CMakeLists.txt b/connectors/corrosion/test/gensource/gensource/CMakeLists.txt deleted file mode 100644 index b13382f1..00000000 --- a/connectors/corrosion/test/gensource/gensource/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -add_subdirectory(generator) - -add_custom_command( - OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/foo.rs" - DEPENDS $ - COMMAND $ "${CMAKE_CURRENT_SOURCE_DIR}/src/foo.rs" -) - -add_custom_target(after_generation DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/foo.rs") -add_custom_target(genexdebug COMMAND ${CMAKE_COMMAND} -E echo "Config DEBUG: $ Config Release: $ IMPORTED_LOCATION: $") - -corrosion_import_crate(MANIFEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Cargo.toml) -add_dependencies(cargo-prebuild_generated after_generation) diff --git a/connectors/corrosion/test/gensource/gensource/Cargo.toml b/connectors/corrosion/test/gensource/gensource/Cargo.toml deleted file mode 100644 index f4c72d39..00000000 --- a/connectors/corrosion/test/gensource/gensource/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "generated" -version = "0.1.0" -edition = "2018" - -[lib] -crate-type = ["lib", "cdylib"] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/connectors/corrosion/test/gensource/gensource/generator/CMakeLists.txt b/connectors/corrosion/test/gensource/gensource/generator/CMakeLists.txt deleted file mode 100644 index aa9c8646..00000000 --- a/connectors/corrosion/test/gensource/gensource/generator/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -corrosion_import_crate(MANIFEST_PATH Cargo.toml TARGET srcgen) -corrosion_set_hostbuild(srcgen) diff --git a/connectors/corrosion/test/gensource/gensource/generator/Cargo.toml b/connectors/corrosion/test/gensource/gensource/generator/Cargo.toml deleted file mode 100644 index 8712fea4..00000000 --- a/connectors/corrosion/test/gensource/gensource/generator/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "srcgen" -version = "0.1.0" -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/connectors/corrosion/test/gensource/gensource/generator/src/main.rs b/connectors/corrosion/test/gensource/gensource/generator/src/main.rs deleted file mode 100644 index 84eef8c7..00000000 --- a/connectors/corrosion/test/gensource/gensource/generator/src/main.rs +++ /dev/null @@ -1,6 +0,0 @@ -use std::io::Write; -fn main() -> Result<(), std::io::Error> { - let out_name = std::env::args().skip(1).next().unwrap(); - let mut out_file = std::fs::File::create(out_name)?; - Ok(write!(out_file, "const _: () = ();")?) -} diff --git a/connectors/corrosion/test/gensource/gensource/src/lib.rs b/connectors/corrosion/test/gensource/gensource/src/lib.rs deleted file mode 100644 index b624d3c7..00000000 --- a/connectors/corrosion/test/gensource/gensource/src/lib.rs +++ /dev/null @@ -1,10 +0,0 @@ -mod foo; - -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - let result = 2 + 2; - assert_eq!(result, 4); - } -} diff --git a/connectors/corrosion/test/hostbuild/CMakeLists.txt b/connectors/corrosion/test/hostbuild/CMakeLists.txt deleted file mode 100644 index d98bba00..00000000 --- a/connectors/corrosion/test/hostbuild/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -# FIXME: ONly test this when cross-compiling? -corrosion_tests_add_test(hostbuild "rust-host-program") - -set_tests_properties("hostbuild_run_rust-host-program" PROPERTIES PASS_REGULAR_EXPRESSION - "^ok\r?\nHello Rust Hostbuild, I am an external C function" - ) -# Run tests are disabled by default when cross-compiling, however we still want to test hostbuild! -# So we manually re-enable the test here. -if(CMAKE_CROSSCOMPILING) - set_tests_properties("hostbuild_run_rust-host-program" PROPERTIES DISABLED FALSE) -endif() diff --git a/connectors/corrosion/test/hostbuild/hostbuild/CMakeLists.txt b/connectors/corrosion/test/hostbuild/hostbuild/CMakeLists.txt deleted file mode 100644 index 1e60ff31..00000000 --- a/connectors/corrosion/test/hostbuild/hostbuild/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -corrosion_import_crate(MANIFEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Cargo.toml) - -corrosion_set_hostbuild(rust-host-program) diff --git a/connectors/corrosion/test/hostbuild/hostbuild/Cargo.toml b/connectors/corrosion/test/hostbuild/hostbuild/Cargo.toml deleted file mode 100644 index 935757af..00000000 --- a/connectors/corrosion/test/hostbuild/hostbuild/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "rust-host-program" -version = "0.1.0" -authors = ["Olivier Goffart "] -edition = "2018" - -[build-dependencies] -cc = "1.0" diff --git a/connectors/corrosion/test/hostbuild/hostbuild/build.rs b/connectors/corrosion/test/hostbuild/hostbuild/build.rs deleted file mode 100644 index aa725cf5..00000000 --- a/connectors/corrosion/test/hostbuild/hostbuild/build.rs +++ /dev/null @@ -1,10 +0,0 @@ -fn main() { - let out_dir = std::env::var("OUT_DIR").unwrap(); - cc::Build::new() - .file("src/lib.c") - .compile("hello"); - - println!("cargo:rustc-link-search=native={}", out_dir); - println!("cargo:rustc-link-lib=hello"); - println!("cargo:rerun-if-changed=src/lib.c"); -} \ No newline at end of file diff --git a/connectors/corrosion/test/hostbuild/hostbuild/src/lib.c b/connectors/corrosion/test/hostbuild/hostbuild/src/lib.c deleted file mode 100644 index 4739e9c5..00000000 --- a/connectors/corrosion/test/hostbuild/hostbuild/src/lib.c +++ /dev/null @@ -1,5 +0,0 @@ -#include - -void c_function(char const *name) { - printf("Hello %s, I am an external C function\n", name); -} diff --git a/connectors/corrosion/test/hostbuild/hostbuild/src/main.rs b/connectors/corrosion/test/hostbuild/hostbuild/src/main.rs deleted file mode 100644 index d4ec7cb7..00000000 --- a/connectors/corrosion/test/hostbuild/hostbuild/src/main.rs +++ /dev/null @@ -1,13 +0,0 @@ -use std::os::raw::c_char; - -extern "C" { - fn c_function(name: *const c_char); -} - -fn main() { - println!("ok"); - let name = b"Rust Hostbuild\0"; - unsafe { - c_function(name.as_ptr() as _); - } -} diff --git a/connectors/corrosion/test/multitarget/CMakeLists.txt b/connectors/corrosion/test/multitarget/CMakeLists.txt deleted file mode 100644 index 663f1b35..00000000 --- a/connectors/corrosion/test/multitarget/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -corrosion_tests_add_test(multitarget "bin1;bin2;bin3") - -set_tests_properties("multitarget_run_bin1" PROPERTIES PASS_REGULAR_EXPRESSION - "Hello, world!\r?\nHello, bin1! I'm Cpp!" - ) - -set_tests_properties("multitarget_run_bin2" PROPERTIES PASS_REGULAR_EXPRESSION - "Hello, world!\r?\nHello, bin2! I'm Cpp!" - ) - -set_tests_properties("multitarget_run_bin3" PROPERTIES PASS_REGULAR_EXPRESSION - "Hello, world!\r?\nHello, bin3! I'm Cpp!" - ) diff --git a/connectors/corrosion/test/multitarget/multitarget/CMakeLists.txt b/connectors/corrosion/test/multitarget/multitarget/CMakeLists.txt deleted file mode 100644 index 16054903..00000000 --- a/connectors/corrosion/test/multitarget/multitarget/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -corrosion_import_crate(MANIFEST_PATH Cargo.toml) - -add_library(cpp-lib4 lib.cpp) -target_compile_features(cpp-lib4 PRIVATE cxx_std_14) -target_compile_options(cpp-lib4 PRIVATE -fPIE) -corrosion_link_libraries(bin1 cpp-lib4) -corrosion_link_libraries(bin2 cpp-lib4) -corrosion_link_libraries(bin3 cpp-lib4) diff --git a/connectors/corrosion/test/multitarget/multitarget/Cargo.toml b/connectors/corrosion/test/multitarget/multitarget/Cargo.toml deleted file mode 100644 index 406e1d00..00000000 --- a/connectors/corrosion/test/multitarget/multitarget/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "multitarget-crate" -version = "0.1.0" -edition = "2018" - -[dependencies] - -[lib] -name = "multitarget_lib" -crate-type=["lib", "staticlib", "cdylib"] - -[[bin]] -name = "bin1" - -[[bin]] -name = "bin2" - -[[bin]] -name = "bin3" diff --git a/connectors/corrosion/test/multitarget/multitarget/lib.cpp b/connectors/corrosion/test/multitarget/multitarget/lib.cpp deleted file mode 100644 index 549964a6..00000000 --- a/connectors/corrosion/test/multitarget/multitarget/lib.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include - -extern "C" void cpp_function(char const *name) { - std::cout << "Hello, " << name << "! I'm Cpp!\n"; -} diff --git a/connectors/corrosion/test/multitarget/multitarget/src/bin/bin1.rs b/connectors/corrosion/test/multitarget/multitarget/src/bin/bin1.rs deleted file mode 100644 index 6284966f..00000000 --- a/connectors/corrosion/test/multitarget/multitarget/src/bin/bin1.rs +++ /dev/null @@ -1,8 +0,0 @@ -use multitarget_lib::hello_world; - -fn main() { - hello_world(); - unsafe { - multitarget_lib::cpp_function("bin1\0".as_ptr() as *const _); - } -} diff --git a/connectors/corrosion/test/multitarget/multitarget/src/bin/bin2.rs b/connectors/corrosion/test/multitarget/multitarget/src/bin/bin2.rs deleted file mode 100644 index 05ddbdb0..00000000 --- a/connectors/corrosion/test/multitarget/multitarget/src/bin/bin2.rs +++ /dev/null @@ -1,8 +0,0 @@ -use multitarget_lib::hello_world; - -fn main() { - hello_world(); - unsafe { - multitarget_lib::cpp_function("bin2\0".as_ptr() as *const _); - } -} diff --git a/connectors/corrosion/test/multitarget/multitarget/src/bin/bin3.rs b/connectors/corrosion/test/multitarget/multitarget/src/bin/bin3.rs deleted file mode 100644 index 238e8b97..00000000 --- a/connectors/corrosion/test/multitarget/multitarget/src/bin/bin3.rs +++ /dev/null @@ -1,8 +0,0 @@ -use multitarget_lib::hello_world; - -fn main() { - hello_world(); - unsafe { - multitarget_lib::cpp_function("bin3\0".as_ptr() as *const _); - } -} diff --git a/connectors/corrosion/test/multitarget/multitarget/src/lib.rs b/connectors/corrosion/test/multitarget/multitarget/src/lib.rs deleted file mode 100644 index 1da2d248..00000000 --- a/connectors/corrosion/test/multitarget/multitarget/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -use std::os::raw::c_char; - -pub fn hello_world() { - println!("Hello, world!"); -} - -extern "C" { - pub fn cpp_function(name: *const c_char); -} diff --git a/connectors/corrosion/test/nostd/CMakeLists.txt b/connectors/corrosion/test/nostd/CMakeLists.txt deleted file mode 100644 index be700caa..00000000 --- a/connectors/corrosion/test/nostd/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -corrosion_tests_add_test(nostd "") diff --git a/connectors/corrosion/test/nostd/nostd/CMakeLists.txt b/connectors/corrosion/test/nostd/nostd/CMakeLists.txt deleted file mode 100644 index a533d79a..00000000 --- a/connectors/corrosion/test/nostd/nostd/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml NO_STD) - -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nostdlib") -list(REMOVE_ITEM CMAKE_CXX_IMPLICIT_LINK_LIBRARIES stdc++) - -add_library(nostd-cpp-lib STATIC main.cpp) -target_link_libraries(nostd-cpp-lib PUBLIC rust-nostd-lib) diff --git a/connectors/corrosion/test/nostd/nostd/main.cpp b/connectors/corrosion/test/nostd/nostd/main.cpp deleted file mode 100644 index 3cede3a8..00000000 --- a/connectors/corrosion/test/nostd/nostd/main.cpp +++ /dev/null @@ -1,6 +0,0 @@ -extern "C" void rust_function(); - -extern "C" void cpp_function() { - // Fail on linking issues - rust_function(); -} \ No newline at end of file diff --git a/connectors/corrosion/test/nostd/nostd/rust/Cargo.toml b/connectors/corrosion/test/nostd/nostd/rust/Cargo.toml deleted file mode 100644 index e16f8fe8..00000000 --- a/connectors/corrosion/test/nostd/nostd/rust/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "rust-nostd-lib" -version = "0.1.0" -edition = "2015" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] - -[lib] -crate-type=["staticlib"] - -[profile.release] -panic = "abort" - -[profile.dev] -panic = "abort" diff --git a/connectors/corrosion/test/nostd/nostd/rust/src/lib.rs b/connectors/corrosion/test/nostd/nostd/rust/src/lib.rs deleted file mode 100644 index 81443752..00000000 --- a/connectors/corrosion/test/nostd/nostd/rust/src/lib.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![no_std] -use core::panic::PanicInfo; - -#[no_mangle] -pub extern "C" fn rust_function() {} - -#[panic_handler] -fn panic(_panic: &PanicInfo<'_>) -> ! { - loop {} -} \ No newline at end of file diff --git a/connectors/corrosion/test/output directory/CMakeLists.txt b/connectors/corrosion/test/output directory/CMakeLists.txt deleted file mode 100644 index 044f9a7c..00000000 --- a/connectors/corrosion/test/output directory/CMakeLists.txt +++ /dev/null @@ -1,137 +0,0 @@ -if(CMAKE_VERSION VERSION_LESS 3.19.0) - return() -endif() - -if(CMAKE_C_COMPILER) - set(TEST_C_COMPILER "C_COMPILER" "${CMAKE_C_COMPILER}") -endif() -if(CMAKE_CXX_COMPILER) - set(TEST_CXX_COMPILER "CXX_COMPILER" "${CMAKE_CXX_COMPILER}") -endif() -if(CMAKE_GENERATOR_PLATFORM) - set(TEST_GENERATOR_PLATFORM "GENERATOR_PLATFORM" "${CMAKE_GENERATOR_PLATFORM}") -endif() - -add_test(NAME "output_directory_build" - COMMAND - ${CMAKE_COMMAND} - -P "${CMAKE_SOURCE_DIR}/test/ConfigureAndBuild.cmake" - SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/output directory" - BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/build" - GENERATOR "${CMAKE_GENERATOR}" - RUST_TOOLCHAIN "${Rust_TOOLCHAIN}" - CARGO_TARGET "${Rust_CARGO_TARGET}" - SYSTEM_NAME "${CMAKE_SYSTEM_NAME}" - "${TEST_C_COMPILER}" - "${TEST_CXX_COMPILER}" - "${TEST_GENERATOR_PLATFORM}" - - COMMAND_EXPAND_LISTS -) -set_tests_properties("output_directory_build" PROPERTIES FIXTURES_SETUP "build_fixture_output_directory") -if(CORROSION_TESTS_INSTALL_CORROSION) - set_tests_properties("output_directory_build" PROPERTIES FIXTURES_REQUIRED "fixture_corrosion_install") -endif() - -foreach(output_approach targetprop var) - if(output_approach STREQUAL "targetprop") - set(rust_proj_suffix "1") - elseif(output_approach STREQUAL "var") - set(rust_proj_suffix "2") - else() - message(FATAL_ERROR "specify rust project suffix for new output approach ${output_approach}") - endif() - - set(bin_name "rust_bin${rust_proj_suffix}${CMAKE_EXECUTABLE_SUFFIX}") - - add_test(NAME output_directory_bin_${output_approach} - COMMAND - "${CMAKE_COMMAND}" - -P "${CMAKE_CURRENT_SOURCE_DIR}/TestFileExists.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/build/custom_bin_${output_approach}/${bin_name}" - ) - set_tests_properties("output_directory_bin_${output_approach}" PROPERTIES FIXTURES_REQUIRED "build_fixture_output_directory") - - set(lib_name "rust_lib${rust_proj_suffix}") - - set(static_lib_name "${CMAKE_STATIC_LIBRARY_PREFIX}${lib_name}${CMAKE_STATIC_LIBRARY_SUFFIX}") - - add_test(NAME output_directory_staticlib_${output_approach} - COMMAND - "${CMAKE_COMMAND}" - -P "${CMAKE_CURRENT_SOURCE_DIR}/TestFileExists.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/build/custom_archive_${output_approach}/${static_lib_name}" - ) - set_tests_properties("output_directory_staticlib_${output_approach}" PROPERTIES FIXTURES_REQUIRED "build_fixture_output_directory") - - if(MINGW) - # Windows-GNU defines "lib" as prefix for DLLs, but cargo creates foo.dll instead of libfoo.dll - set(dynamic_lib_prefix "") - else() - set(dynamic_lib_prefix "${CMAKE_SHARED_LIBRARY_PREFIX}") - endif() - set(dynamic_lib_name "${dynamic_lib_prefix}${lib_name}${CMAKE_SHARED_LIBRARY_SUFFIX}") - - add_test(NAME output_directory_cdylib_${output_approach} - COMMAND - "${CMAKE_COMMAND}" - -P "${CMAKE_CURRENT_SOURCE_DIR}/TestFileExists.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/build/custom_lib_${output_approach}/${dynamic_lib_name}" - ) - set_tests_properties("output_directory_cdylib_${output_approach}" PROPERTIES FIXTURES_REQUIRED "build_fixture_output_directory") - - if(WIN32) - set(implib_name ${CMAKE_IMPORT_LIBRARY_PREFIX}${lib_name}${CMAKE_IMPORT_LIBRARY_SUFFIX}) - - add_test(NAME output_directory_implib_${output_approach} - COMMAND - "${CMAKE_COMMAND}" - -P "${CMAKE_CURRENT_SOURCE_DIR}/TestFileExists.cmake" - # Implib is an ARCHIVE artifact, see: - # https://cmake.org/cmake/help/v3.25/manual/cmake-buildsystem.7.html#archive-output-artifacts - "${CMAKE_CURRENT_BINARY_DIR}/build/custom_archive_${output_approach}/${implib_name}" - ) - set_tests_properties("output_directory_implib_${output_approach}" PROPERTIES FIXTURES_REQUIRED "build_fixture_output_directory") - - if(MSVC) - if(output_approach STREQUAL "targetprop") - set(expected_lib_pdb_path "custom_lib_pdb_targetprop") - set(expected_bin_pdb_path "custom_bin_pdb_targetprop") - elseif(output_approach STREQUAL "var") - # When using a CMAKE_ variable instead of a target property, both targets - # end up in the same directory. - set(expected_lib_pdb_path "custom_binlib_pdb_var") - set(expected_bin_pdb_path "custom_binlib_pdb_var") - else() - message(FATAL_ERROR "specify rust project suffix for new output approach ${output_approach}") - endif() - - set(lib_pdb_name "${lib_name}.pdb") - add_test(NAME output_directory_cdylib_pdb_${output_approach} - COMMAND - "${CMAKE_COMMAND}" - -P "${CMAKE_CURRENT_SOURCE_DIR}/TestFileExists.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/build/${expected_lib_pdb_path}/${lib_pdb_name}" - ) - set_tests_properties("output_directory_cdylib_pdb_${output_approach}" PROPERTIES FIXTURES_REQUIRED "build_fixture_output_directory") - - set(bin_pdb_name "rust_bin${rust_proj_suffix}.pdb") - add_test(NAME output_directory_bin_pdb_${output_approach} - COMMAND - "${CMAKE_COMMAND}" - -P "${CMAKE_CURRENT_SOURCE_DIR}/TestFileExists.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/build/${expected_bin_pdb_path}/${bin_pdb_name}" - ) - set_tests_properties("output_directory_bin_pdb_${output_approach}" PROPERTIES FIXTURES_REQUIRED "build_fixture_output_directory") - endif() - endif() - -endforeach() - -add_test(NAME postbuild_custom_command - COMMAND - "${CMAKE_COMMAND}" - -P "${CMAKE_CURRENT_SOURCE_DIR}/TestFileExists.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/build/another_dir/moved_bin" - ) -set_tests_properties("postbuild_custom_command" PROPERTIES FIXTURES_REQUIRED "build_fixture_output_directory") diff --git a/connectors/corrosion/test/output directory/TestFileExists.cmake b/connectors/corrosion/test/output directory/TestFileExists.cmake deleted file mode 100644 index cfc33f2d..00000000 --- a/connectors/corrosion/test/output directory/TestFileExists.cmake +++ /dev/null @@ -1,13 +0,0 @@ -# CMake script to test if a file exists. Errors if the file does not exist. -# Expect actual arguments to start at index 3 (cmake -P ) - -# Expect one argument -if(NOT (CMAKE_ARGC EQUAL "4")) - message(FATAL_ERROR "Test Internal Error: Unexpected ARGC Value: ${CMAKE_ARGC}.") -endif() - -set(FILE_PATH "${CMAKE_ARGV3}") - -if(NOT ( EXISTS "${FILE_PATH}" )) - message(FATAL_ERROR "Test failed: File `${FILE_PATH}` does not exist.") -endif() diff --git a/connectors/corrosion/test/output directory/output directory/CMakeLists.txt b/connectors/corrosion/test/output directory/output directory/CMakeLists.txt deleted file mode 100644 index 5a0f2cf8..00000000 --- a/connectors/corrosion/test/output directory/output directory/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -corrosion_import_crate(MANIFEST_PATH proj1/Cargo.toml) - -# Note: The output directories defined here must be manually kept in sync with the expected test location. -set_target_properties(rust_bin1 - PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/custom_bin_targetprop" - PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/custom_bin_pdb_targetprop" - -) -set_target_properties(rust_lib1 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/custom_archive_targetprop") -set_target_properties(rust_lib1 - PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/custom_lib_targetprop" - PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/custom_lib_pdb_targetprop" -) - -add_custom_command(TARGET cargo-build_rust_bin1 POST_BUILD - COMMAND - ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/another_dir" - COMMAND - ${CMAKE_COMMAND} -E copy_if_different "$" "${CMAKE_CURRENT_BINARY_DIR}/another_dir/moved_bin" - ) - -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/custom_bin_var") -set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/custom_binlib_pdb_var") -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/custom_archive_var") -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/custom_lib_var") - -corrosion_import_crate(MANIFEST_PATH proj2/Cargo.toml) - -unset(CMAKE_RUNTIME_OUTPUT_DIRECTORY) -unset(CMAKE_PDB_OUTPUT_DIRECTORY) -unset(CMAKE_ARCHIVE_OUTPUT_DIRECTORY) -unset(CMAKE_LIBRARY_OUTPUT_DIRECTORY) -unset(CMAKE_PDB_OUTPUT_DIRECTORY) - -add_executable(consumer consumer.cpp) -add_dependencies(consumer cargo-build_rust_lib1 cargo-build_rust_lib2) - -target_link_libraries(consumer rust_lib1 rust_lib2) diff --git a/connectors/corrosion/test/output directory/output directory/consumer.cpp b/connectors/corrosion/test/output directory/output directory/consumer.cpp deleted file mode 100644 index fa943ba6..00000000 --- a/connectors/corrosion/test/output directory/output directory/consumer.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -extern "C" unsigned int ret_12(); - - -int main(int argc, char *argv[]) -{ - std::cout << "HI\n"; - unsigned int a = ret_12(); - if (a != 12) { - return -1; - } - - return 0; -} diff --git a/connectors/corrosion/test/output directory/output directory/proj1/Cargo.toml b/connectors/corrosion/test/output directory/output directory/proj1/Cargo.toml deleted file mode 100644 index 0f3bc1bc..00000000 --- a/connectors/corrosion/test/output directory/output directory/proj1/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "rust_package1" -version = "0.1.0" -edition = "2018" - -[lib] -name = "rust_lib1" -crate-type=["staticlib", "cdylib"] - -[[bin]] -name = "rust_bin1" diff --git a/connectors/corrosion/test/output directory/output directory/proj1/src/bin/rust_bin1.rs b/connectors/corrosion/test/output directory/output directory/proj1/src/bin/rust_bin1.rs deleted file mode 100644 index 11c0291c..00000000 --- a/connectors/corrosion/test/output directory/output directory/proj1/src/bin/rust_bin1.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world from test rust binary"); -} diff --git a/connectors/corrosion/test/output directory/output directory/proj1/src/lib.rs b/connectors/corrosion/test/output directory/output directory/proj1/src/lib.rs deleted file mode 100644 index cfadd0f9..00000000 --- a/connectors/corrosion/test/output directory/output directory/proj1/src/lib.rs +++ /dev/null @@ -1,4 +0,0 @@ -#[no_mangle] -pub extern "C" fn ret_12() -> u32 { - 12 -} diff --git a/connectors/corrosion/test/output directory/output directory/proj2/Cargo.toml b/connectors/corrosion/test/output directory/output directory/proj2/Cargo.toml deleted file mode 100644 index 63df8d5e..00000000 --- a/connectors/corrosion/test/output directory/output directory/proj2/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "rust_package2" -version = "0.1.0" -edition = "2018" - -[lib] -name = "rust_lib2" -crate-type=["staticlib", "cdylib"] - -[[bin]] -name = "rust_bin2" diff --git a/connectors/corrosion/test/output directory/output directory/proj2/src/bin/rust_bin2.rs b/connectors/corrosion/test/output directory/output directory/proj2/src/bin/rust_bin2.rs deleted file mode 100644 index 11c0291c..00000000 --- a/connectors/corrosion/test/output directory/output directory/proj2/src/bin/rust_bin2.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world from test rust binary"); -} diff --git a/connectors/corrosion/test/output directory/output directory/proj2/src/lib.rs b/connectors/corrosion/test/output directory/output directory/proj2/src/lib.rs deleted file mode 100644 index cfadd0f9..00000000 --- a/connectors/corrosion/test/output directory/output directory/proj2/src/lib.rs +++ /dev/null @@ -1,4 +0,0 @@ -#[no_mangle] -pub extern "C" fn ret_12() -> u32 { - 12 -} diff --git a/connectors/corrosion/test/parse_target_triple/CMakeLists.txt b/connectors/corrosion/test/parse_target_triple/CMakeLists.txt deleted file mode 100644 index dbd05fd5..00000000 --- a/connectors/corrosion/test/parse_target_triple/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -corrosion_tests_add_test(parse_target_triple "") - -set_tests_properties("parse_target_triple_build" PROPERTIES FAIL_REGULAR_EXPRESSION - "CMake Warning" - ) diff --git a/connectors/corrosion/test/parse_target_triple/parse_target_triple/CMakeLists.txt b/connectors/corrosion/test/parse_target_triple/parse_target_triple/CMakeLists.txt deleted file mode 100644 index 871458c0..00000000 --- a/connectors/corrosion/test/parse_target_triple/parse_target_triple/CMakeLists.txt +++ /dev/null @@ -1,105 +0,0 @@ -# This test is supposed to ensure that the regex in _corrosion_parse_platform works as expected. -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -# Custom json file. The file doesn't need to exist for the test. -_corrosion_parse_platform("Cargo.toml" "1.55" "../../blah/x86_64-unknown-custom-gnu.json") -_corrosion_parse_platform("Cargo.toml" "1.55" "x86_64-unknown-custom-gnu.json") -_corrosion_parse_platform("Cargo.toml" "1.55" "/path/to/x86_64-unknown-custom-gnu.json") -_corrosion_parse_platform("Cargo.toml" "1.55" "../../blah/x86_64-custom_os.json") - -# List of builtin targets aquired via `rustup target list` with rust 1.64 on Linux. -set(rustup_shipped_targets - "aarch64-apple-darwin" - "aarch64-apple-ios" - "aarch64-apple-ios-sim" - "aarch64-fuchsia" - "aarch64-linux-android" - "aarch64-pc-windows-msvc" - "aarch64-unknown-linux-gnu" - "aarch64-unknown-linux-musl" - "aarch64-unknown-none" - "aarch64-unknown-none-softfloat" - "arm-linux-androideabi" - "arm-unknown-linux-gnueabi" - "arm-unknown-linux-gnueabihf" - "arm-unknown-linux-musleabi" - "arm-unknown-linux-musleabihf" - "armebv7r-none-eabi" - "armebv7r-none-eabihf" - "armv5te-unknown-linux-gnueabi" - "armv5te-unknown-linux-musleabi" - "armv7-linux-androideabi" - "armv7-unknown-linux-gnueabi" - "armv7-unknown-linux-gnueabihf" - "armv7-unknown-linux-musleabi" - "armv7-unknown-linux-musleabihf" - "armv7a-none-eabi" - "armv7r-none-eabi" - "armv7r-none-eabihf" - "asmjs-unknown-emscripten" - "i586-pc-windows-msvc" - "i586-unknown-linux-gnu" - "i586-unknown-linux-musl" - "i686-linux-android" - "i686-pc-windows-gnu" - "i686-pc-windows-msvc" - "i686-unknown-freebsd" - "i686-unknown-linux-gnu" - "i686-unknown-linux-musl" - "mips-unknown-linux-gnu" - "mips-unknown-linux-musl" - "mips64-unknown-linux-gnuabi64" - "mips64-unknown-linux-muslabi64" - "mips64el-unknown-linux-gnuabi64" - "mips64el-unknown-linux-muslabi64" - "mipsel-unknown-linux-gnu" - "mipsel-unknown-linux-musl" - "nvptx64-nvidia-cuda" - "powerpc-unknown-linux-gnu" - "powerpc64-unknown-linux-gnu" - "powerpc64le-unknown-linux-gnu" - "riscv32i-unknown-none-elf" - "riscv32imac-unknown-none-elf" - "riscv32imc-unknown-none-elf" - "riscv64gc-unknown-linux-gnu" - "riscv64gc-unknown-none-elf" - "riscv64imac-unknown-none-elf" - "s390x-unknown-linux-gnu" - "sparc64-unknown-linux-gnu" - "sparcv9-sun-solaris" - "thumbv6m-none-eabi" - "thumbv7em-none-eabi" - "thumbv7em-none-eabihf" - "thumbv7m-none-eabi" - "thumbv7neon-linux-androideabi" - "thumbv7neon-unknown-linux-gnueabihf" - "thumbv8m.base-none-eabi" - "thumbv8m.main-none-eabi" - "thumbv8m.main-none-eabihf" - "wasm32-unknown-emscripten" - "wasm32-unknown-unknown" - "wasm32-wasi" - "x86_64-apple-darwin" - "x86_64-apple-ios" - "x86_64-fortanix-unknown-sgx" - "x86_64-fuchsia" - "x86_64-linux-android" - "x86_64-pc-solaris" - "x86_64-pc-windows-gnu" - "x86_64-pc-windows-msvc" - "x86_64-sun-solaris" - "x86_64-unknown-freebsd" - "x86_64-unknown-illumos" - "x86_64-unknown-linux-gnu" - "x86_64-unknown-linux-gnux32" - "x86_64-unknown-linux-musl" - "x86_64-unknown-netbsd" - "x86_64-unknown-none" - "x86_64-unknown-redox" -) - -foreach(target ${rustup_shipped_targets}) - _corrosion_parse_platform("Cargo.toml" "1.55" "${target}") -endforeach() diff --git a/connectors/corrosion/test/parse_target_triple/parse_target_triple/Cargo.toml b/connectors/corrosion/test/parse_target_triple/parse_target_triple/Cargo.toml deleted file mode 100644 index 5d5527ac..00000000 --- a/connectors/corrosion/test/parse_target_triple/parse_target_triple/Cargo.toml +++ /dev/null @@ -1 +0,0 @@ -# Pseudo manifest, just used in CMake to set some source file properties. \ No newline at end of file diff --git a/connectors/corrosion/test/parse_target_triple/parse_target_triple_should_fail/CMakeLists.txt b/connectors/corrosion/test/parse_target_triple/parse_target_triple_should_fail/CMakeLists.txt deleted file mode 100644 index 706b774a..00000000 --- a/connectors/corrosion/test/parse_target_triple/parse_target_triple_should_fail/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -# This test is supposed to ensure that the regex in _corrosion_parse_platform works as expected. -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -# Check if parsing fails -_corrosion_parse_platform("Cargo.toml" "1.55" "x86_64-unknown-linux-gnu-toomuch") - - - diff --git a/connectors/corrosion/test/parse_target_triple/parse_target_triple_should_fail/Cargo.toml b/connectors/corrosion/test/parse_target_triple/parse_target_triple_should_fail/Cargo.toml deleted file mode 100644 index 5d5527ac..00000000 --- a/connectors/corrosion/test/parse_target_triple/parse_target_triple_should_fail/Cargo.toml +++ /dev/null @@ -1 +0,0 @@ -# Pseudo manifest, just used in CMake to set some source file properties. \ No newline at end of file diff --git a/connectors/corrosion/test/rust2cpp/CMakeLists.txt b/connectors/corrosion/test/rust2cpp/CMakeLists.txt deleted file mode 100644 index 4df9b288..00000000 --- a/connectors/corrosion/test/rust2cpp/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -corrosion_tests_add_test(rust2cpp "cpp-exe;cpp-exe-shared") - -set_tests_properties("rust2cpp_run_cpp-exe" PROPERTIES PASS_REGULAR_EXPRESSION - "^Hello, Cpp! I'm Rust!\r?\n$" - ) - -set_tests_properties("rust2cpp_run_cpp-exe-shared" PROPERTIES PASS_REGULAR_EXPRESSION - "^Hello, Cpp! I'm Rust!\r?\n$" - ) diff --git a/connectors/corrosion/test/rust2cpp/rust2cpp/CMakeLists.txt b/connectors/corrosion/test/rust2cpp/rust2cpp/CMakeLists.txt deleted file mode 100644 index 71b3bee6..00000000 --- a/connectors/corrosion/test/rust2cpp/rust2cpp/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml) - -add_executable(cpp-exe main.cpp) -target_link_libraries(cpp-exe PUBLIC rust-lib) - -add_executable(cpp-exe-shared main.cpp) -target_link_libraries(cpp-exe-shared - PUBLIC rust-lib-shared) diff --git a/connectors/corrosion/test/rust2cpp/rust2cpp/main.cpp b/connectors/corrosion/test/rust2cpp/rust2cpp/main.cpp deleted file mode 100644 index 785c0bc3..00000000 --- a/connectors/corrosion/test/rust2cpp/rust2cpp/main.cpp +++ /dev/null @@ -1,9 +0,0 @@ -extern "C" void rust_function(char const *name); - -int main(int argc, char **argv) { - if (argc < 2) { - rust_function("Cpp"); - } else { - rust_function(argv[1]); - } -} diff --git a/connectors/corrosion/test/rust2cpp/rust2cpp/rust/Cargo.toml b/connectors/corrosion/test/rust2cpp/rust2cpp/rust/Cargo.toml deleted file mode 100644 index ab91e620..00000000 --- a/connectors/corrosion/test/rust2cpp/rust2cpp/rust/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "rust-lib" -version = "0.1.0" -authors = ["Andrew Gaspar "] -license = "MIT" -edition = "2018" - -[dependencies] - -[lib] -crate-type=["staticlib", "cdylib"] diff --git a/connectors/corrosion/test/rust2cpp/rust2cpp/rust/src/lib.rs b/connectors/corrosion/test/rust2cpp/rust2cpp/rust/src/lib.rs deleted file mode 100644 index 194e5650..00000000 --- a/connectors/corrosion/test/rust2cpp/rust2cpp/rust/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -use std::os::raw::c_char; - -#[no_mangle] -pub extern "C" fn rust_function(name: *const c_char) { - let name = unsafe { std::ffi::CStr::from_ptr(name).to_str().unwrap() }; - println!("Hello, {}! I'm Rust!", name); -} diff --git a/connectors/corrosion/test/rustflags/CMakeLists.txt b/connectors/corrosion/test/rustflags/CMakeLists.txt deleted file mode 100644 index fd2ea529..00000000 --- a/connectors/corrosion/test/rustflags/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -corrosion_tests_add_test(rustflags "rustflags-cpp-exe") - -set_tests_properties("rustflags_run_rustflags-cpp-exe" PROPERTIES PASS_REGULAR_EXPRESSION - "Hello, Cpp! I'm Rust!\r?\nHello, Cpp again! I'm Rust in (Debug|Release) mode again!\r?\nHello, Cpp again! I'm Rust again, third time the charm!\r?\n$" - ) - -corrosion_tests_add_test(cargo_config_rustflags "cargo_config_rustflags") diff --git a/connectors/corrosion/test/rustflags/cargo_config_rustflags/CMakeLists.txt b/connectors/corrosion/test/rustflags/cargo_config_rustflags/CMakeLists.txt deleted file mode 100644 index 507bde8c..00000000 --- a/connectors/corrosion/test/rustflags/cargo_config_rustflags/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -corrosion_import_crate(MANIFEST_PATH Cargo.toml) - -# Do not use `corrosion_add_target_rustflags()` here, since we want to test if the rustflag from `.cargo/config.toml` -# is picked up. - -# Local rustflags should not interfere with `.cargo/config.toml`, so enable one. -corrosion_add_target_local_rustflags(cargo_config_rustflags "--cfg=local_rustflag") diff --git a/connectors/corrosion/test/rustflags/cargo_config_rustflags/Cargo.toml b/connectors/corrosion/test/rustflags/cargo_config_rustflags/Cargo.toml deleted file mode 100644 index 298b193e..00000000 --- a/connectors/corrosion/test/rustflags/cargo_config_rustflags/Cargo.toml +++ /dev/null @@ -1,4 +0,0 @@ -[package] -name = "cargo_config_rustflags" -version = "0.1.0" -edition = "2018" diff --git a/connectors/corrosion/test/rustflags/cargo_config_rustflags/src/main.rs b/connectors/corrosion/test/rustflags/cargo_config_rustflags/src/main.rs deleted file mode 100644 index f4919bb1..00000000 --- a/connectors/corrosion/test/rustflags/cargo_config_rustflags/src/main.rs +++ /dev/null @@ -1,16 +0,0 @@ - -#[cfg(some_cargo_config_rustflag)] -fn print_line() { - println!("Rustflag is enabled"); -} - -// test that local rustflags don't override global rustflags set via `.cargo/config` -#[cfg(local_rustflag)] -fn test_local_rustflag() { - println!("local_rustflag was enabled"); -} - -fn main() { - print_line(); - test_local_rustflag(); -} diff --git a/connectors/corrosion/test/rustflags/rustflags/CMakeLists.txt b/connectors/corrosion/test/rustflags/rustflags/CMakeLists.txt deleted file mode 100644 index 422c352b..00000000 --- a/connectors/corrosion/test/rustflags/rustflags/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml) - -add_executable(rustflags-cpp-exe main.cpp) -target_link_libraries(rustflags-cpp-exe PUBLIC rustflag-test-lib) - -# Test --cfg=key="value" rustflag. -corrosion_add_target_rustflags(rustflag-test-lib --cfg=test_rustflag_cfg1="test_rustflag_cfg1_value") - -# Test using a generator expression to produce a rustflag and passing multiple rustflags. -corrosion_add_target_rustflags(rustflag-test-lib - --cfg=test_rustflag_cfg2="$,$>,debug,release>" - "--cfg=test_rustflag_cfg3" -) - -corrosion_add_target_local_rustflags(rustflag-test-lib "--cfg=test_local_rustflag1") -corrosion_add_target_local_rustflags(rustflag-test-lib --cfg=test_local_rustflag2="value") diff --git a/connectors/corrosion/test/rustflags/rustflags/main.cpp b/connectors/corrosion/test/rustflags/rustflags/main.cpp deleted file mode 100644 index 0b9b1b92..00000000 --- a/connectors/corrosion/test/rustflags/rustflags/main.cpp +++ /dev/null @@ -1,13 +0,0 @@ -extern "C" void rust_function(char const *name); -extern "C" void rust_second_function(char const *name); -extern "C" void rust_third_function(char const *name); - -int main(int argc, char **argv) { - if (argc < 2) { - rust_function("Cpp"); - rust_second_function("Cpp again"); - rust_third_function("Cpp again"); - } else { - rust_function(argv[1]); - } -} diff --git a/connectors/corrosion/test/rustflags/rustflags/rust/Cargo.toml b/connectors/corrosion/test/rustflags/rustflags/rust/Cargo.toml deleted file mode 100644 index 2bdd26f7..00000000 --- a/connectors/corrosion/test/rustflags/rustflags/rust/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "rustflag-test-lib" -version = "0.1.0" -license = "MIT" -edition = "2018" - -[dependencies] -some_dependency = { path = "some_dependency" } - -[lib] -crate-type=["staticlib"] diff --git a/connectors/corrosion/test/rustflags/rustflags/rust/some_dependency/Cargo.toml b/connectors/corrosion/test/rustflags/rustflags/rust/some_dependency/Cargo.toml deleted file mode 100644 index 94627d03..00000000 --- a/connectors/corrosion/test/rustflags/rustflags/rust/some_dependency/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "some_dependency" -version = "0.1.0" -license = "MIT" -edition = "2018" - diff --git a/connectors/corrosion/test/rustflags/rustflags/rust/some_dependency/src/lib.rs b/connectors/corrosion/test/rustflags/rustflags/rust/some_dependency/src/lib.rs deleted file mode 100644 index d240a7ca..00000000 --- a/connectors/corrosion/test/rustflags/rustflags/rust/some_dependency/src/lib.rs +++ /dev/null @@ -1,10 +0,0 @@ -//! Test that the local rustflags are only passed to the main crate and not to dependencies. -#[cfg(test_local_rustflag1)] -const _: [(); 1] = [(); 2]; - -#[cfg(test_local_rustflag2 = "value")] -const _: [(); 1] = [(); 2]; - -pub fn some_function() -> u32 { - 42 -} diff --git a/connectors/corrosion/test/rustflags/rustflags/rust/src/lib.rs b/connectors/corrosion/test/rustflags/rustflags/rust/src/lib.rs deleted file mode 100644 index f6da1f6e..00000000 --- a/connectors/corrosion/test/rustflags/rustflags/rust/src/lib.rs +++ /dev/null @@ -1,40 +0,0 @@ -#[cfg(test_rustflag_cfg1 = "test_rustflag_cfg1_value")] -use std::os::raw::c_char; - -#[no_mangle] -#[cfg(test_rustflag_cfg1 = "test_rustflag_cfg1_value")] -pub extern "C" fn rust_function(name: *const c_char) { - let name = unsafe { std::ffi::CStr::from_ptr(name).to_str().unwrap() }; - println!("Hello, {}! I'm Rust!", name); -} - -#[no_mangle] -#[cfg(all(debug_assertions, test_rustflag_cfg2 = "debug"))] -pub extern "C" fn rust_second_function(name: *const c_char) { - let name = unsafe { std::ffi::CStr::from_ptr(name).to_str().unwrap() }; - println!("Hello, {}! I'm Rust in Debug mode again!", name); -} - -#[no_mangle] -#[cfg(all(not(debug_assertions), test_rustflag_cfg2 = "release"))] -pub extern "C" fn rust_second_function(name: *const c_char) { - let name = unsafe { std::ffi::CStr::from_ptr(name).to_str().unwrap() }; - println!("Hello, {}! I'm Rust in Release mode again!", name); -} - -#[no_mangle] -#[cfg(test_rustflag_cfg3)] -pub extern "C" fn rust_third_function(name: *const c_char) { - let name = unsafe { std::ffi::CStr::from_ptr(name).to_str().unwrap() }; - println!("Hello, {}! I'm Rust again, third time the charm!", name); - assert_eq!(some_dependency::some_function(), 42); -} - -#[cfg(not(test_rustflag_cfg3))] -const _: [(); 1] = [(); 2]; - -#[cfg(not(test_local_rustflag1))] -const _: [(); 1] = [(); 2]; - -#[cfg(not(test_local_rustflag2 = "value"))] -const _: [(); 1] = [(); 2]; diff --git a/connectors/corrosion/test/workspace/CMakeLists.txt b/connectors/corrosion/test/workspace/CMakeLists.txt deleted file mode 100644 index 39bec842..00000000 --- a/connectors/corrosion/test/workspace/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -corrosion_tests_add_test(workspace "my_program") - -set_tests_properties("workspace_run_my_program" PROPERTIES PASS_REGULAR_EXPRESSION - "^Ok\r?\n$" - ) - diff --git a/connectors/corrosion/test/workspace/workspace/CMakeLists.txt b/connectors/corrosion/test/workspace/workspace/CMakeLists.txt deleted file mode 100644 index c77029fe..00000000 --- a/connectors/corrosion/test/workspace/workspace/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(test_project VERSION 0.1.0) -include(../../test_header.cmake) - -corrosion_import_crate(MANIFEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/Cargo.toml CRATES member1 member2) - -#NOTE: member3 also contains a binary called my_program, but that shouldn't be a problem since it is not imported -add_executable(my_program main.cpp) -target_link_libraries(my_program PUBLIC member1 member2) diff --git a/connectors/corrosion/test/workspace/workspace/Cargo.toml b/connectors/corrosion/test/workspace/workspace/Cargo.toml deleted file mode 100644 index 402fa3ba..00000000 --- a/connectors/corrosion/test/workspace/workspace/Cargo.toml +++ /dev/null @@ -1,2 +0,0 @@ -[workspace] -members=["member1", "member2", "member3"] diff --git a/connectors/corrosion/test/workspace/workspace/main.cpp b/connectors/corrosion/test/workspace/workspace/main.cpp deleted file mode 100644 index 5102b28e..00000000 --- a/connectors/corrosion/test/workspace/workspace/main.cpp +++ /dev/null @@ -1,4 +0,0 @@ -#include -int main() { - std::cout << "Ok"; -} diff --git a/connectors/corrosion/test/workspace/workspace/member1/Cargo.toml b/connectors/corrosion/test/workspace/workspace/member1/Cargo.toml deleted file mode 100644 index b8a4d0a6..00000000 --- a/connectors/corrosion/test/workspace/workspace/member1/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "member1" -version = "0.1.0" -edition = "2018" -description = "descr;\"hello\\" - -[lib] -crate-type = [ "lib", "cdylib" ] diff --git a/connectors/corrosion/test/workspace/workspace/member1/src/lib.rs b/connectors/corrosion/test/workspace/workspace/member1/src/lib.rs deleted file mode 100644 index 31e1bb20..00000000 --- a/connectors/corrosion/test/workspace/workspace/member1/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } -} diff --git a/connectors/corrosion/test/workspace/workspace/member2/Cargo.toml b/connectors/corrosion/test/workspace/workspace/member2/Cargo.toml deleted file mode 100644 index 9fd2fe42..00000000 --- a/connectors/corrosion/test/workspace/workspace/member2/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "member2" -version = "0.1.0" -authors = ["Olivier Goffart "] -edition = "2018" - -[lib] -crate-type = ["staticlib"] diff --git a/connectors/corrosion/test/workspace/workspace/member2/src/lib.rs b/connectors/corrosion/test/workspace/workspace/member2/src/lib.rs deleted file mode 100644 index 31e1bb20..00000000 --- a/connectors/corrosion/test/workspace/workspace/member2/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); - } -} diff --git a/connectors/corrosion/test/workspace/workspace/member3/Cargo.toml b/connectors/corrosion/test/workspace/workspace/member3/Cargo.toml deleted file mode 100644 index ac7ef1f5..00000000 --- a/connectors/corrosion/test/workspace/workspace/member3/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "member3" -version = "0.1.0" -authors = ["Olivier Goffart "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[[bin]] -name = "my_program" -path = "src/main.rs" - -[dependencies] -member1 = { path = "../member1" } diff --git a/connectors/corrosion/test/workspace/workspace/member3/src/main.rs b/connectors/corrosion/test/workspace/workspace/member3/src/main.rs deleted file mode 100644 index e7a11a96..00000000 --- a/connectors/corrosion/test/workspace/workspace/member3/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} From 6e1bca21a0c65d480e5351c2f513cc143317fa0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?book=E8=AF=97=E6=84=8F?= Date: Wed, 16 Aug 2023 16:43:22 +0000 Subject: [PATCH 02/10] Change 'connectors/cargokit/' to 'cargokit/' --- Cargo.toml | 2 +- android/build.gradle | 2 +- ios/rust_in_flutter.podspec | 6 +++--- macos/rust_in_flutter.podspec | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ad323797..46d940d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] -members = ["./example/native/hub", "./connectors/cargokit/build_tool"] +members = ["./example/native/hub", "./cargokit/build_tool"] resolver = "2" diff --git a/android/build.gradle b/android/build.gradle index 868c0def..6864c513 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -59,7 +59,7 @@ android { } // Include Rust crates in the build process -apply from: "../connectors/cargokit/gradle/plugin.gradle" +apply from: "../cargokit/gradle/plugin.gradle" cargokit { manifestDir = "${rootProject.projectDir}/../native/hub" libname = "hub" diff --git a/ios/rust_in_flutter.podspec b/ios/rust_in_flutter.podspec index a598e265..baf3506d 100644 --- a/ios/rust_in_flutter.podspec +++ b/ios/rust_in_flutter.podspec @@ -25,10 +25,10 @@ Pod::Spec.new do |s| # Include Rust crates in the build process. s.script_phase = { :name => 'Build a Rust library', - :script => 'sh ${PODS_TARGET_SRCROOT}/../connectors/cargokit/build_pod.sh ${PROJECT_DIR}/../../native/hub hub', + :script => 'sh ${PODS_TARGET_SRCROOT}/../cargokit/build_pod.sh ${PROJECT_DIR}/../../native/hub hub', :execution_position=> :before_compile, - :input_files => ['${BUILT_PRODUCTS_DIR}/connectors/cargokit_phony'], - :output_files => ['${BUILT_PRODUCTS_DIR}/connectors/cargokit_phony_out', '${BUILT_PRODUCTS_DIR}/output.txt'], + :input_files => ['${BUILT_PRODUCTS_DIR}/cargokit_phony'], + :output_files => ['${BUILT_PRODUCTS_DIR}/cargokit_phony_out', '${BUILT_PRODUCTS_DIR}/output.txt'], } s.pod_target_xcconfig = { # From default Flutter template. diff --git a/macos/rust_in_flutter.podspec b/macos/rust_in_flutter.podspec index 2340ad1c..c7b327e1 100644 --- a/macos/rust_in_flutter.podspec +++ b/macos/rust_in_flutter.podspec @@ -25,10 +25,10 @@ Pod::Spec.new do |s| # Include Rust crates in the build process. s.script_phase = { :name => 'Build a Rust library', - :script => 'sh ${PODS_TARGET_SRCROOT}/../connectors/cargokit/build_pod.sh ${PROJECT_DIR}/../../native/hub hub', + :script => 'sh ${PODS_TARGET_SRCROOT}/../cargokit/build_pod.sh ${PROJECT_DIR}/../../native/hub hub', :execution_position=> :before_compile, - :input_files => ['${BUILT_PRODUCTS_DIR}/connectors/cargokit_phony'], - :output_files => ['${BUILT_PRODUCTS_DIR}/connectors/cargokit_phony_out', '${BUILT_PRODUCTS_DIR}/output.txt'], + :input_files => ['${BUILT_PRODUCTS_DIR}/cargokit_phony'], + :output_files => ['${BUILT_PRODUCTS_DIR}/cargokit_phony_out', '${BUILT_PRODUCTS_DIR}/output.txt'], } s.pod_target_xcconfig = { # From default Flutter template. From 385309e8e539e5087158127779159383c9a87eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?book=E8=AF=97=E6=84=8F?= Date: Wed, 16 Aug 2023 17:22:09 +0000 Subject: [PATCH 03/10] Delete ./windows/rust.cmake and ./linux/rust.cmake --- linux/rust.cmake | 14 -------------- windows/rust.cmake | 14 -------------- 2 files changed, 28 deletions(-) delete mode 100644 linux/rust.cmake delete mode 100644 windows/rust.cmake diff --git a/linux/rust.cmake b/linux/rust.cmake deleted file mode 100644 index 32a71818..00000000 --- a/linux/rust.cmake +++ /dev/null @@ -1,14 +0,0 @@ -add_subdirectory(../connectors/corrosion ${CMAKE_CURRENT_BINARY_DIR}/corrosion) - -cmake_policy(SET CMP0079 NEW) -corrosion_import_crate( - MANIFEST_PATH - ${CMAKE_SOURCE_DIR}/../native/hub/Cargo.toml -) -target_link_libraries(${BINARY_NAME} PUBLIC hub) - -set( - PLUGIN_BUNDLED_LIBRARIES - ${PLUGIN_BUNDLED_LIBRARIES} $ - PARENT_SCOPE -) diff --git a/windows/rust.cmake b/windows/rust.cmake deleted file mode 100644 index 23d6be0d..00000000 --- a/windows/rust.cmake +++ /dev/null @@ -1,14 +0,0 @@ -add_subdirectory(../connectors/corrosion ${CMAKE_CURRENT_BINARY_DIR}/corrosion) - -cmake_policy(SET CMP0079 NEW) -corrosion_import_crate( - MANIFEST_PATH - ${CMAKE_SOURCE_DIR}/../native/hub/Cargo.toml -) -target_link_libraries(${BINARY_NAME} PUBLIC hub) - -set( - PLUGIN_BUNDLED_LIBRARIES - ${PLUGIN_BUNDLED_LIBRARIES} $ - PARENT_SCOPE -) \ No newline at end of file From 26335ea13694e52e0ac71d0e396307620b6aaa79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?book=E8=AF=97=E6=84=8F?= Date: Thu, 17 Aug 2023 13:04:38 +0800 Subject: [PATCH 04/10] Build Android iOS macOS target OK --- android/build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/build.gradle b/android/build.gradle index 6864c513..a06a35cd 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -58,9 +58,10 @@ android { } } +def target = new File(rootProject.projectDir.parent) // Include Rust crates in the build process apply from: "../cargokit/gradle/plugin.gradle" cargokit { - manifestDir = "${rootProject.projectDir}/../native/hub" + manifestDir = "../${target.name}/native/hub" libname = "hub" } From 918451f9cc1d9e031c013910cad722a7cef818b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?book=E8=AF=97=E6=84=8F?= Date: Thu, 17 Aug 2023 09:23:44 +0000 Subject: [PATCH 05/10] Support linux target --- linux/CMakeLists.txt | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index afdacb1f..dd1ab1fb 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -21,5 +21,30 @@ set(rust_in_flutter_bundled_libraries PARENT_SCOPE ) -# Include the CMake build file of the Rust code. -include(./rust.cmake) \ No newline at end of file +apply_standard_settings(${BINARY_NAME}) + +set_target_properties(${BINARY_NAME} PROPERTIES + CXX_VISIBILITY_PRESET hidden + BUILD_RPATH_USE_ORIGIN ON +) + +target_compile_definitions(${BINARY_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) + +cmake_policy(SET CMP0079 NEW) + +target_link_libraries(${BINARY_NAME} PRIVATE flutter PkgConfig::GTK) + +include("../cargokit/cmake/cargokit.cmake") + +get_filename_component(TARGET_PATH "${CMAKE_SOURCE_DIR}" DIRECTORY) +get_filename_component(TARGET_NAME "${TARGET_PATH}" NAME) + +apply_cargokit(${BINARY_NAME} ../${TARGET_NAME}/native/hub hub "") + +target_link_libraries(${BINARY_NAME} PUBLIC hub) + +set( + PLUGIN_BUNDLED_LIBRARIES + ${PLUGIN_BUNDLED_LIBRARIES} $ + PARENT_SCOPE +) From c7c1ac53d1524d165db0797e8d2458474f9058aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?book=E8=AF=97=E6=84=8F?= Date: Thu, 17 Aug 2023 10:03:15 +0000 Subject: [PATCH 06/10] Update Windows, Linux target build tool --- linux/CMakeLists.txt | 29 ++--------------------------- linux/rust.cmake | 27 +++++++++++++++++++++++++++ windows/rust.cmake | 25 +++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 27 deletions(-) create mode 100644 linux/rust.cmake create mode 100644 windows/rust.cmake diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index dd1ab1fb..afdacb1f 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -21,30 +21,5 @@ set(rust_in_flutter_bundled_libraries PARENT_SCOPE ) -apply_standard_settings(${BINARY_NAME}) - -set_target_properties(${BINARY_NAME} PROPERTIES - CXX_VISIBILITY_PRESET hidden - BUILD_RPATH_USE_ORIGIN ON -) - -target_compile_definitions(${BINARY_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) - -cmake_policy(SET CMP0079 NEW) - -target_link_libraries(${BINARY_NAME} PRIVATE flutter PkgConfig::GTK) - -include("../cargokit/cmake/cargokit.cmake") - -get_filename_component(TARGET_PATH "${CMAKE_SOURCE_DIR}" DIRECTORY) -get_filename_component(TARGET_NAME "${TARGET_PATH}" NAME) - -apply_cargokit(${BINARY_NAME} ../${TARGET_NAME}/native/hub hub "") - -target_link_libraries(${BINARY_NAME} PUBLIC hub) - -set( - PLUGIN_BUNDLED_LIBRARIES - ${PLUGIN_BUNDLED_LIBRARIES} $ - PARENT_SCOPE -) +# Include the CMake build file of the Rust code. +include(./rust.cmake) \ No newline at end of file diff --git a/linux/rust.cmake b/linux/rust.cmake new file mode 100644 index 00000000..3642d9bb --- /dev/null +++ b/linux/rust.cmake @@ -0,0 +1,27 @@ +cmake_policy(SET CMP0079 NEW) + +apply_standard_settings(${BINARY_NAME}) + +set_target_properties(${BINARY_NAME} PROPERTIES + CXX_VISIBILITY_PRESET hidden + BUILD_RPATH_USE_ORIGIN ON +) + +target_compile_definitions(${BINARY_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) + +target_link_libraries(${BINARY_NAME} PRIVATE flutter PkgConfig::GTK) + +include("../cargokit/cmake/cargokit.cmake") + +get_filename_component(TARGET_PATH "${CMAKE_SOURCE_DIR}" DIRECTORY) +get_filename_component(TARGET_NAME "${TARGET_PATH}" NAME) + +apply_cargokit(${BINARY_NAME} ../${TARGET_NAME}/native/hub hub "") + +target_link_libraries(${BINARY_NAME} PUBLIC hub) + +set( + PLUGIN_BUNDLED_LIBRARIES + ${PLUGIN_BUNDLED_LIBRARIES} $ + PARENT_SCOPE +) diff --git a/windows/rust.cmake b/windows/rust.cmake new file mode 100644 index 00000000..1160ba66 --- /dev/null +++ b/windows/rust.cmake @@ -0,0 +1,25 @@ +cmake_policy(SET CMP0079 NEW) + +apply_standard_settings(${BINARY_NAME}) + +set_target_properties(${BINARY_NAME} PROPERTIES + CXX_VISIBILITY_PRESET hidden) + +target_compile_definitions(${BINARY_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) + +target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_plugin) + +include("../cargokit/cmake/cargokit.cmake") + +get_filename_component(TARGET_PATH "${CMAKE_SOURCE_DIR}" DIRECTORY) +get_filename_component(TARGET_NAME "${TARGET_PATH}" NAME) + +apply_cargokit(${BINARY_NAME} ../${TARGET_NAME}/native/hub hub hub_init) + +target_link_libraries(${BINARY_NAME} PUBLIC hub) + +set( + PLUGIN_BUNDLED_LIBRARIES + ${PLUGIN_BUNDLED_LIBRARIES} $ + PARENT_SCOPE +) From 124c210d0263ec03197e6ff062570612414294c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?book=E8=AF=97=E6=84=8F?= Date: Thu, 17 Aug 2023 18:58:24 +0800 Subject: [PATCH 07/10] More log of windows compilation --- .github/workflows/build_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_test.yaml b/.github/workflows/build_test.yaml index 904cbba2..1888fe3d 100644 --- a/.github/workflows/build_test.yaml +++ b/.github/workflows/build_test.yaml @@ -128,7 +128,7 @@ jobs: - name: Build example Flutter app if: matrix.target == 'windows' working-directory: example/ - run: flutter build windows + run: flutter build windows -v - name: Build example Flutter app if: matrix.target == 'macos' From 22dc87ca98ec21ba3310d03fc42d0a9054611a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?book=E8=AF=97=E6=84=8F?= Date: Thu, 17 Aug 2023 20:58:18 +0800 Subject: [PATCH 08/10] Move thanks ./connectors/README.md to README.md --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 61489148..7c402055 100644 --- a/README.md +++ b/README.md @@ -468,6 +468,18 @@ We appreciate your contribution to the development of this project! [![GitHub contributors (via allcontributors.org)](https://contrib.rocks/image?repo=cunarist/rust-in-flutter)](https://github.com/cunarist/rust-in-flutter/graphs/contributors) +# 👏 Thanks + +These are tools for connecting Flutter and native compilers. + +Rust-In-Flutter was not made alone. There were pioneers that gave inspiration to the structure of this package. Credits to these wonderful efforts! + +- https://github.com/fzyzcjy/flutter_rust_bridge +- https://github.com/superlistapp/super_native_extensions +- https://github.com/brickpop/flutter-rust-ffi +- https://github.com/corrosion-rs/corrosion +- https://github.com/irondash/cargokit + # ☕ Support Us If you are benefiting from the features of Rust-In-Flutter and find it helpful, why not consider supporting this project? Your generous donations contribute to the maintenance and development of Rust-In-Flutter, ensuring its continuous improvement and growth. 😉 From bb1d88c8d9a1875762e370522f6bc848403cb7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?book=E8=AF=97=E6=84=8F?= Date: Thu, 17 Aug 2023 21:43:21 +0800 Subject: [PATCH 09/10] Adapt to CI cargo clippy --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 46d940d1..f1eeb854 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] -members = ["./example/native/hub", "./cargokit/build_tool"] +members = ["example/native/hub", "cargokit/build_tool"] resolver = "2" From e1f121591140ad2e46961455923d23954a31844e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?book=E8=AF=97=E6=84=8F?= Date: Wed, 23 Aug 2023 01:23:58 +0800 Subject: [PATCH 10/10] Update cargokit --- cargokit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cargokit b/cargokit index 54ae0380..5d6e4df8 160000 --- a/cargokit +++ b/cargokit @@ -1 +1 @@ -Subproject commit 54ae0380f0d85c31733b4e3f4bd34fbfb7003a35 +Subproject commit 5d6e4df801fae0ee6a137ee005febb4b6cdd0ff2