-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for installing an executable
Tests installing an executable to the default location
- Loading branch information
Showing
8 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
**/target/ | ||
**/*.rs.bk | ||
build*/ | ||
install*/ | ||
.vscode | ||
.idea | ||
cmake-build-* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
if(NOT (CMAKE_CROSSCOMPILING AND MSVC)) | ||
# When using MSVC the cmake build via ExternalProject seems to inherit the target architecture, | ||
# which breaks the test. Since we practically don't care about this, and we just want to ensure | ||
# that installing an executable works, skipping this test when cross-compiling is fine. | ||
corrosion_tests_add_test(install_rust_bin "generated_from_installed_bin") | ||
|
||
set_tests_properties("install_rust_bin_run_generated_from_installed_bin" | ||
PROPERTIES PASS_REGULAR_EXPRESSION | ||
"Hello World! I'm generated code" | ||
) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
cmake_minimum_required(VERSION 3.22) | ||
project(test_project VERSION 0.1.0) | ||
|
||
# Note: Corrosion supports `hostbuild`, so building a Rust binary in a subproject | ||
# like this doesn't offer any benefit over using the hostbuild option. | ||
# However, this is a reasonable way to test that installing Rust binaries via | ||
# corrosion_install works as expected. | ||
include(ExternalProject) | ||
|
||
set(bin_suffix "") | ||
if(CMAKE_HOST_WIN32) | ||
set(bin_suffix ".exe") | ||
endif() | ||
set(generator_bin_path "${CMAKE_CURRENT_BINARY_DIR}/rust_bin/bin/my_rust_bin${bin_suffix}") | ||
|
||
ExternalProject_Add( | ||
rust_bin | ||
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/rust_bin" | ||
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/rust_bin" | ||
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/rust_bin" | ||
) | ||
|
||
# This custom command is the main part of the test: | ||
# We test that corrosion (in the CMake of the ExternalProject) properly installed | ||
# a Rust executable to the location we specified by running the executable, which generates some cpp code. | ||
add_custom_command( | ||
OUTPUT generated_main.cpp | ||
COMMAND "${generator_bin_path}" > "${CMAKE_CURRENT_BINARY_DIR}/generated_main.cpp" | ||
DEPENDS rust_bin | ||
) | ||
|
||
add_executable(generated_from_installed_bin ${CMAKE_CURRENT_BINARY_DIR}/generated_main.cpp) |
7 changes: 7 additions & 0 deletions
7
test/corrosion_install/install_rust_bin/rust_bin/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
cmake_minimum_required(VERSION 3.22) | ||
project(test_rust_bin VERSION 0.1.0) | ||
include(../../../test_header.cmake) | ||
include(GNUInstallDirs) | ||
|
||
corrosion_import_crate(MANIFEST_PATH Cargo.toml) | ||
corrosion_install(TARGETS my_rust_bin) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "my_rust_bin" | ||
version = "0.1.0" | ||
edition = "2018" | ||
license = "MIT" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fn main() { | ||
println!( | ||
"#include <iostream> | ||
int main() {{ | ||
std::cout << \"Hello World! I'm generated code\"; | ||
return 0; | ||
}}" | ||
); | ||
} |