From 4af97e7fd8e00a52f84c6b03dde4ba3702c291e3 Mon Sep 17 00:00:00 2001 From: initial Date: Fri, 19 May 2023 11:18:37 +0100 Subject: [PATCH 1/3] [UR] Allow compilation on apple --- examples/hello_world/CMakeLists.txt | 5 +---- source/common/linux/ur_lib_loader.cpp | 2 +- source/common/umf_pools/disjoint_pool.hpp | 1 + test/unified_malloc_framework/common/pool.hpp | 6 ++++++ 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/hello_world/CMakeLists.txt b/examples/hello_world/CMakeLists.txt index b1723ae605..bde1fd9cf5 100644 --- a/examples/hello_world/CMakeLists.txt +++ b/examples/hello_world/CMakeLists.txt @@ -9,10 +9,6 @@ add_executable(${TARGET_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/hello_world.cpp ) -target_include_directories(${TARGET_NAME} PRIVATE - ${CMAKE_SOURCE_DIR}/include -) - if(MSVC) set_target_properties(${TARGET_NAME} PROPERTIES @@ -24,4 +20,5 @@ endif() target_link_libraries(${TARGET_NAME} PRIVATE ${PROJECT_NAME}::loader ${CMAKE_DL_LIBS} + ${PROJECT_NAME}::headers ) diff --git a/source/common/linux/ur_lib_loader.cpp b/source/common/linux/ur_lib_loader.cpp index 445de6f2eb..1c5e0af89b 100644 --- a/source/common/linux/ur_lib_loader.cpp +++ b/source/common/linux/ur_lib_loader.cpp @@ -12,7 +12,7 @@ #include "logger/ur_logger.hpp" #include "ur_lib_loader.hpp" -#if defined(SANITIZER_ANY) +#if defined(SANITIZER_ANY) || defined(__APPLE__) #define LOAD_DRIVER_LIBRARY(NAME) dlopen(NAME, RTLD_LAZY | RTLD_LOCAL) #else #define LOAD_DRIVER_LIBRARY(NAME) \ diff --git a/source/common/umf_pools/disjoint_pool.hpp b/source/common/umf_pools/disjoint_pool.hpp index 85dd86872d..48d0ecf51b 100644 --- a/source/common/umf_pools/disjoint_pool.hpp +++ b/source/common/umf_pools/disjoint_pool.hpp @@ -11,6 +11,7 @@ #include #include +#include #include "../umf_helpers.hpp" diff --git a/test/unified_malloc_framework/common/pool.hpp b/test/unified_malloc_framework/common/pool.hpp index 7ec62b8741..5be080ef33 100644 --- a/test/unified_malloc_framework/common/pool.hpp +++ b/test/unified_malloc_framework/common/pool.hpp @@ -11,7 +11,11 @@ #ifndef UMF_TEST_POOL_HPP #define UMF_TEST_POOL_HPP 1 +#if defined(__APPLE__) +#include +#else #include +#endif #include #include @@ -61,6 +65,8 @@ struct malloc_pool : public pool_base { size_t malloc_usable_size(void *ptr) noexcept { #ifdef _WIN32 return _msize(ptr); +#elif __APPLE__ + return ::malloc_size(ptr); #else return ::malloc_usable_size(ptr); #endif From 70459f4c04ac0d0e2d352590a953aef92fdd02e7 Mon Sep 17 00:00:00 2001 From: Petr Vesely Date: Fri, 7 Jul 2023 14:39:49 +0100 Subject: [PATCH 2/3] [UR] Add simple macos action --- .github/workflows/cmake.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index fdfaf6cc1f..d3fd0e3e5e 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -125,3 +125,33 @@ jobs: - name: Test working-directory: ${{github.workspace}}/build run: ctest -C ${{matrix.build_type}} --output-on-failure -L "python|umf|loader|validation|tracing|unit|urtrace" + + + macos-build: + name: Build - MacOS + strategy: + matrix: + os: ['macos-12', 'macos-13'] + runs-on: ${{matrix.os}} + + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-python@v4 + with: + python-version: 3.9 + + - name: Install prerequisites + run: python3 -m pip install -r third_party/requirements.txt + + - name: Configure CMake + run: > + cmake + -B${{github.workspace}}/build + -DUR_ENABLE_TRACING=ON + -DUR_DEVELOPER_MODE=ON + -DCMAKE_BUILD_TYPE=Release + -DUR_BUILD_TESTS=ON + -DUR_FORMAT_CPP_STYLE=ON + - name: Build + run: cmake --build ${{github.workspace}}/build -j $(nproc) From 8653be6311919cbc620b94e3390de577b55d4230 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Thu, 16 Mar 2023 16:34:43 +0000 Subject: [PATCH 3/3] [ur] macOS fix dylib version & enable color diagnostics Update the `MAKE_LIBRARY_NAME` macro to match the library naming scheme CMake uses when `VERSION` is specified on macOS, taking the form `lib..dylib`. Enable color diagnostics for AppleClang. And disable the `CMAKE_FIND_FRAMEWORK` option so that in-tree dylibs are correctly loaded. --- CMakeLists.txt | 6 +++++- source/common/ur_util.hpp | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e7b03bb00f..f19ea5618b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,10 @@ include(CTest) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(helpers) +if(CMAKE_SYSTEM_NAME STREQUAL Darwin) + set(CMAKE_FIND_FRAMEWORK NEVER) +endif() + find_package(Python3 COMPONENTS Interpreter) set(CMAKE_CXX_STANDARD 17) @@ -52,7 +56,7 @@ endif() if(NOT MSVC) add_compile_options(-fPIC -Wall -Wpedantic $<$:-fdiagnostics-color=always> - $<$:-fcolor-diagnostics>) + $<$:-fcolor-diagnostics>) if(UR_DEVELOPER_MODE) add_compile_options(-Werror -fno-omit-frame-pointer) endif() diff --git a/source/common/ur_util.hpp b/source/common/ur_util.hpp index 5bf556dda6..e77d439275 100644 --- a/source/common/ur_util.hpp +++ b/source/common/ur_util.hpp @@ -57,8 +57,12 @@ inline int ur_getpid(void) { return static_cast(getpid()); } #define MAKE_LIBRARY_NAME(NAME, VERSION) NAME ".dll" #else #define HMODULE void * +#if defined(__APPLE__) +#define MAKE_LIBRARY_NAME(NAME, VERSION) "lib" NAME "." VERSION ".dylib" +#else #define MAKE_LIBRARY_NAME(NAME, VERSION) "lib" NAME ".so." VERSION #endif +#endif inline std::string create_library_path(const char *name, const char *path) { std::string library_path;