Skip to content

Commit

Permalink
WIP: Support custom Rust targets
Browse files Browse the repository at this point in the history
Support custom Rust targets defined in a JSON file.

Signed-off-by: Jonathan Schwender <[email protected]>
  • Loading branch information
jschwe committed Sep 12, 2022
1 parent 0416713 commit a304e4d
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cmake/Corrosion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,13 @@ function(_corrosion_parse_platform manifest rust_version target_triple)
# 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.
# The target-triple may optionally also be a path to a json file, however we still require the
# filename (wihout the extenion) to follow the "arch-(vendor-)os(-env)" syntax.
# todo: alternatively we could just pass the target triple through as is if parsing fails,
# and just not add any libs or other os dependent options, since it is likely a custom OS
# anyway.
string(REGEX MATCH
"^([^-]+)-((${known_vendors_joined})-)?([^-]+)(-([^-]+))?$"
"([a-z0-9_]+)-((${known_vendors_joined})-)?([a-z0-9_]+)(-([a-z0-9_]+))?(\.json)?$"
whole_match
"${target_triple}"
)
Expand Down
20 changes: 20 additions & 0 deletions test/config/ParseTargetTriple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This test is supposed to ensure that the regex in _corrosion_parse_platform works as expected.
cmake_minimum_required(VERSION 3.15)

project(ParseTargetTriple LANGUAGES C)

add_subdirectory(../../.. corrosion)


# Important built-in target triples.
_corrosion_parse_platform("Cargo.toml" "1.55" "x86_64-unknown-linux-gnu")
_corrosion_parse_platform("Cargo.toml" "1.55" "aarch64-unknown-linux-gnu")
_corrosion_parse_platform("Cargo.toml" "1.55" "aarch64-fuchsia")

# 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")


1 change: 1 addition & 0 deletions test/config/ParseTargetTriple/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Pseudo manifest, just used in CMake to set some source file properties.
10 changes: 10 additions & 0 deletions test/config/ParseTargetTriple/Test.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
execute_process(
COMMAND
${CMAKE_COMMAND} ${CMAKE_CURRENT_LIST_DIR}
COMMAND_ECHO STDOUT
RESULT_VARIABLE SUCCESS
)

if (NOT SUCCESS EQUAL 0)
message(FATAL_ERROR)
endif()
7 changes: 7 additions & 0 deletions test/multitarget/Cargo.lock

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

0 comments on commit a304e4d

Please sign in to comment.