From 144dea123dededa31e03ab5fcce4b5f6b2a76c0f Mon Sep 17 00:00:00 2001 From: Matthias Wahl Date: Sat, 14 Jan 2023 16:42:05 +0100 Subject: [PATCH 1/6] Create libponyc-standalone on macos. It will not link libstdc++ statically, as this is not available on osx. When linking against libponyc-standalone one also needs to link against libc++ and libz, but at least we have all the llvm symbols in there. --- src/libponyc/CMakeLists.txt | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/libponyc/CMakeLists.txt b/src/libponyc/CMakeLists.txt index 4acc0537fb..e7e5cbfed2 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") @@ -139,7 +152,7 @@ else() COMMAND echo "addlib $" >> standalone.mri COMMAND echo "save" >> standalone.mri COMMAND echo "end" >> standalone.mri - COMMAND ar -M < standalone.mri + COMMAND ${CMAKE_AR} -M < standalone.mri DEPENDS $ ${STANDALONE_ARCHIVES} ) # add a separate target that depends on the standalone library file From 5530f6d70935a47c7611ba812792191bc92f0ded Mon Sep 17 00:00:00 2001 From: Matthias Wahl Date: Sat, 14 Jan 2023 22:21:46 +0100 Subject: [PATCH 2/6] Go back to using plain ar on linux --- src/libponyc/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libponyc/CMakeLists.txt b/src/libponyc/CMakeLists.txt index e7e5cbfed2..fa39833600 100644 --- a/src/libponyc/CMakeLists.txt +++ b/src/libponyc/CMakeLists.txt @@ -152,7 +152,7 @@ else() COMMAND echo "addlib $" >> standalone.mri COMMAND echo "save" >> standalone.mri COMMAND echo "end" >> standalone.mri - COMMAND ${CMAKE_AR} -M < standalone.mri + COMMAND ar -M < standalone.mri DEPENDS $ ${STANDALONE_ARCHIVES} ) # add a separate target that depends on the standalone library file From b7498e3a43cf0b17798ebab08fd239dacb32cf3c Mon Sep 17 00:00:00 2001 From: Matthias Wahl Date: Sat, 14 Jan 2023 22:28:13 +0100 Subject: [PATCH 3/6] Add release notes --- .release-notes/4303.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .release-notes/4303.md diff --git a/.release-notes/4303.md b/.release-notes/4303.md new file mode 100644 index 0000000000..ba8d140053 --- /dev/null +++ b/.release-notes/4303.md @@ -0,0 +1,6 @@ +## Enable building of libponyc-standalone on macos + +With this change we now produce the static library `libponyc-standalone.a` also on macos. +As on osx it is hard to statically link `libc++`, it needs to be linked dynamically +when building a final binary with this library. + From 27ce31c6c62a4be3303f0d00a3b0e509b9c7aba0 Mon Sep 17 00:00:00 2001 From: Matthias Wahl Date: Sun, 15 Jan 2023 20:23:55 +0100 Subject: [PATCH 4/6] Update .release-notes/4303.md Co-authored-by: Sean T Allen --- .release-notes/4303.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.release-notes/4303.md b/.release-notes/4303.md index ba8d140053..eb4d019414 100644 --- a/.release-notes/4303.md +++ b/.release-notes/4303.md @@ -1,4 +1,4 @@ -## Enable building of libponyc-standalone on macos +## Enable building of libponyc-standalone on MacOS With this change we now produce the static library `libponyc-standalone.a` also on macos. As on osx it is hard to statically link `libc++`, it needs to be linked dynamically From 3798bf6d0700e8e8fb368d33c0bb126c00c64cef Mon Sep 17 00:00:00 2001 From: Matthias Wahl Date: Sun, 15 Jan 2023 20:24:27 +0100 Subject: [PATCH 5/6] Update .release-notes/4303.md Co-authored-by: Sean T Allen --- .release-notes/4303.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.release-notes/4303.md b/.release-notes/4303.md index eb4d019414..bec96e9fe4 100644 --- a/.release-notes/4303.md +++ b/.release-notes/4303.md @@ -1,6 +1,4 @@ ## Enable building of libponyc-standalone on MacOS -With this change we now produce the static library `libponyc-standalone.a` also on macos. -As on osx it is hard to statically link `libc++`, it needs to be linked dynamically -when building a final binary with this library. +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. From 4ac6caab2746b77acaad0c6adf65836468ca934f Mon Sep 17 00:00:00 2001 From: Matthias Wahl Date: Mon, 16 Jan 2023 08:25:30 +0100 Subject: [PATCH 6/6] Add pony program example to release notes --- .release-notes/4303.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.release-notes/4303.md b/.release-notes/4303.md index bec96e9fe4..33f88cc17e 100644 --- a/.release-notes/4303.md +++ b/.release-notes/4303.md @@ -2,3 +2,13 @@ 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 +```