Skip to content

Commit 1cba24a

Browse files
committed
Add tests for rust loader.
1 parent 931f028 commit 1cba24a

File tree

10 files changed

+322
-0
lines changed

10 files changed

+322
-0
lines changed

source/scripts/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ option(OPTION_BUILD_SCRIPTS_LUA "Build Lua scripts." ON)
2323
option(OPTION_BUILD_SCRIPTS_NODE "Build NodeJS scripts." ON)
2424
option(OPTION_BUILD_SCRIPTS_PY "Build Python scripts." ON)
2525
option(OPTION_BUILD_SCRIPTS_RB "Build Ruby scripts." ON)
26+
option(OPTION_BUILD_SCRIPTS_RS "Build Rust scripts." ON)
2627
option(OPTION_BUILD_SCRIPTS_RPC "Build RPC scripts." ON)
2728
option(OPTION_BUILD_SCRIPTS_TS "Build TypeScript scripts." ON)
2829
option(OPTION_BUILD_SCRIPTS_WASM "Build WebAssembly scripts." ON)
@@ -39,6 +40,7 @@ add_subdirectory(llvm)
3940
add_subdirectory(node)
4041
add_subdirectory(python)
4142
add_subdirectory(ruby)
43+
add_subdirectory(rust)
4244
add_subdirectory(rpc)
4345
add_subdirectory(typescript)
4446
add_subdirectory(wasm)

source/scripts/rust/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Check if this script is enabled
2+
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_RS OR NOT OPTION_BUILD_SCRIPTS OR NOT OPTION_BUILD_SCRIPTS_RS)
3+
return()
4+
endif()
5+
6+
# Append cmake path
7+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
8+
9+
# Wasm project utility
10+
include(RustProject)
11+
12+
add_subdirectory(basic)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# Configure Rust project
3+
#
4+
5+
rust_project(basic 0.1.0)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# Rust project generator by Parra Studios
3+
# Generates a Rust project embedded into CMake.
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+
if(RUSTPROJECT_FOUND)
21+
return()
22+
endif()
23+
24+
set(RUSTPROJECT_FOUND YES)
25+
26+
#
27+
# Generic script project generator
28+
#
29+
30+
include(ScriptProject)
31+
32+
# Define current Rust project configuration path
33+
get_filename_component(RUST_PROJECT_CONFIG_PATH ${CMAKE_CURRENT_LIST_FILE} PATH)
34+
35+
#
36+
# Rust sub-project util function
37+
#
38+
39+
function(rust_project target version)
40+
41+
# TODO
42+
43+
# Configuration
44+
set(PACKAGE_NAME ${target})
45+
set(PACKAGE_VERSION ${version})
46+
set(PACKAGE_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/timestamp")
47+
48+
# Create project file
49+
script_project(${target} rust ${RUST_PROJECT_CONFIG_PATH}/RustProject.cmake.in)
50+
51+
endfunction()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# WebAssembly project generator by Parra Studios
3+
# Generates a WebAssembly project embedded into CMake.
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+
# Check if this loader is enabled
21+
if(NOT OPTION_BUILD_SCRIPTS OR NOT OPTION_BUILD_SCRIPTS_RS)
22+
return()
23+
endif()
24+
25+
#
26+
# External dependencies
27+
#
28+
29+
# TODO
30+
31+
# Target name
32+
set(target @PACKAGE_NAME@)
33+
34+
# Exit here if required dependencies are not met
35+
message(STATUS "Script ${target}")

source/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,4 @@ add_subdirectory(metacall_julia_test)
203203
add_subdirectory(metacall_java_test)
204204
add_subdirectory(metacall_wasm_loader_test)
205205
add_subdirectory(metacall_wasm_python_port_test)
206+
add_subdirectory(metacall_rust_test)
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Check if this loader is enabled
2+
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_RS OR NOT OPTION_BUILD_SCRIPTS OR NOT OPTION_BUILD_SCRIPTS_RS)
3+
return()
4+
endif()
5+
6+
#
7+
# Executable name and options
8+
#
9+
10+
# Target name
11+
set(target metacall-rust-test)
12+
message(STATUS "Test ${target}")
13+
14+
#
15+
# Compiler warnings
16+
#
17+
18+
include(Warnings)
19+
20+
#
21+
# Compiler security
22+
#
23+
24+
include(SecurityFlags)
25+
26+
#
27+
# Sources
28+
#
29+
30+
set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}")
31+
set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")
32+
33+
set(sources
34+
${source_path}/main.cpp
35+
${source_path}/metacall_rust_test.cpp
36+
)
37+
38+
# Group source files
39+
set(header_group "Header Files (API)")
40+
set(source_group "Source Files")
41+
source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$"
42+
${header_group} ${headers})
43+
source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$"
44+
${source_group} ${sources})
45+
46+
#
47+
# Create executable
48+
#
49+
50+
# Build executable
51+
add_executable(${target}
52+
${sources}
53+
)
54+
55+
# Create namespaced alias
56+
add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target})
57+
58+
#
59+
# Project options
60+
#
61+
62+
set_target_properties(${target}
63+
PROPERTIES
64+
${DEFAULT_PROJECT_OPTIONS}
65+
FOLDER "${IDE_FOLDER}"
66+
)
67+
68+
#
69+
# Include directories
70+
#
71+
72+
target_include_directories(${target}
73+
PRIVATE
74+
${DEFAULT_INCLUDE_DIRECTORIES}
75+
${PROJECT_BINARY_DIR}/source/include
76+
)
77+
78+
#
79+
# Libraries
80+
#
81+
82+
target_link_libraries(${target}
83+
PRIVATE
84+
${DEFAULT_LIBRARIES}
85+
86+
GTest
87+
88+
${META_PROJECT_NAME}::metacall
89+
)
90+
91+
#
92+
# Compile definitions
93+
#
94+
95+
target_compile_definitions(${target}
96+
PRIVATE
97+
${DEFAULT_COMPILE_DEFINITIONS}
98+
)
99+
100+
#
101+
# Compile options
102+
#
103+
104+
target_compile_options(${target}
105+
PRIVATE
106+
${DEFAULT_COMPILE_OPTIONS}
107+
)
108+
109+
#
110+
# Linker options
111+
#
112+
113+
target_link_libraries(${target}
114+
PRIVATE
115+
${DEFAULT_LINKER_OPTIONS}
116+
)
117+
118+
#
119+
# Define test
120+
#
121+
122+
add_test(NAME ${target}
123+
COMMAND $<TARGET_FILE:${target}>
124+
)
125+
126+
#
127+
# Define dependencies
128+
#
129+
130+
add_dependencies(${target}
131+
rs_loader
132+
)
133+
134+
#
135+
# Define test properties
136+
#
137+
138+
set_property(TEST ${target}
139+
PROPERTY LABELS ${target}
140+
)
141+
142+
include(TestEnvironmentVariables)
143+
144+
test_environment_variables(${target}
145+
""
146+
${TESTS_ENVIRONMENT_VARIABLES}
147+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Loader Library by Parra Studios
3+
* A plugin for loading ruby 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+
#include <gtest/gtest.h>
22+
23+
int main(int argc, char *argv[])
24+
{
25+
::testing::InitGoogleTest(&argc, argv);
26+
27+
return RUN_ALL_TESTS();
28+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Loader Library by Parra Studios
3+
* A plugin for loading ruby 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+
#include <gtest/gtest.h>
22+
23+
#include <metacall/metacall.h>
24+
25+
class metacall_rs_test : public testing::Test
26+
{
27+
protected:
28+
};
29+
30+
TEST_F(metacall_rs_test, DefaultConstructor)
31+
{
32+
const char *rs_scripts[] = {
33+
"hello.rs"
34+
};
35+
36+
ASSERT_EQ((int)0, (int)metacall_initialize());
37+
38+
EXPECT_EQ((int)0, (int)metacall_load_from_file("rs", rs_scripts, sizeof(rs_scripts) / sizeof(rs_scripts[0]), NULL));
39+
40+
EXPECT_EQ((int)0, (int)metacall_destroy());
41+
}

0 commit comments

Comments
 (0)