[vlc-devel] [PATCH] extras: fix arch handling in macOS build script

Felix Paul Kühne fkuehne at videolan.org
Thu Dec 10 17:43:21 CET 2020


Hello Rémi,

Thanks for your detailed and rapid review!

> Am 09.12.2020 um 19:23 schrieb Rémi Denis-Courmont <remi at remlab.net>:
> 
> Le mercredi 9 décembre 2020, 18:33:48 EET Felix Paul Kühne a écrit :
>> From: Felix Paul Kühne <felix at feepk.net>
> 
> I'm sure Steve is itching to tell you that that's not necessary (though it 
> actually would be if someone were to git-am this email).

Tbh, I would need to check how to remove this or just change the email address used by git, which is probably easier.

> 
>> ---
>> extras/package/macosx/build.sh     | 27 +++++++-----
>> extras/package/macosx/env.build.sh | 71 +++++++++++++++++++++++-------
>> 2 files changed, 73 insertions(+), 25 deletions(-)
>> 
>> diff --git a/extras/package/macosx/build.sh b/extras/package/macosx/build.sh
>> index 69395ef5d0..554069f97c 100755
>> --- a/extras/package/macosx/build.sh
>> +++ b/extras/package/macosx/build.sh
>> @@ -115,9 +115,13 @@ if [ "$QUIET" = "yes" ]; then
>>     out="/dev/null"
>> fi
>> 
>> -info "Building VLC for the Mac OS X"
>> +ACTUAL_ARCH=`get_actual_arch $ARCH`
>> +BUILD_ARCH=`get_buildsystem_arch $BUILD_ARCH`
> 
> Can you keep it consistent maybe? Call it HOST like below, like contribs and 
> like autoconf?

Good idea.

> 
>> 
>> -TRIPLET=$(vlcGetTriplet)
>> +info "Building VLC for macOS for architecture ${ACTUAL_ARCH} on a
>> ${BUILD_ARCH} device" +
>> +BUILD_TRIPLET=$(vlcGetBuildTriplet)
>> +HOST_TRIPLET=$(vlcGetHostTriplet)
>> export SDKROOT
>> vlcSetBaseEnvironment
>> vlcroot="$(vlcGetRootDir)"
>> @@ -157,11 +161,11 @@ info "Building contribs"
>> spushd "${vlcroot}/contrib"
>> 
>> if [ "$REBUILD" = "yes" ]; then
>> -    rm -rf contrib-$TRIPLET
>> -    rm -rf $TRIPLET
>> +    rm -rf contrib-$HOST_TRIPLET
>> +    rm -rf $HOST_TRIPLET
>> fi
>> -mkdir -p contrib-$TRIPLET && cd contrib-$TRIPLET
>> -../bootstrap --build=$TRIPLET --host=$TRIPLET > $out
>> +mkdir -p contrib-$HOST_TRIPLET && cd contrib-$HOST_TRIPLET
>> +../bootstrap --build=$BUILD_TRIPLET --host=$HOST_TRIPLET > $out
>> 
>> if [ "$CONTRIBFROMSOURCE" = "yes" ]; then
>>     make list
>> @@ -182,6 +186,7 @@ spopd
>> 
>> 
>> vlcUnsetContribEnvironment
>> +vlcSetLibVLCEnvironment
>> 
>> #
>> # vlc/bootstrap
>> @@ -214,8 +219,8 @@ fi
>> if [ "${vlcroot}/configure" -nt Makefile ]; then
>> 
>>   ${vlcroot}/extras/package/macosx/configure.sh \
>> -      --build=$TRIPLET \
>> -      --host=$TRIPLET \
>> +      --build=$BUILD_TRIPLET \
>> +      --host=$HOST_TRIPLET \
>>       --with-macosx-version-min=$MINIMAL_OSX_VERSION \
>>       --with-macosx-sdk=$SDKROOT \
>>       $CONFIGFLAGS \
>> @@ -237,7 +242,6 @@ make -j$JOBS
>> info "Preparing VLC.app"
>> make VLC.app
>> 
>> -
>> if [ "$PACKAGETYPE" = "u" ]; then
>>     info "Copying app with debug symbols into VLC-debug.app and stripping"
>>     rm -rf VLC-debug.app
>> @@ -248,14 +252,15 @@ if [ "$PACKAGETYPE" = "u" ]; then
>>     (cd VLC-debug.app/Contents/MacOS/lib/ && rm libvlccore.dylib && mv
>> libvlccore.*.dylib libvlccore.dylib) (cd VLC-debug.app/Contents/MacOS/lib/
>> && rm libvlc.dylib && mv libvlc.*.dylib libvlc.dylib)
>> 
>> -
>>     find VLC.app/ -name "*.dylib" -exec strip -x {} \;
>>     find VLC.app/ -type f -name "VLC" -exec strip -x {} \;
>>     find VLC.app/ -type f -name "Sparkle" -exec strip -x {} \;
>>     find VLC.app/ -type f -name "Growl" -exec strip -x {} \;
>>     find VLC.app/ -type f -name "Breakpad" -exec strip -x {} \;
>> 
>> +if [ "$BUILD_TRIPLET" = "$HOST_TRIPLET" ]; then
>>     bin/vlc-cache-gen VLC.app/Contents/MacOS/plugins
>> +fi
> 
> Indentation.

Fixed.

> And obviously, this might make VLC load times suck, depending how fast the 
> hardware is, and if PIC is supported or not.

On a pre-release device cold launched from the internal SSD, the time to do vlc vlc://quit is 0.33s with a cache and 0.38s, so this should be OK for the average user. Of course, this may differ for more advanced playback scenarios.


> 
>>     info "Building VLC release archive"
>>     make package-macosx-release
>> @@ -273,3 +278,5 @@ fi
>> if [ ! -z "$VLCBUILDDIR" ]; then
>>     popd
>> fi
>> +
>> +vlcUnsetLibVLCEnvironment
> 
> This is a big strange and brittle approach. As in, it won't work properly if 
> the original values actually were set. Normally, to restore environment 
> variables, you just set them (in a child process) and exit.

Ehm, thanks, yes :D


> 
>> diff --git a/extras/package/macosx/env.build.sh
>> b/extras/package/macosx/env.build.sh index 755722fb9b..894a6f9fd2 100755
>> --- a/extras/package/macosx/env.build.sh
>> +++ b/extras/package/macosx/env.build.sh
>> @@ -1,16 +1,40 @@
>> #!/bin/bash
>> 
>> ARCH="x86_64"
>> +BUILD_ARCH=`uname -m | cut -d. -f1`
>> MINIMAL_OSX_VERSION="10.11"
>> 
>> +get_actual_arch() {
>> +    if [ "$1" = "aarch64" ]; then
>> +        echo "arm64"
>> +    else
>> +        echo "$1"
>> +    fi
>> +}
>> +
>> +get_buildsystem_arch() {
>> +    if [ "$1" = "arm64" ]; then
>> +        echo "aarch64"
>> +    else
>> +        echo "$1"
>> +    fi
>> +}
>> 
>> -vlcGetTriplet() {
>> +vlcGetOSXKernelVersion() {
>>     local OSX_KERNELVERSION=$(uname -r | cut -d. -f1)
>>     if [ ! -z "$VLC_FORCE_KERNELVERSION" ]; then
>>         OSX_KERNELVERSION="$VLC_FORCE_KERNELVERSION"
>>     fi
>> 
>> -    echo "$ARCH-apple-darwin$OSX_KERNELVERSION"
>> +    echo "$OSX_KERNELVERSION"
>> +}
>> +
>> +vlcGetBuildTriplet() {
>> +    echo "$BUILD_ARCH-apple-darwin$(vlcGetOSXKernelVersion)"
>> +}
>> +
>> +vlcGetHostTriplet() {
>> +    echo "$ARCH-apple-darwin$(vlcGetOSXKernelVersion)"
>> }
>> 
>> # Gets VLCs root dir based on location of this file, also follow symlinks
>> @@ -25,30 +49,32 @@ vlcGetRootDir() {
>> }
>> 
>> vlcSetBaseEnvironment() {
>> -    local LOCAL_TRIPLET="$TRIPLET"
>> -    if [ -z "$LOCAL_TRIPLET" ]; then
>> -        LOCAL_TRIPLET="$(vlcGetTriplet)"
>> +    local LOCAL_BUILD_TRIPLET="$BUILD_TRIPLET"
>> +    if [ -z "$LOCAL_BUILD_TRIPLET" ]; then
>> +        LOCAL_BUILD_TRIPLET="$(vlcGetBuildTriplet)"
>>     fi
>> 
>>     local VLC_ROOT_DIR="$(vlcGetRootDir)"
>> 
>>     echo "Setting base environment"
>> -    echo "Using VLC root dir $VLC_ROOT_DIR and triplet $LOCAL_TRIPLET"
>> +    echo "Using VLC root dir $VLC_ROOT_DIR, build triplet
>> $LOCAL_BUILD_TRIPLET and host triplet $(vlcGetHostTriplet)"
>> 
>> +    export AR="$(xcrun --find ar)"
>>     export CC="$(xcrun --find clang)"
>>     export CXX="$(xcrun --find clang++)"
>> +    export NM="$(xcrun --find nm)"
>>     export OBJC="$(xcrun --find clang)"
>>     export OBJCXX="$(xcrun --find clang++)"
>> -    export AR="$(xcrun --find ar)"
>>     export RANLIB="$(xcrun --find ranlib)"
>> -    export NM="$(xcrun --find nm)"
>> +    export STRINGS="`xcrun --find strings`"
>> +    export STRIP="`xcrun --find strip`"
> 
> Looks like a different problem being fixed?

Squashed from a separate patch on the 3.0 branch. I’ll check whether it’s actually needed at all in the first place.


> 
>> 
>>     python3Path=$(echo
>> /Library/Frameworks/Python.framework/Versions/3.*/bin | awk '{print $1;}')
>> if [ ! -d "$python3Path" ]; then
>>         python3Path=""
>>     fi
>> 
>> -    export
>> PATH="${VLC_ROOT_DIR}/extras/tools/build/bin:${VLC_ROOT_DIR}/contrib/${LOCA
>> L_TRIPLET}/bin:$python3Path:${VLC_PATH}:/bin:/sbin:/usr/bin:/usr/sbin" +   
>> export
>> PATH="${VLC_ROOT_DIR}/extras/tools/build/bin:${VLC_ROOT_DIR}/contrib/${LOCA
>> L_BUILD_TRIPLET}/bin:$python3Path:${VLC_PATH}:/bin:/sbin:/usr/bin:/usr/sbin"
>> }
>> 
>> vlcSetSymbolEnvironment() {
>> @@ -110,13 +136,13 @@ vlcSetContribEnvironment() {
>>     export CXXFLAGS="-Werror=partial-availability"
>>     export OBJCFLAGS="-Werror=partial-availability"
>> 
>> -    export EXTRA_CFLAGS="-isysroot $SDKROOT
>> -mmacosx-version-min=$MINIMAL_OSX_VERSION
>> -DMACOSX_DEPLOYMENT_TARGET=$MINIMAL_OSX_VERSION" -    export
>> EXTRA_LDFLAGS="-isysroot $SDKROOT -mmacosx-version-min=$MINIMAL_OSX_VERSION
>> -DMACOSX_DEPLOYMENT_TARGET=$MINIMAL_OSX_VERSION" +    export
>> EXTRA_CFLAGS="-isysroot $SDKROOT -mmacosx-version-min=$MINIMAL_OSX_VERSION
>> -DMACOSX_DEPLOYMENT_TARGET=$MINIMAL_OSX_VERSION -arch $ACTUAL_ARCH" +   
>> export EXTRA_LDFLAGS="-isysroot $SDKROOT
>> -mmacosx-version-min=$MINIMAL_OSX_VERSION
>> -DMACOSX_DEPLOYMENT_TARGET=$MINIMAL_OSX_VERSION -arch $ACTUAL_ARCH" export
>> XCODE_FLAGS="MACOSX_DEPLOYMENT_TARGET=$MINIMAL_OSX_VERSION -sdk $SDKROOT
>> WARNING_CFLAGS=-Werror=partial-availability" }
>> 
>> vlcUnsetContribEnvironment() {
>> -    echo "Unsetting contrib flags, prepare VLC flags"
>> +    echo "Unsetting contrib flags"
>> 
>>     unset CFLAGS
>>     unset CXXFLAGS
>> @@ -125,13 +151,26 @@ vlcUnsetContribEnvironment() {
>>     unset EXTRA_CFLAGS
>>     unset EXTRA_LDFLAGS
>>     unset XCODE_FLAGS
>> +}
>> +
>> +vlcSetLibVLCEnvironment() {
>> +    echo "Setting libVLC flags"
>> 
>>     # Enable debug symbols by default
>> -    export CFLAGS="-g"
>> -    export CXXFLAGS="-g"
>> -    export OBJCFLAGS="-g"
>> +    export CFLAGS="-g -arch $ACTUAL_ARCH"
>> +    export CXXFLAGS="-g -arch $ACTUAL_ARCH"
>> +    export OBJCFLAGS="-g -arch $ACTUAL_ARCH"
>> +    export LDFLAGS="-arch $ACTUAL_ARCH"
>> }
>> 
>> +vlcUnsetLibVLCEnvironment() {
>> +    echo "Unsetting libVLC flags"
>> +
>> +    unset CFLAGS
>> +    unset CXXFLAGS
>> +    unset OBJCFLAGS
>> +    unset LDFLAGS
>> +}
>> 
>> # Parameter handling
>> 
>> @@ -151,9 +190,11 @@ fi
>> if [ "$VLC_ENV_MODE" = "contrib" ]; then
>>     vlcSetBaseEnvironment
>>     vlcSetSymbolEnvironment
>> +    vlcUnsetLibVLCEnvironment
>>     vlcSetContribEnvironment "$MINIMAL_OSX_VERSION"
>> elif [ "$VLC_ENV_MODE" = "vlc" ]; then
>>     vlcSetBaseEnvironment
>>     vlcSetSymbolEnvironment
>>     vlcUnsetContribEnvironment
>> +    vlcSetLibVLCEnvironment
>> fi

Best regards,

Felix



More information about the vlc-devel mailing list