From 5d5c6c0d1898912df6ed16e08eef5c667c46f151 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 11 Mar 2026 19:18:15 -0500 Subject: [PATCH] Attempt to fix finding libedit on macOS (#609) First pass at trying to fix this... --- cmake/wasi-sdk-toolchain.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmake/wasi-sdk-toolchain.cmake b/cmake/wasi-sdk-toolchain.cmake index 21cdb39..56920f7 100644 --- a/cmake/wasi-sdk-toolchain.cmake +++ b/cmake/wasi-sdk-toolchain.cmake @@ -113,6 +113,9 @@ if(WASI_SDK_LLDB) include(ProcessorCount) ProcessorCount(nproc) find_program(MAKE_EXECUTABLE make REQUIRED) + if(CMAKE_SYSTEM_NAME STREQUAL Darwin) + set(libedit_ldflags -Wl,-install_name,@rpath/libedit.0.dylib) + endif() ExternalProject_Add(libedit URL https://thrysoee.dk/editline/libedit-20251016-3.1.tar.gz URL_HASH SHA256=21362b00653bbfc1c71f71a7578da66b5b5203559d43134d2dd7719e313ce041 @@ -127,8 +130,7 @@ if(WASI_SDK_LLDB) --enable-pic --disable-examples CC=${CMAKE_C_COMPILER} - CFLAGS=${libedit_cflags} - LDFLAGS=${libedit_cflags} + LDFLAGS=${libedit_ldflags} BUILD_COMMAND ${MAKE_EXECUTABLE} -j${nproc} V=1 @@ -169,6 +171,9 @@ ExternalProject_Add(llvm-build # Pass `-s` to strip symbols by default and shrink the size of the # distribution -DCMAKE_EXE_LINKER_FLAGS=-s + # Looks to be required on macOS for, at build time, the dynamic linker to + # find `libedit.dylib` when that's enabled. + -DCMAKE_BUILD_RPATH=${wasi_tmp_install}/lib ${llvm_cmake_flags_list} # See https://www.scivision.dev/cmake-externalproject-list-arguments/ for # why this is in `CMAKE_CACHE_ARGS` instead of above