From 10f5582e2e04e719e0de0c666e10f10e5135d602 Mon Sep 17 00:00:00 2001 From: Vasily Kiniv Date: Sat, 11 Nov 2023 10:26:17 +0200 Subject: [PATCH 1/2] Add option to build for Apple Silicon --- .gitignore | 1 + cross-compile/macosx/contrib/pulseview | 27 -------- cross-compile/macosx/contrib/sigrok-cli | 27 -------- cross-compile/macosx/create_dmg | 80 ++++++++++++++++++----- cross-compile/macosx/sigrok-native-macosx | 46 +++++++++++-- 5 files changed, 105 insertions(+), 76 deletions(-) delete mode 100755 cross-compile/macosx/contrib/pulseview delete mode 100755 cross-compile/macosx/contrib/sigrok-cli diff --git a/.gitignore b/.gitignore index 155abe0..e742623 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build/ +cross-compile/macosx/build* firmware/kingst-la/*.bitstream firmware/kingst-la/*.fw diff --git a/cross-compile/macosx/contrib/pulseview b/cross-compile/macosx/contrib/pulseview deleted file mode 100755 index a77ae3e..0000000 --- a/cross-compile/macosx/contrib/pulseview +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -## -## This file is part of the sigrok-util project. -## -## Copyright (C) 2017 Uwe Hermann -## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; if not, see . -## - -DIR="$(dirname "$0")" -cd "$DIR" -export DYLD_LIBRARY_PATH="../Frameworks" -export PYTHONHOME="../Frameworks/Python.framework/Versions/3.7" -export SIGROK_FIRMWARE_DIR="../share/sigrok-firmware" -export SIGROKDECODE_DIR="../share/libsigrokdecode/decoders" -exec ./pulseview.real "$@" diff --git a/cross-compile/macosx/contrib/sigrok-cli b/cross-compile/macosx/contrib/sigrok-cli deleted file mode 100755 index 3eb8ee2..0000000 --- a/cross-compile/macosx/contrib/sigrok-cli +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/sh -## -## This file is part of the sigrok-util project. -## -## Copyright (C) 2020 Uwe Hermann -## -## This program is free software; you can redistribute it and/or modify -## it under the terms of the GNU General Public License as published by -## the Free Software Foundation; either version 2 of the License, or -## (at your option) any later version. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with this program; if not, see . -## - -DIR="$(dirname "$0")" -cd "$DIR" -export DYLD_LIBRARY_PATH="../Frameworks" -export PYTHONHOME="../Frameworks/Python.framework/Versions/3.7" -export SIGROK_FIRMWARE_DIR="../share/sigrok-firmware" -export SIGROKDECODE_DIR="../share/libsigrokdecode/decoders" -exec ./sigrok-cli.real "$@" diff --git a/cross-compile/macosx/create_dmg b/cross-compile/macosx/create_dmg index be97673..8e623df 100755 --- a/cross-compile/macosx/create_dmg +++ b/cross-compile/macosx/create_dmg @@ -23,6 +23,9 @@ set -e # The path where the installed sigrok libraries/binaries are located. PREFIX=$HOME/sr_macosx +# Build for Apple Silicon (y/n) +APPLE_SILICON=y + if [ "x$1" = "xsigrok-cli" ]; then APPNAME="sigrok-cli" APPNAME_BINARY="sigrok-cli" @@ -34,20 +37,30 @@ fi # The path where to download files to and where to build packages. BUILDDIR=./build_app_$APPNAME_BINARY -# We use Qt 5.5 in order to remain compatible with more versions of Mac OS X. -QTVER=qt@5.5 +if [[ $APPLE_SILICON = y ]]; then + # Use Qt6 if building for Apple Silicon + QTVER=qt@6 +else + # We use Qt 5.5 in order to remain compatible with more versions of Mac OS X. + QTVER=qt@5.5 +fi # Path to Qt5 binaries. QTBINDIR=`brew list $QTVER | grep bin | head -n 1 | xargs dirname` -QTTRANSLATIONSDIR=`brew --prefix $QTVER`/translations +QTTRANSLATIONSDIR=`brew --prefix $QTVER`/share/qt/translations # Path to boost libraries. BOOSTLIBDIR=`brew list boost | grep libboost_system | grep -v cmake | head -n 1 | xargs dirname` -# Path to Python 3 framework. -PYTHONFRAMEWORKDIR=`brew list python3 | grep libpython | head -n 1 | xargs dirname`/../../../.. +# Extract path and version of python3 framework from libsigrokdecode using otool +PYTHONFRAMEWORKDIR=$(otool -L $PREFIX/lib/libsigrokdecode.*.dylib | grep python | head -n 1) +PYTHONFRAMEWORKDIR=${PYTHONFRAMEWORKDIR%"/Python.framework"*} +PYTHONFRAMEWORKDIR=$(readlink -f $PYTHONFRAMEWORKDIR)/ +PYVER=${PYTHONFRAMEWORKDIR#*@} +PYVER=${PYVER%%"/"*} -PYVER="3.7" +# Path to dbus +DBUSLIBDIR=`brew list dbus | grep bin | head -n 1 | xargs dirname`/../lib # You usually don't need to change anything below this line. @@ -85,6 +98,15 @@ if [ "x$APPNAME_BINARY" = "xpulseview" ]; then mkdir -p $CONTENTSDIR/translations cp $QTTRANSLATIONSDIR/qt_*.qm $CONTENTSDIR/translations cp $QTTRANSLATIONSDIR/qtbase_*.qm $CONTENTSDIR/translations + + if [[ $APPLE_SILICON = y ]]; then + # Copy QtDBus, which should be but is not actually copied by macdeployqt + cp -R $QTBINDIR/../lib/QtDBus.framework $FRAMEWORKSDIR + rm -rf $FRAMEWORKSDIR/QtDBus.framework/Headers + # Copy dbus + cp $DBUSLIBDIR/*.dylib $FRAMEWORKSDIR + chmod 644 $FRAMEWORKSDIR/libdbus*.dylib + fi fi $QTBINDIR/macdeployqt $APPNAME.app @@ -109,18 +131,46 @@ rm -rf $PYDIR/lib/python$PYVER/__pycache__ rm -rf $PYDIR/lib/python$PYVER/**/__pycache__ rm -rf $PYDIR/lib/python$PYVER/**/**/__pycache__ rm -rf $PYDIR/Resources -install_name_tool -change \ - /usr/local/opt/python/Frameworks/Python.framework/Versions/$PYVER/Python \ - @executable_path/../Frameworks/Python.framework/Versions/$PYVER/Python \ - $FRAMEWORKSDIR/libsigrokdecode.*.dylib -install_name_tool -change \ - /usr/local/opt/python/Frameworks/Python.framework/Versions/$PYVER/Python \ - @executable_path/../Frameworks/Python.framework/Versions/$PYVER/Python \ - $PREFIX/lib/libirmp.*.dylib + +PYFRAMEWORKSDIR_SRC=/usr/local/opt/python/Frameworks/Python.framework/Versions/$PYVER/Python +if [[ $APPLE_SILICON = y ]]; then + PYFRAMEWORKSDIR_SRC=/opt/homebrew/opt/python@$PYVER/Frameworks/Python.framework/Versions/$PYVER/Python +fi +PYFRAMEWORKSDIR_DST=@executable_path/../Frameworks/Python.framework/Versions/$PYVER/Python +install_name_tool -change $PYFRAMEWORKSDIR_SRC $PYFRAMEWORKSDIR_DST $FRAMEWORKSDIR/libsigrokdecode.*.dylib +install_name_tool -change $PYFRAMEWORKSDIR_SRC $PYFRAMEWORKSDIR_DST $PREFIX/lib/libirmp.*.dylib + +if [[ $APPLE_SILICON = y ]]; then + # Sign all binaries recursively + function sign_all { + for f in $1/*; do + file_type_str=$(file -Ih $f) + mime=${file_type_str#*: } + if [[ $mime = "inode/directory;"* ]]; then + sign_all $f + elif [[ $mime = "application/x-mach-binary;"* ]]; then + codesign --force -s - $f &> /dev/null || : + fi + done + } + sign_all $MACOSDIR + sign_all $FRAMEWORKSDIR + sign_all $CONTENTSDIR/PlugIns +fi # Add wrapper (sets PYTHONHOME/SIGROK_FIRMWARE_DIR/SIGROKDECODE_DIR). mv $MACOSDIR/$APPNAME_BINARY $MACOSDIR/$APPNAME_BINARY.real -cp ../contrib/$APPNAME_BINARY $MACOSDIR +cat <> $MACOSDIR/$APPNAME_BINARY +#!/bin/sh + +DIR="\$(dirname "\$0")" +cd "\$DIR" +export DYLD_LIBRARY_PATH="../Frameworks" +export PYTHONHOME="../Frameworks/Python.framework/Versions/$PYVER" +export SIGROK_FIRMWARE_DIR="../share/sigrok-firmware" +export SIGROKDECODE_DIR="../share/libsigrokdecode/decoders" +exec ./$APPNAME_BINARY.real "\$@" +EOT chmod 755 $MACOSDIR/$APPNAME_BINARY cp ../contrib/Info.plist_$APPNAME_BINARY $CONTENTSDIR/Info.plist diff --git a/cross-compile/macosx/sigrok-native-macosx b/cross-compile/macosx/sigrok-native-macosx index 7f6380e..aa4c20f 100755 --- a/cross-compile/macosx/sigrok-native-macosx +++ b/cross-compile/macosx/sigrok-native-macosx @@ -23,6 +23,13 @@ set -e # The path where the compiled packages will be installed. PREFIX=$HOME/sr_macosx +# Run tests (y/n) +ENABLE_TESTS=n + +# Build for Apple Silicon (y/n) +# Tests is currently failing on Apple Silicon, disable tests by setting ENABLE_TESTS=n +APPLE_SILICON=y + # The path where to download files to and where to build packages. BUILDDIR=./build @@ -44,8 +51,13 @@ PARALLEL="-j "`sysctl -n hw.ncpu` export CC=gcc export CXX=g++ -# We use Qt 5.5 in order to remain compatible with more versions of Mac OS X. -QTVER=qt@5.5 +if [[ $APPLE_SILICON = y ]]; then + # Use Qt6 if building for Apple Silicon + QTVER=qt@6 +else + # We use Qt 5.5 in order to remain compatible with more versions of Mac OS X. + QTVER=qt@5.5 +fi # Path to Qt5 binaries (needed for cmake to find the Qt5 libs). export PATH="$(brew --prefix $QTVER)/bin:$PATH" @@ -54,10 +66,24 @@ export PATH="$(brew --prefix $QTVER)/bin:$PATH" # ----------------------------------------------------------------------------- +if [[ $APPLE_SILICON = y ]]; then + qt5_found=$(brew list --versions qt@5 || :) + if [[ $qt5_found ]]; then + echo "\033[0;31mWarning: PulseView build will most likely fail, because Qt5 is installed and will be picked by CMake over Qt6. Uninstall Qt5 or modify PulseView CMake.\033[0m" + fi + if [[ $ENABLE_TESTS = y ]]; then + echo "\033[0;31mWarning: Tests will most likely fail on Apple Silicon, disable tests by setting ENABLE_TESTS=n\033[0m" + fi +fi + # PKG_CONFIG_PATH will need to point to pkg-config files of Homebrew's # keg-only formulae. +FORMULAS=("libffi" "python@3") +if [[ $APPLE_SILICON = n ]]; then + FORMULAS+=("python@2" "$QTVER") +fi P="$PREFIX/lib/pkgconfig" -for FORMULA in libffi python@2 python@3 "$QTVER"; do +for FORMULA in ${FORMULAS[@]}; do P="$P:$(brew --prefix "$FORMULA")/lib/pkgconfig" done @@ -96,7 +122,9 @@ cd build PKG_CONFIG_PATH=$P ../configure $C $SB make $PARALLEL $V PYTHONPATH=$PYPATH $SB make install $V -$SB make check $V +if [[ $ENABLE_TESTS = y ]]; then + $SB make check $V +fi cd ../.. # libsigrokdecode @@ -108,7 +136,9 @@ cd build PKG_CONFIG_PATH=$P ../configure $C $SB make $PARALLEL $V make install $V -$SB make check $V +if [[ $ENABLE_TESTS = y ]]; then + $SB make check $V +fi cd ../.. # sigrok-firmware @@ -150,9 +180,11 @@ $GIT_CLONE $REPO_BASE/pulseview cd pulseview mkdir build cd build -PKG_CONFIG_PATH=$P $SB cmake -DCMAKE_INSTALL_PREFIX:PATH=$PREFIX -DDISABLE_WERROR=y -DENABLE_TESTS=y .. +PKG_CONFIG_PATH=$P $SB cmake -DCMAKE_INSTALL_PREFIX:PATH=$PREFIX -DDISABLE_WERROR=y -DENABLE_TESTS=$ENABLE_TESTS .. $SB make $PARALLEL $V make install $V -$SB make test $V +if [[ $ENABLE_TESTS = y ]]; then + $SB make test $V +fi cd ../.. From 484603b61215d2e31715193ccc91d6e51afee02d Mon Sep 17 00:00:00 2001 From: Vasily Kiniv Date: Sat, 11 Nov 2023 10:51:10 +0200 Subject: [PATCH 2/2] Revert Qt translations path for old macOS, style fix --- cross-compile/macosx/create_dmg | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cross-compile/macosx/create_dmg b/cross-compile/macosx/create_dmg index 8e623df..ffd441c 100755 --- a/cross-compile/macosx/create_dmg +++ b/cross-compile/macosx/create_dmg @@ -39,7 +39,7 @@ BUILDDIR=./build_app_$APPNAME_BINARY if [[ $APPLE_SILICON = y ]]; then # Use Qt6 if building for Apple Silicon - QTVER=qt@6 + QTVER=qt@6 else # We use Qt 5.5 in order to remain compatible with more versions of Mac OS X. QTVER=qt@5.5 @@ -47,7 +47,11 @@ fi # Path to Qt5 binaries. QTBINDIR=`brew list $QTVER | grep bin | head -n 1 | xargs dirname` -QTTRANSLATIONSDIR=`brew --prefix $QTVER`/share/qt/translations +if [[ $APPLE_SILICON = y ]]; then + QTTRANSLATIONSDIR=`brew --prefix $QTVER`/share/qt/translations +else + TRANSLATIONSDIR=`brew --prefix $QTVER`/translations +fi # Path to boost libraries. BOOSTLIBDIR=`brew list boost | grep libboost_system | grep -v cmake | head -n 1 | xargs dirname`