From f7c8e097e2926334b5b859baa106fe66ad54178c Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Fri, 16 Dec 2022 12:08:35 -0500 Subject: [PATCH] Use plugin-CPU.EXT filename for plugin binary on non-x64 CPUs, so multiple binaries can coexist. --- plugin.mk | 12 +++++++++--- src/plugin.cpp | 11 ++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/plugin.mk b/plugin.mk index 88a51f51..47438416 100644 --- a/plugin.mk +++ b/plugin.mk @@ -23,8 +23,14 @@ LDFLAGS += -L$(RACK_DIR) -lRack include $(RACK_DIR)/arch.mk +TARGET := plugin +ifndef ARCH_X64 + # On non-x64, append CPU name to plugin binary + TARGET := $(TARGET)-$(ARCH_CPU) +endif + ifdef ARCH_LIN - TARGET := plugin.so + TARGET := $(TARGET).so # This prevents static variables in the DSO (dynamic shared object) from being preserved after dlclose(). FLAGS += -fno-gnu-unique # When Rack loads a plugin, it symlinks /tmp/Rack2 to its system dir, so the plugin can link to libRack. @@ -35,13 +41,13 @@ ifdef ARCH_LIN endif ifdef ARCH_MAC - TARGET := plugin.dylib + TARGET := $(TARGET).dylib LDFLAGS += -undefined dynamic_lookup RACK_USER_DIR ?= $(HOME)/Documents/Rack2 endif ifdef ARCH_WIN - TARGET := plugin.dll + TARGET := $(TARGET).dll LDFLAGS += -static-libstdc++ RACK_USER_DIR ?= $(USERPROFILE)/Documents/Rack2 endif diff --git a/src/plugin.cpp b/src/plugin.cpp index 0b969f88..25621f66 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -102,7 +102,16 @@ static InitCallback loadPluginCallback(Plugin* plugin) { #elif ARCH_MAC libraryExt = "dylib"; #endif - std::string libraryPath = system::join(plugin->path, "plugin." + libraryExt); + +#if defined ARCH_X64 + // Use `plugin.EXT` on x64 for backward compatibility. + // Change to `plugin-OS-CPU.EXT` in Rack 3. + std::string libraryFilename = "plugin." + libraryExt; +#else + // Use `plugin-CPU.EXT` on other CPUs like ARM64 + std::string libraryFilename = "plugin-" + APP_CPU + "." + libraryExt; +#endif + std::string libraryPath = system::join(plugin->path, libraryFilename); // Check file existence if (!system::isFile(libraryPath))