Skip to content

Commit 4bd06b0

Browse files
committed
Add rust project with tests working properly.
1 parent 1cba24a commit 4bd06b0

File tree

22 files changed

+421
-48
lines changed

22 files changed

+421
-48
lines changed

source/loaders/rs_loader/CMakeLists.txt

Lines changed: 182 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_RS)
44
endif()
55

66
#
7-
# Plugin name and options
7+
# External dependencies
88
#
99

1010
find_package(Rust)
@@ -14,44 +14,202 @@ if(NOT RUST_FOUND)
1414
return()
1515
endif()
1616

17+
add_subdirectory(rust)
18+
19+
#
20+
# Plugin name and options
21+
#
22+
1723
# Target name
1824
set(target rs_loader)
1925

2026
# Exit here if required dependencies are not met
2127
message(STATUS "Plugin ${target}")
2228

23-
set(TARGET_BUILD_NAME "${CMAKE_SHARED_LIBRARY_PREFIX}rs_loader${CMAKE_SHARED_LIBRARY_SUFFIX}")
29+
# Set API export file and macro
30+
string(TOUPPER ${target} target_upper)
31+
set(feature_file "include/${target}/${target}_features.h")
32+
set(export_file "include/${target}/${target}_api.h")
33+
set(export_macro "${target_upper}_API")
2434

25-
if(CMAKE_BUILD_TYPE STREQUAL "Release")
26-
set(TARGET_BUILD_TYPE "--release")
27-
set(TARGET_BUILD_PATH "${CMAKE_CURRENT_SOURCE_DIR}/target/release/${TARGET_BUILD_NAME}")
28-
set(TARGET_OUTPUT_NAME "${CMAKE_SHARED_LIBRARY_PREFIX}rs_loader${CMAKE_SHARED_LIBRARY_SUFFIX}")
29-
else()
30-
set(TARGET_BUILD_TYPE)
31-
set(TARGET_BUILD_PATH "${CMAKE_CURRENT_SOURCE_DIR}/target/debug/${TARGET_BUILD_NAME}")
32-
set(TARGET_OUTPUT_NAME "${CMAKE_SHARED_LIBRARY_PREFIX}rs_loaderd${CMAKE_SHARED_LIBRARY_SUFFIX}")
33-
endif()
35+
#
36+
# Compiler warnings
37+
#
38+
39+
include(Warnings)
40+
41+
#
42+
# Compiler security
43+
#
44+
45+
include(SecurityFlags)
46+
47+
#
48+
# Sources
49+
#
50+
51+
set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}")
52+
set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")
3453

35-
if(MSVC)
36-
set(TARGET_OUTPUT_PATH "${PROJECT_BINARY_DIR}/${CMAKE_BUILD_TYPE}")
54+
set(headers
55+
${include_path}/rs_loader.h
56+
${include_path}/rs_loader_impl.h
57+
)
58+
59+
set(sources
60+
${source_path}/rs_loader.c
61+
)
62+
63+
# Group source files
64+
set(header_group "Header Files (API)")
65+
set(source_group "Source Files")
66+
source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$"
67+
${header_group} ${headers})
68+
source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$"
69+
${source_group} ${sources})
70+
71+
#
72+
# Create library
73+
#
74+
75+
# Build library
76+
add_library(${target}
77+
${sources}
78+
${headers}
79+
)
80+
81+
add_dependencies(${target} rs_loader_impl)
82+
83+
# Create namespaced alias
84+
add_library(${META_PROJECT_NAME}::${target} ALIAS ${target})
85+
86+
# Export library for downstream projects
87+
export(TARGETS ${target} NAMESPACE ${META_PROJECT_NAME}:: FILE ${PROJECT_BINARY_DIR}/cmake/${target}/${target}-export.cmake)
88+
89+
# Create feature detection header
90+
# Compilers: https://cmake.org/cmake/help/v3.1/variable/CMAKE_LANG_COMPILER_ID.html#variable:CMAKE_%3CLANG%3E_COMPILER_ID
91+
# Feature: https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html
92+
93+
# Check for availability of module; use pre-generated version if not found
94+
if (WriterCompilerDetectionHeaderFound)
95+
write_compiler_detection_header(
96+
FILE ${feature_file}
97+
PREFIX ${target_upper}
98+
COMPILERS AppleClang Clang GNU MSVC
99+
FEATURES cxx_alignas cxx_alignof cxx_constexpr cxx_final cxx_noexcept cxx_nullptr cxx_sizeof_member cxx_thread_local
100+
VERSION 3.2
101+
)
37102
else()
38-
set(TARGET_OUTPUT_PATH "${PROJECT_BINARY_DIR}")
103+
file(
104+
COPY ${PROJECT_SOURCE_DIR}/codegeneration/${target}_features.h
105+
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/${target}
106+
USE_SOURCE_PERMISSIONS
107+
)
39108
endif()
40109

41-
# Build without internet access
42-
add_custom_target(${target}
43-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
44-
COMMAND ${CARGO_EXECUTABLE} build ${TARGET_BUILD_TYPE}
45-
COMMAND ${CMAKE_COMMAND} -E copy ${TARGET_BUILD_PATH} ${TARGET_OUTPUT_PATH}/${TARGET_OUTPUT_NAME}
110+
# Create API export header
111+
generate_export_header(${target}
112+
EXPORT_FILE_NAME ${export_file}
113+
EXPORT_MACRO_NAME ${export_macro}
114+
)
115+
116+
#
117+
# Project options
118+
#
119+
120+
set_target_properties(${target}
121+
PROPERTIES
122+
${DEFAULT_PROJECT_OPTIONS}
123+
FOLDER "${IDE_FOLDER}"
124+
BUNDLE $<$<BOOL:${APPLE}>:$<$<VERSION_GREATER:${PROJECT_OS_VERSION},8>>>
125+
)
126+
127+
#
128+
# Include directories
129+
#
130+
131+
target_include_directories(${target}
132+
PRIVATE
133+
${PROJECT_BINARY_DIR}/source/include
134+
${CMAKE_CURRENT_SOURCE_DIR}/include
135+
${CMAKE_CURRENT_BINARY_DIR}/include
136+
137+
$<TARGET_PROPERTY:${META_PROJECT_NAME}::metacall,INCLUDE_DIRECTORIES> # MetaCall includes
138+
139+
PUBLIC
140+
${DEFAULT_INCLUDE_DIRECTORIES}
141+
142+
INTERFACE
143+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
144+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
145+
$<INSTALL_INTERFACE:include>
146+
)
147+
148+
#
149+
# Libraries
150+
#
151+
152+
get_target_property(RS_LOADER_IMPL rs_loader_impl OUTPUT_NAME)
153+
154+
target_link_libraries(${target}
155+
PRIVATE
156+
${META_PROJECT_NAME}::metacall # MetaCall library
157+
${RS_LOADER_IMPL} # Rust implementation library
158+
159+
PUBLIC
160+
${DEFAULT_LIBRARIES}
161+
162+
INTERFACE
163+
)
164+
165+
#
166+
# Compile definitions
167+
#
168+
169+
target_compile_definitions(${target}
170+
PRIVATE
171+
172+
PUBLIC
173+
$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:${target_upper}_STATIC_DEFINE>
174+
${DEFAULT_COMPILE_DEFINITIONS}
175+
176+
INTERFACE
177+
)
178+
179+
#
180+
# Compile options
181+
#
182+
183+
target_compile_options(${target}
184+
PRIVATE
185+
186+
PUBLIC
187+
${DEFAULT_COMPILE_OPTIONS}
188+
189+
INTERFACE
190+
)
191+
192+
#
193+
# Linker options
194+
#
195+
196+
target_link_libraries(${target}
197+
PRIVATE
198+
199+
PUBLIC
200+
${DEFAULT_LINKER_OPTIONS}
201+
202+
INTERFACE
46203
)
47204

48205
#
49206
# Deployment
50207
#
51208

52-
# Files
53-
install(FILES
54-
${TARGET_OUTPUT_PATH}/${TARGET_OUTPUT_NAME}
55-
DESTINATION ${INSTALL_LIB}
56-
COMPONENT runtime
209+
# Library
210+
install(TARGETS ${target}
211+
EXPORT "${target}-export" COMPONENT dev
212+
RUNTIME DESTINATION ${INSTALL_BIN} COMPONENT runtime
213+
LIBRARY DESTINATION ${INSTALL_SHARED} COMPONENT runtime
214+
ARCHIVE DESTINATION ${INSTALL_LIB} COMPONENT dev
57215
)

source/loaders/rs_loader/Cargo.lock

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Loader Library by Parra Studios
3+
* A plugin for loading rust code at run-time into a process.
4+
*
5+
* Copyright (C) 2016 - 2021 Vicente Eduardo Ferrer Garcia <[email protected]>
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
#ifndef RS_LOADER_H
22+
#define RS_LOADER_H 1
23+
24+
#include <rs_loader/rs_loader_api.h>
25+
26+
#include <loader/loader_impl_interface.h>
27+
28+
#include <dynlink/dynlink.h>
29+
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
34+
RS_LOADER_API loader_impl_interface rs_loader_impl_interface_singleton(void);
35+
36+
DYNLINK_SYMBOL_EXPORT(rs_loader_impl_interface_singleton);
37+
38+
RS_LOADER_API const char *rs_loader_print_info(void);
39+
40+
DYNLINK_SYMBOL_EXPORT(rs_loader_print_info);
41+
42+
#ifdef __cplusplus
43+
}
44+
#endif
45+
46+
#endif /* RS_LOADER_H */
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Loader Library by Parra Studios
3+
* A plugin for loading rust code at run-time into a process.
4+
*
5+
* Copyright (C) 2016 - 2021 Vicente Eduardo Ferrer Garcia <[email protected]>
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
#ifndef RS_LOADER_IMPL_H
22+
#define RS_LOADER_IMPL_H 1
23+
24+
#include <rs_loader/rs_loader_api.h>
25+
26+
#include <loader/loader_impl_interface.h>
27+
28+
#include <configuration/configuration.h>
29+
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
34+
RS_LOADER_API loader_impl_data rs_loader_impl_initialize(loader_impl impl, configuration config);
35+
36+
RS_LOADER_API int rs_loader_impl_execution_path(loader_impl impl, const loader_naming_path path);
37+
38+
RS_LOADER_API loader_handle rs_loader_impl_load_from_file(loader_impl impl, const loader_naming_path paths[], size_t size);
39+
40+
RS_LOADER_API loader_handle rs_loader_impl_load_from_memory(loader_impl impl, const loader_naming_name name, const char *buffer, size_t size);
41+
42+
RS_LOADER_API loader_handle rs_loader_impl_load_from_package(loader_impl impl, const loader_naming_path path);
43+
44+
RS_LOADER_API int rs_loader_impl_clear(loader_impl impl, loader_handle handle);
45+
46+
RS_LOADER_API int rs_loader_impl_discover(loader_impl impl, loader_handle handle, context ctx);
47+
48+
RS_LOADER_API int rs_loader_impl_destroy(loader_impl impl);
49+
50+
#ifdef __cplusplus
51+
}
52+
#endif
53+
54+
#endif /* RS_LOADER_IMPL_H */
File renamed without changes.

0 commit comments

Comments
 (0)