diff --git a/.release-notes/4303.md b/.release-notes/4303.md new file mode 100644 index 0000000000..33f88cc17e --- /dev/null +++ b/.release-notes/4303.md @@ -0,0 +1,14 @@ +## Enable building of libponyc-standalone on MacOS + +We now ship a "standalone" version of libponyc for MacOS. libponyc-standalone allows applications to use Pony compiler functionality as a library. The standalone version contains "all dependencies" needed in a single library. On MacOS, sadly "all dependencies" means "all that can be statically linked", so unlike Linux, dynamically linking to C++ standard library is required on MacOS. + +An example pony program linking against it would need to look like this: + +```pony +use "lib:ponyc-standalone" if posix or osx +use "lib:c++" if osx + +actor Main + new create(env: Env) => + None +``` diff --git a/src/libponyc/CMakeLists.txt b/src/libponyc/CMakeLists.txt index 4acc0537fb..fa39833600 100644 --- a/src/libponyc/CMakeLists.txt +++ b/src/libponyc/CMakeLists.txt @@ -121,9 +121,22 @@ endif (NOT MSVC) # build a standalone version of libponyc.a with all needed dependencies linked statically if (MSVC) # TODO - #file(GLOB_RECURSE LLVM_OBJS "${PROJECT_SOURCE_DIR}/../../build/build_libs/llvm/src/llvm/Release/lib/*.lib") elseif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin") - # TODO + # on macos we dont have no static libc++ + # so when we want to use this lib + # we need to additionally link libc++ and libz (for llvm) + file(GLOB_RECURSE LLVM_OBJS "${PROJECT_SOURCE_DIR}/../../build/build_libs/llvm/src/llvm//lib/libLLVM*.a") + add_custom_target(libponyc-standalone ALL + COMMAND libtool -static -o libponyc-standalone.a $ ${PROJECT_SOURCE_DIR}/../../build/libs/lib/libblake2.a ${LLVM_OBJS} + DEPENDS $ ${STANDALONE_ARCHIVES} + ) + # copy the generated file after it is built + add_custom_command(TARGET libponyc-standalone POST_BUILD + COMMAND $<$:${CMAKE_COMMAND}> ARGS -E copy libponyc-standalone.a ${CMAKE_BINARY_DIR}/../debug/ + COMMAND $<$:${CMAKE_COMMAND}> ARGS -E copy libponyc-standalone.a ${CMAKE_BINARY_DIR}/../release/ + COMMAND $<$:${CMAKE_COMMAND}> ARGS -E copy libponyc-standalone.a ${CMAKE_BINARY_DIR}/../relwithdebinfo/ + COMMAND $<$:${CMAKE_COMMAND}> ARGS -E copy libponyc-standalone.a ${CMAKE_BINARY_DIR}/../minsizerel/ + ) elseif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "BSD") # TODO elseif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "DragonFly")