diff --git a/include/system.hpp b/include/system.hpp index d3be5945..f0795f6d 100644 --- a/include/system.hpp +++ b/include/system.hpp @@ -49,6 +49,7 @@ bool createDirectory(const std::string& path); Returns whether the creation was successful. */ bool createDirectories(const std::string& path); +bool createSymbolicLink(const std::string& target, const std::string& link); /** Deletes a file or empty directory. Returns whether the deletion was successful. */ diff --git a/plugin.mk b/plugin.mk index bbacbb1b..6d36e652 100644 --- a/plugin.mk +++ b/plugin.mk @@ -67,10 +67,14 @@ dist: all cp $(TARGET) dist/$(SLUG)/ ifdef ARCH_MAC $(STRIP) -S dist/$(SLUG)/$(TARGET) - $(INSTALL_NAME_TOOL) -change libRack.dylib @rpath/libRack.dylib dist/$(SLUG)/$(TARGET) - $(INSTALL_NAME_TOOL) -add_rpath . dist/$(SLUG)/$(TARGET) + $(INSTALL_NAME_TOOL) -change libRack.dylib /tmp/Rack2/libRack.dylib dist/$(SLUG)/$(TARGET) $(OTOOL) -L dist/$(SLUG)/$(TARGET) -else +endif +ifdef ARCH_LIN + $(STRIP) -s dist/$(SLUG)/$(TARGET) + # TODO Change libRack.so path to /tmp/Rack2/libRack.dylib +endif +ifdef ARCH_WIN $(STRIP) -s dist/$(SLUG)/$(TARGET) endif @# Copy distributables diff --git a/src/plugin.cpp b/src/plugin.cpp index d0042521..a4e041b3 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -52,11 +52,13 @@ static void* loadLibrary(std::string libraryPath) { throw Exception("Failed to load library %s: code %d", libraryPath.c_str(), error); } #else - // As of Rack v2.0, plugins are linked with `-rpath=.` so change current directory so it can find libRack. - std::string cwd = system::getWorkingDirectory(); - system::setWorkingDirectory(asset::systemDir); - // Change it back when we're finished - DEFER({system::setWorkingDirectory(cwd);}); + // Since Rack 2, plugins on Linux/Mac link to the absolute path /tmp/Rack2/libRack. + // Create a symlink at /tmp/Rack2 to the system dir containting libRack. + if (!settings::devMode) { + std::string systemDir = system::getAbsolute(asset::systemDir); + std::string linkPath = "/tmp/Rack2"; + system::createSymbolicLink(systemDir, linkPath); + } // Load library with dlopen void* handle = NULL; #if defined ARCH_LIN diff --git a/src/system.cpp b/src/system.cpp index 5eb9fbdb..c29fa637 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -165,6 +165,17 @@ bool createDirectories(const std::string& path) { } +bool createSymbolicLink(const std::string& target, const std::string& link) { + try { + fs::create_symlink(fs::u8path(target), fs::u8path(link)); + return true; + } + catch (fs::filesystem_error& e) { + return false; + } +} + + bool remove(const std::string& path) { try { return fs::remove(fs::u8path(path));