Skip to content

Commit

Permalink
fix: make lean4 build on FreeBSD
Browse files Browse the repository at this point in the history
  • Loading branch information
yurivict committed Jan 14, 2024
1 parent 42e6214 commit 6e4cfe4
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
string(APPEND LEANC_EXTRA_FLAGS " -fPIC")
string(APPEND LEANSHARED_LINKER_FLAGS " -Wl,-rpath=\\$$ORIGIN/..:\\$$ORIGIN")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -lleanshared -Wl,-rpath=\\\$ORIGIN/../lib:\\\$ORIGIN/../lib/lean")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
string(APPEND CMAKE_CXX_FLAGS " -fPIC -ftls-model=initial-exec")
string(APPEND LEANC_EXTRA_FLAGS " -fPIC")
string(APPEND LEANSHARED_LINKER_FLAGS " -Wl,-rpath=\\$$ORIGIN/..:\\$$ORIGIN")
string(APPEND CMAKE_EXE_LINKER_FLAGS " -lleanshared -Wl,-rpath=\\\$ORIGIN/../lib:\\\$ORIGIN/../lib/lean")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
string(APPEND CMAKE_CXX_FLAGS " -ftls-model=initial-exec")
string(APPEND LEANSHARED_LINKER_FLAGS " -install_name @rpath/libleanshared.dylib")
Expand Down
8 changes: 7 additions & 1 deletion src/runtime/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,13 @@ extern "C" LEAN_EXPORT obj_res lean_io_app_path(obj_arg) {
char dest[PATH_MAX];
memset(dest, 0, PATH_MAX);
pid_t pid = getpid();
snprintf(path, PATH_MAX, "/proc/%d/exe", pid);
#if defined(__linux__)
snprintf(path, PATH_MAX, "/proc/%d/exe", pid);
#elif defined(__FreeBSD__)
snprintf(path, PATH_MAX, "/proc/%d/file", pid);
#else
# error "Unknown platform"
#endif
if (readlink(path, dest, PATH_MAX) == -1) {
return io_result_mk_error("failed to locate application");
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/runtime/stack_overflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Port of the corresponding Rust code (see links below).
#include <lean/lean.h>
#include "runtime/stack_overflow.h"

#if defined(__FreeBSD__)
# include <pthread_np.h>
# define pthread_getattr_np pthread_attr_get_np
#endif

namespace lean {
// stack guard of the main thread
static stack_guard * g_stack_guard;
Expand Down
5 changes: 5 additions & 0 deletions stage0/src/CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions stage0/src/runtime/io.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions stage0/src/runtime/stack_overflow.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6e4cfe4

Please sign in to comment.