@@ -49,6 +49,7 @@ bool createDirectory(const std::string& path); | |||||
Returns whether the creation was successful. | Returns whether the creation was successful. | ||||
*/ | */ | ||||
bool createDirectories(const std::string& path); | bool createDirectories(const std::string& path); | ||||
bool createSymbolicLink(const std::string& target, const std::string& link); | |||||
/** Deletes a file or empty directory. | /** Deletes a file or empty directory. | ||||
Returns whether the deletion was successful. | Returns whether the deletion was successful. | ||||
*/ | */ | ||||
@@ -67,10 +67,14 @@ dist: all | |||||
cp $(TARGET) dist/$(SLUG)/ | cp $(TARGET) dist/$(SLUG)/ | ||||
ifdef ARCH_MAC | ifdef ARCH_MAC | ||||
$(STRIP) -S dist/$(SLUG)/$(TARGET) | $(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) | $(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) | $(STRIP) -s dist/$(SLUG)/$(TARGET) | ||||
endif | endif | ||||
@# Copy distributables | @# Copy distributables | ||||
@@ -52,11 +52,13 @@ static void* loadLibrary(std::string libraryPath) { | |||||
throw Exception("Failed to load library %s: code %d", libraryPath.c_str(), error); | throw Exception("Failed to load library %s: code %d", libraryPath.c_str(), error); | ||||
} | } | ||||
#else | #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.<ext> | |||||
// 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 | // Load library with dlopen | ||||
void* handle = NULL; | void* handle = NULL; | ||||
#if defined ARCH_LIN | #if defined ARCH_LIN | ||||
@@ -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) { | bool remove(const std::string& path) { | ||||
try { | try { | ||||
return fs::remove(fs::u8path(path)); | return fs::remove(fs::u8path(path)); | ||||