Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create libponyc-standalone on MacOS #4303

Merged
merged 6 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .release-notes/4303.md
Original file line number Diff line number Diff line change
@@ -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
```
17 changes: 15 additions & 2 deletions src/libponyc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember why, but the GLOB_RECURSE had problems on Linux once I started using.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is finding all the libs and the resulting static library has all we need. And this is scoped to Darwin only, so, unless this becomes a problem on M1 mac, i think this is fine, but thanks for the heads-up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How was this tested on MacOS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was tested by taking a pony program and linking it to the resulting libponyc-standalone.a.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what program? does the program fully exercise the API or could there be errors that get hidden by dead code elimination?

add_custom_target(libponyc-standalone ALL
COMMAND libtool -static -o libponyc-standalone.a $<TARGET_FILE:libponyc> ${PROJECT_SOURCE_DIR}/../../build/libs/lib/libblake2.a ${LLVM_OBJS}
DEPENDS $<TARGET_FILE:libponyc> ${STANDALONE_ARCHIVES}
)
# copy the generated file after it is built
add_custom_command(TARGET libponyc-standalone POST_BUILD
COMMAND $<$<CONFIG:Debug>:${CMAKE_COMMAND}> ARGS -E copy libponyc-standalone.a ${CMAKE_BINARY_DIR}/../debug/
COMMAND $<$<CONFIG:Release>:${CMAKE_COMMAND}> ARGS -E copy libponyc-standalone.a ${CMAKE_BINARY_DIR}/../release/
COMMAND $<$<CONFIG:RelWithDebInfo>:${CMAKE_COMMAND}> ARGS -E copy libponyc-standalone.a ${CMAKE_BINARY_DIR}/../relwithdebinfo/
COMMAND $<$<CONFIG:MinSizeRel>:${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")
Expand Down