Skip to content

Commit 12ecf23

Browse files
authored
Merge pull request #533 from metacall/feature/run-outside-metacall-cli
Implement support for running MetaCall from `python.exe` and `node.exe`.
2 parents b8e6f32 + 120a383 commit 12ecf23

File tree

478 files changed

+2653
-1727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

478 files changed

+2653
-1727
lines changed

.github/workflows/docker-hub-platform.yml

+37-23
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ jobs:
9494
manifest:
9595
name: Create and Push Manifest Lists
9696
needs: build
97+
# Only run when master or when tagging a version
98+
if: (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')) && github.event_name != 'pull_request'
9799
runs-on: ubuntu-latest
98100
steps:
99101
- name: Login to Docker Hub
@@ -104,10 +106,15 @@ jobs:
104106

105107
- name: Create and Push Manifest Lists
106108
run: |
107-
for tag in "deps" "dev" "runtime" "cli"; do
109+
tags=("deps" "dev" "runtime" "cli")
110+
platforms=("linux/amd64" "linux/386" "linux/arm64" "linux/riscv64" "linux/ppc64le" "linux/s390x" "linux/arm/v7" "linux/arm/v6")
111+
112+
echo "Create all the tags by platform"
113+
114+
for tag in "${tags[@]}"; do
108115
echo "Creating manifest for tag: $tag"
109116
platform_tags=""
110-
for platform in "linux/amd64" "linux/386" "linux/arm64" "linux/riscv64" "linux/ppc64le" "linux/s390x" "linux/arm/v7" "linux/arm/v6"; do
117+
for platform in "${platforms[@]}"; do
111118
platform_tag=$(echo "${platform}" | tr '/' '-')
112119
platform_tags="${platform_tags} ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${IMAGE_NAME}:${tag}-${platform_tag}"
113120
done
@@ -116,28 +123,32 @@ jobs:
116123
docker manifest push ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${IMAGE_NAME}:${tag}
117124
done
118125
119-
- name: Create Version Specific Tags
120-
if: startsWith(github.ref, 'refs/tags/')
121-
run: |
122-
VERSION=${GITHUB_REF#refs/tags/v}
123-
tags=("deps" "dev" "runtime" "cli")
124-
platforms=("linux/amd64" "linux/386" "linux/arm64" "linux/riscv64" "linux/ppc64le" "linux/s390x" "linux/arm/v7" "linux/arm/v6")
125-
for tag in "${tags[@]}"; do
126-
platform_tags=""
127-
for platform in "${platforms[@]}"; do
128-
platform_tags="${platform_tags} ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${IMAGE_NAME}:${tag}-${platform}"
129-
done
130-
docker manifest create ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${IMAGE_NAME}:${VERSION}-${tag} ${platform_tags} --amend
131-
docker manifest push ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${IMAGE_NAME}:${VERSION}-${tag}
132-
done
126+
echo "Create the latest tag"
133127
134128
cli_platform_tags=""
135-
for platform in ${{ matrix.platform }}; do
136-
cli_platform_tags="${cli_platform_tags} ${DOCKER_USERNAME}/${IMAGE_NAME}:cli-${platform}"
129+
for platform in ${platforms[@]}"; do
130+
platform_tag=$(echo "${platform}" | tr '/' '-')
131+
cli_platform_tags="${cli_platform_tags} ${DOCKER_USERNAME}/${IMAGE_NAME}:cli-${platform_tag}"
137132
done
138133
docker manifest create ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${IMAGE_NAME}:latest ${cli_platform_tags} --amend
139134
docker manifest push ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${IMAGE_NAME}:latest
140135
136+
if [[ "${{ startsWith(github.ref, 'refs/tags/') }}" = true ]]; then
137+
VERSION=${GITHUB_REF#refs/tags/v}
138+
139+
echo "Create the version ${VERSION} tag"
140+
141+
for tag in "${tags[@]}"; do
142+
platform_tags=""
143+
for platform in "${platforms[@]}"; do
144+
platform_tag=$(echo "${platform}" | tr '/' '-')
145+
platform_tags="${platform_tags} ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${IMAGE_NAME}:${tag}-${platform_tag}"
146+
done
147+
docker manifest create ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${IMAGE_NAME}:${VERSION}-${tag} ${platform_tags} --amend
148+
docker manifest push ${DOCKER_REGISTRY}/${DOCKER_USERNAME}/${IMAGE_NAME}:${VERSION}-${tag}
149+
done
150+
fi
151+
141152
cleanup:
142153
name: Cleanup Platform Specific Tags
143154
needs: [build, manifest]
@@ -146,16 +157,19 @@ jobs:
146157
steps:
147158
- name: Remove Platform-Specific Tags
148159
run: |
149-
platforms=("linux-amd64" "linux-386" "linux-arm64" "linux-riscv64" "linux-ppc64le" "linux-s390x" "linux-arm-v7" "linux-arm-v6")
150160
tags=("deps" "dev" "runtime" "cli")
161+
platforms=("linux/amd64" "linux/386" "linux/arm64" "linux/riscv64" "linux/ppc64le" "linux/s390x" "linux/arm/v7" "linux/arm/v6")
162+
163+
for tag in "${tags[@]}"; do
164+
for platform in "${platforms[@]}"; do
165+
platform_tag=$(echo "${platform}" | tr '/' '-')
166+
tag_to_delete="${tag}-${platform_tag}"
151167
152-
for platform in "${platforms[@]}"; do
153-
for tag in "${tags[@]}"; do
154-
tag_to_delete="${tag}-${platform}"
155168
echo "Deleting tag: ${tag_to_delete}"
169+
echo "https://hub.docker.com/v2/repositories/${DOCKER_USERNAME}/${IMAGE_NAME}/tags/${tag_to_delete}/"
156170
157171
curl -X DELETE \
158-
-H "Authorization: Bearer ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}" \
172+
-H "Authorization: Bearer ${{ secrets.DOCKER_HUB_ACCESS_TOKEN_DELETE }}" \
159173
"https://hub.docker.com/v2/repositories/${DOCKER_USERNAME}/${IMAGE_NAME}/tags/${tag_to_delete}/"
160174
done
161175
done

CMakeLists.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#
2323

2424
# CMake version
25-
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
25+
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
2626

2727
# Include cmake modules
2828

@@ -241,6 +241,9 @@ else()
241241
endif()
242242
endif()
243243

244+
# Export compile commands
245+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
246+
244247
#
245248
# CTest configuration
246249
#

cmake/CompileOptions.cmake

+66
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,72 @@ else()
149149
set(SANITIZER_COMPILE_DEFINITIONS)
150150
endif()
151151

152+
function(find_sanitizer NAME LINK_OPTION)
153+
string(TOUPPER "${NAME}" NAME_UPPER)
154+
set(SANITIZER_PROGRAM_CODE "int main() {return 0;}")
155+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/sanitizer_locate.cpp" "${SANITIZER_PROGRAM_CODE}")
156+
157+
try_compile(
158+
STATUS
159+
${PROJECT_OUTPUT_DIR}
160+
${CMAKE_CURRENT_BINARY_DIR}/sanitizer_locate.cpp
161+
OUTPUT_VARIABLE SANITIZER_COMPILER_OUTPUT
162+
LINK_OPTIONS ${LINK_OPTION}
163+
COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/sanitizer_locate
164+
)
165+
166+
if(NOT STATUS)
167+
message(FATAL_ERROR "Could not find location for lib${NAME}: ${SANITIZER_COMPILER_OUTPUT}")
168+
return()
169+
endif()
170+
171+
file(GET_RUNTIME_DEPENDENCIES
172+
EXECUTABLES ${CMAKE_CURRENT_BINARY_DIR}/sanitizer_locate
173+
RESOLVED_DEPENDENCIES_VAR SANITIZER_PROGRAM_LIBRARIES
174+
)
175+
176+
foreach(DEPENDENCY IN LISTS SANITIZER_PROGRAM_LIBRARIES)
177+
string(FIND "${DEPENDENCY}" "${NAME}" POSITION)
178+
if(POSITION GREATER -1)
179+
set(LIB${NAME_UPPER}_PATH "${DEPENDENCY}" PARENT_SCOPE)
180+
return()
181+
endif()
182+
endforeach()
183+
endfunction()
184+
185+
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
186+
if(OPTION_BUILD_THREAD_SANITIZER)
187+
find_sanitizer(tsan -fsanitize=thread)
188+
set(SANITIZER_LIBRARIES_PATH
189+
"${LIBTSAN_PATH}"
190+
)
191+
elseif(OPTION_BUILD_MEMORY_SANITIZER)
192+
set(SANITIZER_LIBRARIES_PATH) # TODO
193+
elseif(OPTION_BUILD_ADDRESS_SANITIZER)
194+
find_sanitizer(asan -fsanitize=address)
195+
find_sanitizer(ubsan -fsanitize=undefined)
196+
set(SANITIZER_LIBRARIES_PATH
197+
"${LIBASAN_PATH}"
198+
"${LIBUBSAN_PATH}"
199+
)
200+
endif()
201+
endif()
202+
203+
if(SANITIZER_LIBRARIES_PATH)
204+
if(PROJECT_OS_LINUX)
205+
list(JOIN SANITIZER_LIBRARIES_PATH " " SANITIZER_LIBRARIES_PATH_JOINED)
206+
set(TESTS_SANITIZER_PRELOAD_ENVIRONMENT_VARIABLES
207+
"LD_PRELOAD=${SANITIZER_LIBRARIES_PATH_JOINED}"
208+
)
209+
elseif(PROJECT_OS_FAMILY MATCHES "macos")
210+
list(JOIN SANITIZER_LIBRARIES_PATH ":" SANITIZER_LIBRARIES_PATH_JOINED)
211+
set(TESTS_SANITIZER_PRELOAD_ENVIRONMENT_VARIABLES
212+
"DYLD_INSERT_LIBRARIES=${SANITIZER_LIBRARIES_PATH_JOINED}"
213+
"DYLD_FORCE_FLAT_NAMESPACE=1"
214+
)
215+
endif()
216+
endif()
217+
152218
if((PROJECT_OS_WIN AND MSVC) OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
153219
# MSVC and Clang do not require to link manually the sanitizer libraries
154220
set(SANITIZER_LIBRARIES)

cmake/InstallRapidJSON.cmake

+8-10
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,17 @@ if(NOT RAPIDJSON_FOUND OR USE_BUNDLED_RAPIDJSON)
2828
endif()
2929

3030
ExternalProject_Add(rapid-json-depends
31-
GIT_REPOSITORY "https://github.com/Tencent/rapidjson.git"
32-
GIT_TAG "${RAPIDJSON_VERSION}"
33-
CMAKE_ARGS
34-
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
35-
-DRAPIDJSON_BUILD_DOC=Off
36-
-DRAPIDJSON_BUILD_EXAMPLES=Off
37-
-DRAPIDJSON_BUILD_TESTS=Off
38-
TEST_COMMAND ""
31+
GIT_REPOSITORY "https://github.com/Tencent/rapidjson.git"
32+
GIT_TAG "${RAPIDJSON_VERSION}"
33+
BUILD_COMMAND ""
34+
CONFIGURE_COMMAND ""
35+
INSTALL_COMMAND ""
36+
TEST_COMMAND ""
3937
)
4038

41-
ExternalProject_Get_Property(rapid-json-depends INSTALL_DIR)
39+
ExternalProject_Get_Property(rapid-json-depends SOURCE_DIR)
4240

43-
set(RAPIDJSON_ROOT_DIR ${INSTALL_DIR})
41+
set(RAPIDJSON_ROOT_DIR ${SOURCE_DIR})
4442
set(RAPIDJSON_INCLUDE_DIRS ${RAPIDJSON_ROOT_DIR}/include)
4543
set(RAPIDJSON_FOUND TRUE)
4644

source/adt/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ target_compile_options(${target}
164164
# Linker options
165165
#
166166

167-
target_link_libraries(${target}
167+
target_link_options(${target}
168168
PRIVATE
169169

170170
PUBLIC

source/benchmarks/log_bench/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ target_compile_options(${target}
108108
# Linker options
109109
#
110110

111-
target_link_libraries(${target}
111+
target_link_options(${target}
112112
PRIVATE
113113
${DEFAULT_LINKER_OPTIONS}
114114
)

source/benchmarks/metacall_cs_call_bench/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ target_compile_options(${target}
109109
# Linker options
110110
#
111111

112-
target_link_libraries(${target}
112+
target_link_options(${target}
113113
PRIVATE
114114
${DEFAULT_LINKER_OPTIONS}
115115
)

source/benchmarks/metacall_cs_call_bench/source/metacall_cs_call_bench.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,7 @@ int main(int argc, char **argv)
186186

187187
::benchmark::RunSpecifiedBenchmarks();
188188

189-
return metacall_destroy();
189+
metacall_destroy();
190+
191+
return 0;
190192
}

source/benchmarks/metacall_node_call_bench/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ target_compile_options(${target}
109109
# Linker options
110110
#
111111

112-
target_link_libraries(${target}
112+
target_link_options(${target}
113113
PRIVATE
114114
${DEFAULT_LINKER_OPTIONS}
115115
)

source/benchmarks/metacall_node_call_bench/source/metacall_node_call_bench.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -292,5 +292,7 @@ int main(int argc, char **argv)
292292
}
293293
#endif /* OPTION_BUILD_LOADERS_NODE */
294294

295-
return metacall_destroy();
295+
metacall_destroy();
296+
297+
return 0;
296298
}

source/benchmarks/metacall_py_c_api_bench/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ target_compile_options(${target}
121121
# Linker options
122122
#
123123

124-
target_link_libraries(${target}
124+
target_link_options(${target}
125125
PRIVATE
126126
${DEFAULT_LINKER_OPTIONS}
127127
)

source/benchmarks/metacall_py_call_bench/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ target_compile_options(${target}
109109
# Linker options
110110
#
111111

112-
target_link_libraries(${target}
112+
target_link_options(${target}
113113
PRIVATE
114114
${DEFAULT_LINKER_OPTIONS}
115115
)

source/benchmarks/metacall_py_call_bench/source/metacall_py_call_bench.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,7 @@ int main(int argc, char *argv[])
178178
::benchmark::RunSpecifiedBenchmarks();
179179
::benchmark::Shutdown();
180180

181-
if (metacall_destroy() != 0)
182-
{
183-
return 4;
184-
}
181+
metacall_destroy();
185182

186183
return 0;
187184
}

source/benchmarks/metacall_py_init_bench/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ target_compile_options(${target}
109109
# Linker options
110110
#
111111

112-
target_link_libraries(${target}
112+
target_link_options(${target}
113113
PRIVATE
114114
${DEFAULT_LINKER_OPTIONS}
115115
)

source/benchmarks/metacall_py_init_bench/source/metacall_py_init_bench.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,7 @@ BENCHMARK_DEFINE_F(metacall_py_init_bench, destroy)
130130
/* Python */
131131
#if defined(OPTION_BUILD_LOADERS_PY)
132132
{
133-
if (metacall_destroy() != 0)
134-
{
135-
state.SkipWithError("Error destroying MetaCall");
136-
}
133+
metacall_destroy();
137134
}
138135
#endif /* OPTION_BUILD_LOADERS_PY */
139136
}

source/benchmarks/metacall_rb_call_bench/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ target_compile_options(${target}
109109
# Linker options
110110
#
111111

112-
target_link_libraries(${target}
112+
target_link_options(${target}
113113
PRIVATE
114114
${DEFAULT_LINKER_OPTIONS}
115115
)

source/benchmarks/metacall_rb_call_bench/source/metacall_rb_call_bench.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,7 @@ int main(int argc, char *argv[])
198198
::benchmark::RunSpecifiedBenchmarks();
199199
::benchmark::Shutdown();
200200

201-
if (metacall_destroy() != 0)
202-
{
203-
return 4;
204-
}
201+
metacall_destroy();
205202

206203
return 0;
207204
}

source/cli/metacallcli/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ target_compile_features(${target}
139139
# Linker options
140140
#
141141

142-
target_link_libraries(${target}
142+
target_link_options(${target}
143143
PRIVATE
144144
${DEFAULT_LINKER_OPTIONS}
145145
)

source/cli/metacallcli/source/application.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,7 @@ application::application(int argc, char *argv[]) :
299299

300300
application::~application()
301301
{
302-
int result = metacall_destroy();
303-
304-
if (result != 0)
305-
{
306-
std::cout << "Error while destroying MetaCall, exit code: " << result << std::endl;
307-
}
302+
metacall_destroy();
308303
}
309304

310305
void application::arguments_parse(std::vector<std::string> &arguments)

source/cli/plugins/cli_core_plugin/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ target_compile_options(${target}
180180
# Linker options
181181
#
182182

183-
target_link_libraries(${target}
183+
target_link_options(${target}
184184
PRIVATE
185185

186186
PUBLIC

source/cli/plugins/cli_core_plugin/include/cli_core_plugin/cli_core_plugin.h

-4
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,12 @@
2323

2424
#include <cli_core_plugin/cli_core_plugin_api.h>
2525

26-
#include <dynlink/dynlink.h>
27-
2826
#ifdef __cplusplus
2927
extern "C" {
3028
#endif
3129

3230
CLI_CORE_PLUGIN_API int cli_core_plugin(void *loader, void *handle);
3331

34-
DYNLINK_SYMBOL_EXPORT(cli_core_plugin);
35-
3632
#ifdef __cplusplus
3733
}
3834
#endif

0 commit comments

Comments
 (0)