Skip to content

Commit 84dcd6c

Browse files
committed
Update CMakeLists.txt without rpath
1 parent 7527a60 commit 84dcd6c

File tree

4 files changed

+54
-34
lines changed

4 files changed

+54
-34
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ jobs:
149149
run: |
150150
mkdir -p /tmp/ArkScript
151151
cmake --install build --prefix /tmp/ArkScript
152+
# to ensure that the executable won't try to load libArkReactor.so/dylib from build/
153+
rm -rf build
152154
153155
- name: Test installation
154156
run: |
@@ -213,13 +215,13 @@ jobs:
213215
mkdir -p artifact/lib/std
214216
# Linux/MacOS
215217
if [[ '${{ startsWith(matrix.config.os, 'ubuntu') }}' == 'true' ]] || [[ '${{ startsWith(matrix.config.os, 'macos') }}' == 'true' ]]; then
216-
cp build/arkscript artifact || true
217-
cp build/libArkReactor.* artifact || true
218+
cp build/arkscript artifact
219+
cp build/bin/libArkReactor.* artifact
218220
fi
219221
# Windows
220222
if [[ '${{ startsWith(matrix.config.os, 'windows') }}' == 'true' ]]; then
221-
cp build/$BUILD_TYPE/arkscript.exe artifact || true
222-
cp build/$BUILD_TYPE/ArkReactor.dll artifact || true
223+
cp build/$BUILD_TYPE/arkscript.exe artifact
224+
cp build/$BUILD_TYPE/ArkReactor.dll artifact
223225
fi
224226
# Generic
225227
cp lib/*.arkm artifact/lib
@@ -230,8 +232,11 @@ jobs:
230232
shell: bash
231233
run: |
232234
mkdir -p temp/tests/unittests/
233-
cp build/unittests temp/ || true
234-
cp build/$BUILD_TYPE/unittests.exe temp/ || true
235+
if [[ '${{ startsWith(matrix.config.os, 'windows') }}' == 'true' ]]; then
236+
cp build/$BUILD_TYPE/unittests.exe temp/
237+
else
238+
cp build/unittests temp/
239+
fi
235240
cp tests/unittests/*.arkm temp/tests/unittests
236241
cp -r tests/unittests temp/tests/unittests
237242
@@ -275,6 +280,7 @@ jobs:
275280
- name: Run tests
276281
run: |
277282
export ASAN_OPTIONS=detect_odr_violation=0
283+
cp ./build/bin/libArkReactor.so ./build
278284
./build/unittests
279285
280286
- name: Gather coverage
@@ -372,9 +378,13 @@ jobs:
372378
-DARK_SANITIZERS=On \
373379
-DARK_UNITY_BUILD=On
374380
cmake --build ${BUILD_FOLDER} --config Release -j 4
381+
cp ${BUILD_FOLDER}/bin/libArkReactor.so ${BUILD_FOLDER}
375382
376383
- name: Fuzz
377384
run: |
385+
# ensure the executable works first
386+
ARKSCRIPT_PATH=$(pwd)/lib ${BUILD_FOLDER}/arkscript -e '(import std.List) (print list:map " is a function")' || exit 1
387+
# then we can fuzz. If the executable doesn't work, the fuzzer crashes with a cryptic error message
378388
afl-fuzz -i tests/fuzzing/corpus-cmin-tmin \
379389
-o output \
380390
-s $FUZZER_SEED \

.github/workflows/setup-tests/action.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ runs:
4747
cp artifact/unittests .
4848
chmod u+x unittests
4949
50+
- shell: bash
51+
if: ${{ !startsWith(inputs.os_name, 'windows') }}
52+
run: cp build/libArkReactor.* .
53+
5054
- shell: bash
5155
if: startsWith(matrix.config.name, 'Windows')
5256
run: |

CMakeLists.txt

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ option(ARK_COVERAGE "Enable coverage while building (clang, gcc) (requires ARK_T
3535
option(ARK_UNITY_BUILD "Enable unity build" Off)
3636
option(ARK_JS_ONLY "Compiles to native JS (No WASM). Can be used only when compiling with emsdk" OFF)
3737

38-
if (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
39-
set(ARK_EMSCRIPTEN TRUE)
40-
endif ()
38+
include(cmake/vars.cmake)
4139

4240
if (NOT ARK_EMSCRIPTEN)
4341
include(cmake/link_time_optimization.cmake)
@@ -67,21 +65,18 @@ configure_file(
6765

6866
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
6967

70-
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
71-
set(CMAKE_COMPILER_IS_CLANG ON)
72-
endif ()
73-
7468
file(GLOB_RECURSE SOURCE_FILES
7569
${ark_SOURCE_DIR}/src/arkreactor/*.cpp
7670
${ark_SOURCE_DIR}/thirdparties/fmt/src/format.cc)
7771

78-
add_library(ArkReactor SHARED ${SOURCE_FILES})
79-
8072
if (NOT ARK_EMSCRIPTEN)
73+
add_library(ArkReactor SHARED ${SOURCE_FILES})
8174
enable_lto(ArkReactor)
8275
set_target_properties(ArkReactor PROPERTIES
83-
INSTALL_NAME_DIR "@rpath"
84-
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_INSTALL_BINDIR})
76+
INSTALL_NAME_DIR "@rpath"
77+
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_INSTALL_BINDIR})
78+
else ()
79+
add_library(ArkReactor STATIC ${SOURCE_FILES})
8580
endif ()
8681

8782
target_include_directories(ArkReactor
@@ -93,6 +88,7 @@ target_include_directories(ArkReactor
9388
"${ark_SOURCE_DIR}/thirdparties/fmt/include")
9489

9590
target_compile_features(ArkReactor PRIVATE cxx_std_20)
91+
target_compile_definitions(ArkReactor PRIVATE ARK_EXPORT)
9692

9793
if (ARK_ENABLE_SYSTEM)
9894
target_compile_definitions(ArkReactor PRIVATE ARK_ENABLE_SYSTEM)
@@ -148,7 +144,6 @@ if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANG OR APPLE)
148144
elseif (CMAKE_COMPILER_IS_GNUCXX)
149145
target_compile_options(ArkReactor PRIVATE -Wno-unused-local-typedefs)
150146
endif ()
151-
152147
elseif (MSVC)
153148
target_compile_definitions(ArkReactor PRIVATE ARK_USE_COMPUTED_GOTOS=0)
154149
target_compile_options(ArkReactor
@@ -184,7 +179,7 @@ endif ()
184179
if (NOT ARK_EMSCRIPTEN)
185180
# Installs the dynamic library file.
186181
install(TARGETS ArkReactor
187-
LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR})
182+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
188183

189184
# Install header files
190185
install(DIRECTORY ${ark_SOURCE_DIR}/include/
@@ -207,8 +202,6 @@ if (NOT ARK_EMSCRIPTEN)
207202
endif ()
208203
endif ()
209204

210-
target_compile_definitions(ArkReactor PRIVATE ARK_EXPORT)
211-
212205
#####################################################
213206
# Create the different (optional) targets
214207
#####################################################
@@ -260,14 +253,13 @@ if (ARK_TESTS)
260253
${ark_SOURCE_DIR}/src/arkscript/REPL/Utils.cpp)
261254
add_executable(unittests ${SOURCES})
262255
target_include_directories(unittests PUBLIC ${ark_SOURCE_DIR}/tests/unittests)
263-
256+
target_include_directories(unittests PUBLIC ${ark_SOURCE_DIR}/include)
264257
target_include_directories(unittests SYSTEM PUBLIC ${ark_SOURCE_DIR}/thirdparties/dtl/dtl)
265258

259+
set(BOOST_UT_DISABLE_MODULE On)
266260
add_subdirectory(${ark_SOURCE_DIR}/thirdparties/ut)
267-
target_include_directories(unittests PUBLIC ${ark_SOURCE_DIR}/include)
268261
target_link_libraries(unittests PUBLIC ArkReactor ut replxx)
269262

270-
set(BOOST_UT_DISABLE_MODULE On)
271263
target_compile_features(unittests PRIVATE cxx_std_20)
272264
target_compile_definitions(unittests PRIVATE ARK_TESTS_ROOT="${CMAKE_CURRENT_SOURCE_DIR}/")
273265

@@ -278,8 +270,8 @@ if (ARK_TESTS)
278270
VS_DEBUGGER_WORKING_DIRECTORY "${ark_SOURCE_DIR}"
279271
VS_DEBUGGER_COMMAND "$<TARGET_FILE:unittests>"
280272
BUILD_WITH_INSTALL_RPATH ON
281-
INSTALL_RPATH_USE_LINK_PATH ON
282-
INSTALL_RPATH "@executable_path")
273+
INSTALL_RPATH_USE_LINK_PATH ON)
274+
set_target_rpath(unittests)
283275

284276
if (ARK_COVERAGE AND CMAKE_COMPILER_IS_CLANG)
285277
target_compile_options(unittests PRIVATE -coverage -fcoverage-mapping -fprofile-instr-generate)
@@ -348,20 +340,17 @@ if (ARK_BUILD_EXE)
348340
target_compile_features(arkscript PRIVATE cxx_std_20)
349341

350342
if (ARK_UNITY_BUILD)
351-
set_target_properties(arkscript PROPERTIES UNITY_BUILD ON UNITY_BUILD_MODE BATCH UNITY_BUILD_BATCH_SIZE 16)
343+
set_target_properties(arkscript PROPERTIES
344+
UNITY_BUILD ON
345+
UNITY_BUILD_MODE BATCH
346+
UNITY_BUILD_BATCH_SIZE 16)
352347
endif ()
353348
set_target_properties(arkscript PROPERTIES
354349
VS_DEBUGGER_WORKING_DIRECTORY "${ark_SOURCE_DIR}"
355350
VS_DEBUGGER_COMMAND "$<TARGET_FILE:arkscript>"
356351
BUILD_WITH_INSTALL_RPATH ON
357352
INSTALL_RPATH_USE_LINK_PATH ON)
358-
if (APPLE)
359-
set_target_properties(arkscript PROPERTIES
360-
INSTALL_RPATH "@executable_path;@executable_path/../bin")
361-
elseif (UNIX)
362-
set_target_properties(arkscript PROPERTIES
363-
INSTALL_RPATH "\$ORIGIN:\$ORIGIN/../bin")
364-
endif ()
353+
set_target_rpath(arkscript)
365354

366355
enable_lto(arkscript)
367356

cmake/vars.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
2+
set(CMAKE_COMPILER_IS_CLANG ON)
3+
endif ()
4+
5+
if (${CMAKE_SYSTEM_NAME} MATCHES "Emscripten")
6+
set(ARK_EMSCRIPTEN TRUE)
7+
endif ()
8+
9+
function(set_target_rpath target)
10+
if (APPLE)
11+
set_target_properties(${target} PROPERTIES
12+
INSTALL_RPATH "@executable_path;@executable_path/../lib")
13+
elseif (UNIX)
14+
set_target_properties(${target} PROPERTIES
15+
INSTALL_RPATH "\$ORIGIN:\$ORIGIN/../lib")
16+
endif ()
17+
endfunction()

0 commit comments

Comments
 (0)