From 028d1eea780aad582d49804c79237bc2231791c5 Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 1 Aug 2022 12:41:04 +0100 Subject: [PATCH] Projucer: Fix signing issue when building LV2 plugins on Arm macs --- .../ProjectSaving/jucer_ProjectExport_Xcode.h | 11 ++++++- .../LV2/juce_LV2TurtleDumpProgram.cpp | 30 +++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Xcode.h b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Xcode.h index 6344807c9c..9e9e60bd79 100644 --- a/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Xcode.h +++ b/extras/Projucer/Source/ProjectSaving/jucer_ProjectExport_Xcode.h @@ -2299,7 +2299,16 @@ private: if (target->type == XcodeTarget::LV2PlugIn) { - auto script = "set -e\n\"$CONFIGURATION_BUILD_DIR/../" + // When building LV2 plugins on Arm macs, we need to load and run the plugin bundle + // during a post-build step in order to generate the plugin's supporting files. Arm + // macs will only load shared libraries if they are signed, but Xcode runs its + // signing step after any post-build scripts. As a workaround, we check whether the + // plugin is signed and generate an adhoc certificate if necessary, before running + // the manifest-generator. + auto script = "set -e\n" + "xcrun codesign --verify \"$CONFIGURATION_BUILD_DIR/$PRODUCT_NAME\" " + "|| xcrun codesign -s - \"$CONFIGURATION_BUILD_DIR/$PRODUCT_NAME\"\n" + "\"$CONFIGURATION_BUILD_DIR/../" + Project::getLV2FileWriterName() + "\" \"$CONFIGURATION_BUILD_DIR/$PRODUCT_NAME\"\n"; diff --git a/modules/juce_audio_plugin_client/LV2/juce_LV2TurtleDumpProgram.cpp b/modules/juce_audio_plugin_client/LV2/juce_LV2TurtleDumpProgram.cpp index 0e4723d28b..1e4a4bc15d 100644 --- a/modules/juce_audio_plugin_client/LV2/juce_LV2TurtleDumpProgram.cpp +++ b/modules/juce_audio_plugin_client/LV2/juce_LV2TurtleDumpProgram.cpp @@ -23,18 +23,36 @@ ============================================================================== */ +#include +#include + #ifdef _WIN32 #include + #include HMODULE dlopen (const char* filename, int) { return LoadLibrary (filename); } FARPROC dlsym (HMODULE handle, const char* name) { return GetProcAddress (handle, name); } + void printError() + { + constexpr DWORD numElements = 256; + TCHAR messageBuffer[numElements]{}; + + FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, + GetLastError(), + MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), + messageBuffer, + numElements - 1, + nullptr); + + _tprintf ("%s", messageBuffer); + } enum { RTLD_LAZY = 0 }; #else #include + void printError() { printf ("%s\n", dlerror()); } #endif -#include - -// Replicating some of the LV2 header here so that we don't have to set up any +// Replicating part of the LV2 header here so that we don't have to set up any // custom include paths for this file. // Normally this would be a bad idea, but the LV2 API has to keep these definitions // in order to remain backwards-compatible. @@ -67,12 +85,18 @@ int main (int argc, const char** argv) }; if (auto* handle = dlopen (libraryPath, RTLD_LAZY)) + { if (auto* getDescriptor = reinterpret_cast (dlsym (handle, "lv2_descriptor"))) if (auto* descriptor = getDescriptor (0)) if (auto* extensionData = descriptor->extension_data) if (auto* recallFeature = reinterpret_cast (extensionData ("https://lv2-extensions.juce.com/turtle_recall"))) if (auto* doRecall = recallFeature->doRecall) return doRecall (libraryPath); + } + else + { + printError(); + } return 1; }