From eff5da51c45f7971dbd1a36e423f8a6964e988a8 Mon Sep 17 00:00:00 2001 From: Tom M Date: Tue, 10 May 2022 23:15:09 +0200 Subject: [PATCH 1/4] Add universal build to Mac CI pipeline (#1096) --- .azure/azure-pipelines-mac.yml | 131 ++++++++++++++++++++++++++++++++- 1 file changed, 130 insertions(+), 1 deletion(-) diff --git a/.azure/azure-pipelines-mac.yml b/.azure/azure-pipelines-mac.yml index 5665acef..70b53c10 100644 --- a/.azure/azure-pipelines-mac.yml +++ b/.azure/azure-pipelines-mac.yml @@ -13,8 +13,14 @@ trigger: - '.cirrus.yml' - 'README.md' +parameters: +- name: UseCache + displayName: Use Dependency Cache + type: boolean + default: true + jobs: -- job: macOS +- job: macOS_brew strategy: matrix: UnixLibs: @@ -26,6 +32,9 @@ jobs: 11_0: imageName: 'macos-11' CMakeFlags: '' + 12_0: + imageName: 'macos-12' + CMakeFlags: '' pool: vmImage: $(imageName) @@ -67,3 +76,123 @@ jobs: cmake -DCMAKE_INSTALL_PREFIX=$(Build.ArtifactStagingDirectory) .. make install displayName: 'Install fluidsynth to artifact dir' + + +- job: macOS_ports + timeoutInMinutes: 300 + strategy: + matrix: + # SDL2/SDL_cpuinfo.h includes some x86 specific headers, which ofc doesn't work when cross compiling for arm64 + # And this universal build thingy doesn't work on Mac10.15 for some reason... + # Furthermore, there is a problem when restoring the cache on Mac11, so disable this job as well + #11_0_universal_unixlibs: + # macPortsUrl: 'https://github.com/macports/macports-base/releases/download/v2.7.2/MacPorts-2.7.2-11-BigSur.pkg' + # imageName: 'macos-11' + # CMakeFlags: '-Denable-sdl2=0 -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -Denable-framework=0 -DLIB_SUFFIX=""' + 12_0_universal_unixlibs: + macPortsUrl: 'https://github.com/macports/macports-base/releases/download/v2.7.2/MacPorts-2.7.2-12-Monterey.pkg' + imageName: 'macos-12' + CMakeFlags: '-Denable-sdl2=0 -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -Denable-framework=0 -DLIB_SUFFIX=""' + pool: + vmImage: $(imageName) + steps: + - script: | + set -ex + brew install wget pkg-config + wget $(macPortsUrl) + sudo installer -pkg *.pkg -target / + rm -f *.pkg + sudo chown -R $(id -u):$(id -g) /opt/local + sudo chflags nouchg /opt/local + displayName: 'Prerequisites' + workingDirectory: $(Agent.TempDirectory) + - task: Cache@2 + continueOnError: true + displayName: "Cache macPort packages" + condition: and(not(in(variables['Build.Reason'], 'Schedule')), ${{ parameters.useCache }}) + inputs: + key: '"$(Agent.OS)" | "$(imageName)" | "$(macPortsUrl)" | "versionalways"' + path: '/opt/local' + cacheHitVar: CACHE_RESTORED + - script: | + set -x + export PATH=$PATH:/opt/local/bin + echo $PATH + which codesign + codesign --help + which port + echo "+universal" | sudo tee -a /opt/local/etc/macports/variants.conf + + sudo sh -c 'cat << EOF >> /opt/local/etc/macports/macports.conf + buildfromsource always + universal_archs arm64 x86_64 + ui_interactive no + EOF' + + sudo port deps glib2-devel + sudo port deps libsndfile + sudo port deps dbus-glib + sudo port deps libomp-devel + sudo port install glib2-devel libsndfile dbus-glib libomp-devel + # remove all extended attributes, as they cannot be restored when restoring the pipeline cache + sudo xattr -rcv /opt/local + # fixup permissions to allow non-priv pipeline user access every directory, to make the caching step succeed at the end + sudo chown -R $(id -u):$(id -g) /opt/local + displayName: 'Port install universal' + condition: and(succeeded(), ne(variables.CACHE_RESTORED, 'true')) + - script: | + set -ex + export PATH=$PATH:/opt/local/bin + export PKG_CONFIG_PATH="/opt/local/lib/pkgconfig" + mkdir build && cd build + cmake -Werror=dev $(CMakeFlags) -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_VERBOSE_MAKEFILE=1 -DNO_GUI=1 .. + make -j3 + displayName: 'Compile fluidsynth' + - script: | + export PATH=$PATH:/opt/local/bin + sudo port -v install fluidsynth +universal + displayName: 'port install fluidsynth +universal' + condition: failed() + - script: | + cat /opt/local/var/macports/logs/*_fluidsynth/fluidsynth/main.log + condition: failed() + displayName: 'Print fluidsynth error log' + - script: | + set -ex + cd build + make -j3 check + displayName: 'Execute Unittests' + - script: | + set -ex + cd build + make -j3 demo + displayName: 'Compile demos' + - script: | + set -ex + cd build + sudo make install + rm -f install_manifest.txt + displayName: 'Install fluidsynth to default location' + - script: | + set -ex + cd build + cmake -DCMAKE_INSTALL_PREFIX=$(Build.ArtifactStagingDirectory) .. + make install + cd /opt/local/lib/ + cp -a libgthread*.dylib libglib*.dylib libintl*.dylib libsndfile*.dylib libdbus-*.dylib libreadline*.dylib $(Build.ArtifactStagingDirectory)/lib + file /opt/local/lib/libglib-2.0.dylib $(Build.ArtifactStagingDirectory)/bin/fluidsynth $(Build.ArtifactStagingDirectory)/lib/libfluidsynth*.dylib + displayName: 'Install fluidsynth to artifact dir' + - task: PublishBuildArtifacts@1 + displayName: 'Publish fluidsynth artifacts' + inputs: + PathtoPublish: '$(Build.ArtifactStagingDirectory)' + ArtifactName: 'fluidsynth-$(imageName)' + publishLocation: 'Container' + - task: PublishBuildArtifacts@1 + displayName: 'Publish macPorts deps' + enabled: false + condition: and(succeeded(), ne(variables.CACHE_RESTORED, 'true')) + inputs: + PathtoPublish: '/opt/local/lib' + ArtifactName: 'macports-$(imageName)' + publishLocation: 'Container' From f013e82d58d00e8feb7e82e22051632c61893306 Mon Sep 17 00:00:00 2001 From: derselbst Date: Sat, 21 May 2022 20:43:18 +0200 Subject: [PATCH 2/4] Fix size_t to int truncation in new_fluid_midi_file() --- src/midi/fluid_midi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/midi/fluid_midi.c b/src/midi/fluid_midi.c index 89271cf3..778a705b 100644 --- a/src/midi/fluid_midi.c +++ b/src/midi/fluid_midi.c @@ -126,8 +126,13 @@ new_fluid_midi_file(const char *buffer, size_t length) { fluid_midi_file *mf; - mf = FLUID_NEW(fluid_midi_file); + if(length > INT_MAX) + { + FLUID_LOG(FLUID_ERR, "Refusing to open a MIDI file which is bigger than 2GiB"); + return NULL; + } + mf = FLUID_NEW(fluid_midi_file); if(mf == NULL) { FLUID_LOG(FLUID_ERR, "Out of memory"); @@ -140,7 +145,7 @@ new_fluid_midi_file(const char *buffer, size_t length) mf->running_status = -1; mf->buffer = buffer; - mf->buf_len = length; + mf->buf_len = (int)length; mf->buf_pos = 0; mf->eof = FALSE; From d554067fc553465177e68982f0bd6f6aab4c2cfb Mon Sep 17 00:00:00 2001 From: derselbst Date: Sat, 21 May 2022 21:35:16 +0200 Subject: [PATCH 3/4] Fix size_t to int truncation in fluid_wasapi_finddev_callback() --- src/drivers/fluid_wasapi.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/drivers/fluid_wasapi.c b/src/drivers/fluid_wasapi.c index 7fc82098..f94077f9 100644 --- a/src/drivers/fluid_wasapi.c +++ b/src/drivers/fluid_wasapi.c @@ -803,6 +803,7 @@ static void fluid_wasapi_finddev_callback(IMMDevice *dev, void *data) { fluid_wasapi_finddev_data_t *d = (fluid_wasapi_finddev_data_t *)data; int nsz; + size_t id_len; char *name = NULL; wchar_t *id = NULL; IPropertyStore *prop = NULL; @@ -841,9 +842,15 @@ static void fluid_wasapi_finddev_callback(IMMDevice *dev, void *data) goto cleanup; } - nsz = wcslen(id); - d->id = FLUID_ARRAY(wchar_t, nsz + 1); - FLUID_MEMCPY(d->id, id, sizeof(wchar_t) * (nsz + 1)); + id_len = wcslen(id); + if(id_len >= UINT_MAX / sizeof(wchar_t)) + { + FLUID_LOG(FLUID_ERR, "wasapi: the returned device identifier was way too long"); + goto cleanup; + } + id_len++; + d->id = FLUID_ARRAY(wchar_t, id_len); + FLUID_MEMCPY(d->id, id, sizeof(wchar_t) * id_len); } cleanup: From 0d0b4d4b8458025041b6bca4c7c87babe937b796 Mon Sep 17 00:00:00 2001 From: Tom M Date: Mon, 23 May 2022 00:37:23 +0200 Subject: [PATCH 4/4] Fix universal MacOS CI build (#1106) Do not build libomp, because it depends on cmake-bootstrap, which for some reason tries to execute a unit test compiled for arm64, which obviously fails on a x86_64 host. --- .azure/azure-pipelines-mac.yml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.azure/azure-pipelines-mac.yml b/.azure/azure-pipelines-mac.yml index 70b53c10..b8247516 100644 --- a/.azure/azure-pipelines-mac.yml +++ b/.azure/azure-pipelines-mac.yml @@ -115,29 +115,26 @@ jobs: path: '/opt/local' cacheHitVar: CACHE_RESTORED - script: | - set -x + set -ex export PATH=$PATH:/opt/local/bin echo $PATH which codesign - codesign --help which port + cmake --version || true + echo "+universal" | sudo tee -a /opt/local/etc/macports/variants.conf - + sudo sh -c 'cat << EOF >> /opt/local/etc/macports/macports.conf buildfromsource always universal_archs arm64 x86_64 ui_interactive no EOF' - - sudo port deps glib2-devel - sudo port deps libsndfile - sudo port deps dbus-glib - sudo port deps libomp-devel - sudo port install glib2-devel libsndfile dbus-glib libomp-devel - # remove all extended attributes, as they cannot be restored when restoring the pipeline cache - sudo xattr -rcv /opt/local + + sudo port install glib2-devel libsndfile dbus-glib readline # fixup permissions to allow non-priv pipeline user access every directory, to make the caching step succeed at the end sudo chown -R $(id -u):$(id -g) /opt/local + # remove all extended attributes, as they cannot be restored when restoring the pipeline cache + #sudo xattr -rcv /opt/local displayName: 'Port install universal' condition: and(succeeded(), ne(variables.CACHE_RESTORED, 'true')) - script: | @@ -153,7 +150,11 @@ jobs: sudo port -v install fluidsynth +universal displayName: 'port install fluidsynth +universal' condition: failed() + enabled: false - script: | + set -x + cat /opt/local/var/macports/logs/*cmake-bootstrap/cmake-bootstrap/main.log + cat /opt/local/var/macports/build/*cmake-bootstrap/cmake-bootstrap/work/cmake-3.9.4-arm64/Bootstrap.cmk/*.log cat /opt/local/var/macports/logs/*_fluidsynth/fluidsynth/main.log condition: failed() displayName: 'Print fluidsynth error log'