Skip to content

Commit

Permalink
RPATH shenanigans (#1637)
Browse files Browse the repository at this point in the history
* Err, libcurl's rpath made no sense (it lives in libs/ already...)
* And libzstd's rpath made no sense either.
It's a library, not a binary in the root folder.
Also, it doesn't actually have meaningful deps, so we don't actually need an rpath anyway...
* Set webp's rpath to $ORIGIN, so it picks up our own dependencies
  • Loading branch information
NiLuJe committed Jul 13, 2023
1 parent c0591a3 commit fcf5c57
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions Makefile.third
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,11 @@ $(GIF_LIB): $(THIRDPARTY_DIR)/giflib/*.*
$(LIBWEBP_LIB) $(LIBWEBP_DIR): $(THIRDPARTY_DIR)/libwebp/*.*
install -d $(LIBWEBP_BUILD_DIR)
cd $(LIBWEBP_BUILD_DIR) && \
$(CMAKE) $(CMAKE_FLAGS) -DCC="$(CC)" -DCXX="$(CXX)" -DCFLAGS="$(CFLAGS)" \
-DCXXFLAGS="$(CXXFLAGS)" -DLDFLAGS="$(LDFLAGS)" -DCHOST=$(CHOST) \
$(CMAKE) $(CMAKE_FLAGS) -DCC="$(CC)" -DCXX="$(CXX)" -DCHOST="$(CHOST)" \
-DCPPFLAGS="$(CPPFLAGS)" \
-DCFLAGS="$(CFLAGS)" \
-DCXXFLAGS="$(CXXFLAGS)" \
-DLDFLAGS="$(LDFLAGS) -Wl,-rpath,'$(ORIGIN_CMAKE_TO_AUTOCFG)'" \
$(CURDIR)/$(THIRDPARTY_DIR)/libwebp && \
$(CMAKE_MAKE_PROGRAM) $(CMAKE_MAKE_PROGRAM_FLAGS)
cp -fL $(LIBWEBP_DIR)/lib/$(notdir $(LIBWEBP_LIB)) $@
Expand Down Expand Up @@ -808,7 +810,7 @@ $(CURL_LIB): $(THIRDPARTY_DIR)/curl/*.*
-DCC="$(CC)" \
-DCPPFLAGS="$(CPPFLAGS) -I$(ZLIB_DIR)/include -I$(OPENSSL_DIR)/include" \
-DCFLAGS="$(CFLAGS)" \
-DLDFLAGS="$(LDFLAGS) -L$(ZLIB_DIR) -L$(OPENSSL_DIR) -Wl,-rpath,'$(ORIGIN_CMAKE_TO_AUTOCFG)/../libs' -lssl -lcrypto -lz -lrt" \
-DLDFLAGS="$(LDFLAGS) -L$(ZLIB_DIR) -L$(OPENSSL_DIR) -Wl,-rpath,'$(ORIGIN_CMAKE_TO_AUTOCFG)' -lssl -lcrypto -lz -lrt" \
$(CURDIR)/thirdparty/curl && \
$(CMAKE_MAKE_PROGRAM) $(CMAKE_MAKE_PROGRAM_FLAGS)
cp -fL $(CURL_DIR)/lib/$(notdir $(CURL_LIB)) $(OUTPUT_DIR)/libs
Expand Down
2 changes: 1 addition & 1 deletion thirdparty/zstd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ep_get_source_dir(SOURCE_DIR)
ep_get_binary_dir(BINARY_DIR)

# Because escaping rpath is even more hellish than usual, for some reason...
# NOTE: In ZSH, passing MOREFLAGS="-Wl,-rpath,'\\\$$\\\$\$ORIGIN/./libs'" works, too.
# NOTE: In ZSH, passing MOREFLAGS="-Wl,-rpath,'\\\$$\\\$\$ORIGIN'" works, too.
set(PATCH_CMD "${KO_PATCH} ${CMAKE_CURRENT_SOURCE_DIR}/zstd-rpath.patch")

# This a pure Makefile buildsystem, don't enforce CFLAGS via command line args, the buildsystem needs to be able to modify it.
Expand Down
6 changes: 3 additions & 3 deletions thirdparty/zstd/zstd-rpath.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
diff --git a/lib/Makefile b/lib/Makefile
index ef202183..a7035f2c 100644
index a4cf61ab..bd16e3c2 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -139,7 +139,7 @@ LIBZSTD = libzstd.$(SHARED_EXT_VER)
.PHONY: $(LIBZSTD) # must be run every time
$(LIBZSTD): CPPFLAGS += $(CPPFLAGS_DYNLIB)
$(LIBZSTD): CFLAGS += -fPIC -fvisibility=hidden
-$(LIBZSTD): LDFLAGS += -shared $(LDFLAGS_DYNLIB)
+$(LIBZSTD): LDFLAGS += -shared -Wl,-rpath,'\$$\\$$\$$ORIGIN/./libs' $(LDFLAGS_DYNLIB)
+$(LIBZSTD): LDFLAGS += -shared -Wl,-rpath,'\$$\\$$\$$ORIGIN' $(LDFLAGS_DYNLIB)

ifndef BUILD_DIR
# determine BUILD_DIR from compilation flags
Expand All @@ -16,7 +16,7 @@ index ef202183..a7035f2c 100644
ZSTD_NOMT_FILES = $(filter-out $(ZSTDMT_FILES),$(ZSTD_FILES))
libzstd-nomt: CFLAGS += -fPIC -fvisibility=hidden
-libzstd-nomt: LDFLAGS += -shared
+libzstd-nomt: LDFLAGS += -shared -Wl,-rpath,'\$$\\$$\$$ORIGIN/./libs'
+libzstd-nomt: LDFLAGS += -shared -Wl,-rpath,'\$$\\$$\$$ORIGIN'
libzstd-nomt: $(ZSTD_NOMT_FILES)
@echo compiling single-thread dynamic library $(LIBVER)
@echo files : $(ZSTD_NOMT_FILES)

0 comments on commit fcf5c57

Please sign in to comment.