-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add CPM and Rust support #4
Open
madskjeldgaard
wants to merge
1
commit into
sudara:main
Choose a base branch
from
madskjeldgaard:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors | ||
|
||
set(CPM_DOWNLOAD_VERSION 0.38.7) | ||
set(CPM_HASH_SUM "83e5eb71b2bbb8b1f2ad38f1950287a057624e385c238f6087f94cdfc44af9c5") | ||
|
||
if(CPM_SOURCE_CACHE) | ||
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") | ||
elseif(DEFINED ENV{CPM_SOURCE_CACHE}) | ||
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") | ||
else() | ||
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") | ||
endif() | ||
|
||
# Expand relative path. This is important if the provided path contains a tilde (~) | ||
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) | ||
|
||
file(DOWNLOAD | ||
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake | ||
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} | ||
) | ||
|
||
include(${CPM_DOWNLOAD_LOCATION}) |
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,39 @@ | ||
# Dependencies that are downloaded using the CPM package manager | ||
include("${CMAKE_CURRENT_LIST_DIR}/CPM.cmake") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this be a problem if CPM is already included? Do we need something like https://cmake.org/cmake/help/latest/command/include_guard.html ? |
||
|
||
option(USE_RUST "Use Rust" ON) | ||
if(USE_RUST) | ||
|
||
# Define USING_RUST to be used in C++ code | ||
add_definitions(-DUSING_RUST) | ||
|
||
# Install corrosion – a Rust to C++ bridge | ||
cpmaddpackage(NAME Corrosion GITHUB_REPOSITORY corrosion-rs/corrosion GIT_TAG | ||
v0.4.7) | ||
|
||
# Rust directory: rust in root dir | ||
set(RUST_DIR "${CMAKE_CURRENT_SOURCE_DIR}/rust") | ||
|
||
# Add a rust library After this, all you need to do is link to the rust | ||
# library in your C++ like this: target_link_libraries(SharedCode INTERFACE | ||
# myrustlib) | ||
corrosion_import_crate(MANIFEST_PATH "${RUST_DIR}/{{ cookiecutter.__rust_lib_name }}/Cargo.toml") | ||
|
||
corrosion_add_cxxbridge( | ||
{{ cookiecutter.__rust_lib_name }} | ||
CRATE | ||
{{ cookiecutter.__rust_crate_name }} | ||
MANIFEST_PATH | ||
"${RUST_DIR}/{{ cookiecutter.__rust_lib_name }}" | ||
# NOTE: These file paths are relative to the root of the rust crate's src | ||
# dir eg rust/{{ cookiecutter.__rust_lib_name }}/src. | ||
FILES | ||
"lib.rs") | ||
|
||
if(MSVC) | ||
# Note: This is required because we use `cxx` which uses `cc` to compile and | ||
# link C++ code. | ||
corrosion_set_env_vars({{ cookiecutter.__rust_crate_name }} "CFLAGS=-MDd" "CXXFLAGS=-MDd") | ||
endif() | ||
|
||
endif() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the best practice for finding this hash and bumping the version, etc?...