Skip to content

Commit

Permalink
macOS support for universal/aarch64/10.11 (#155)
Browse files Browse the repository at this point in the history
* Support macOS 10.11

* Support download precompiled dependencies

* Add sanitizer to cmake
  • Loading branch information
xfangfang authored Jun 27, 2023
1 parent 6675f80 commit c65f833
Show file tree
Hide file tree
Showing 13 changed files with 221 additions and 90 deletions.
90 changes: 36 additions & 54 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ jobs:
DIST_EXE: ${{ steps.info.outputs.DIST_EXE }}
DIST_UWP: ${{ steps.info.outputs.DIST_UWP }}
DIST_NRO: ${{ steps.info.outputs.DIST_NRO }}
DIST_DMG_PREFIX: ${{ steps.info.outputs.DIST_DMG_PREFIX }}
DIST_INTEL_DMG: ${{ steps.info.outputs.DIST_INTEL_DMG }}
DIST_ARM_DMG: ${{ steps.info.outputs.DIST_ARM_DMG }}
DIST_UNIVERSAL_DMG: ${{ steps.info.outputs.DIST_UNIVERSAL_DMG }}
DIST_FLATPAK_X86_64: ${{ steps.info.outputs.DIST_FLATPAK_X86_64 }}
DIST_FLATPAK_AARCH64: ${{ steps.info.outputs.DIST_FLATPAK_AARCH64 }}
steps:
Expand Down Expand Up @@ -63,15 +66,18 @@ jobs:
echo "DIST_EXE=wiliwili-Windows-x64-${VERSION}" >> $GITHUB_OUTPUT
echo "DIST_UWP=wiliwili-windows-x64-uwp-${VERSION}" >> $GITHUB_OUTPUT
echo "DIST_NRO=wiliwili-NintendoSwitch-${VERSION}" >> $GITHUB_OUTPUT
echo "DIST_DMG_PREFIX=wiliwili-macOS" >> $GITHUB_OUTPUT
echo "DIST_INTEL_DMG=wiliwili-macOS-IntelChip-${VERSION}" >> $GITHUB_OUTPUT
echo "DIST_ARM_DMG=wiliwili-macOS-AppleSilicon-${VERSION}" >> $GITHUB_OUTPUT
echo "DIST_UNIVERSAL_DMG=wiliwili-macOS-Universal-${VERSION}" >> $GITHUB_OUTPUT
echo "DIST_FLATPAK_X86_64=wiliwili-Linux-${VERSION}-x86_64" >> $GITHUB_OUTPUT
echo "DIST_FLATPAK_AARCH64=wiliwili-Linux-${VERSION}-aarch64" >> $GITHUB_OUTPUT
echo $VERSION
echo "${{ github.event.inputs.version }}"
release:
needs: [ build-win-x64, build-switch, build-macos-intel, build-flatpak, version ]
needs: [ build-win-x64, build-switch, build-macos, build-flatpak, version ]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
Expand All @@ -95,35 +101,10 @@ jobs:
${{ needs.version.outputs.DIST_EXE }}/${{ needs.version.outputs.DIST_EXE }}.tar.gz
${{ needs.version.outputs.DIST_NRO }}/${{ needs.version.outputs.DIST_NRO }}.tar.gz
${{ needs.version.outputs.DIST_INTEL_DMG }}/${{ needs.version.outputs.DIST_INTEL_DMG }}.dmg
${{ needs.version.outputs.DIST_ARM_DMG }}/${{ needs.version.outputs.DIST_ARM_DMG }}.dmg
${{ needs.version.outputs.DIST_UNIVERSAL_DMG }}/${{ needs.version.outputs.DIST_UNIVERSAL_DMG }}.dmg
${{ needs.version.outputs.DIST_FLATPAK_X86_64 }}/${{ needs.version.outputs.DIST_FLATPAK_X86_64 }}.flatpak
## WeTransfer 暂时不可用,可以使用 CatBox 代替,但是后者貌似是非盈利组织维护的,所以还是不要滥用了,先注释掉
# - name: Upload WeTransfer
# if: github.event.inputs.release != 'true' && !cancelled()
# continue-on-error: true
# run: |
# tree
# curl -fsSL git.io/file-transfer | sh
# ./transfer wet -s -p 16 --no-progress \
# ${{ needs.version.outputs.DIST_EXE }}/${{ needs.version.outputs.DIST_EXE }}.tar.gz \
# ${{ needs.version.outputs.DIST_NRO }}/${{ needs.version.outputs.DIST_NRO }}.tar.gz \
# ${{ needs.version.outputs.DIST_INTEL_DMG }}/${{ needs.version.outputs.DIST_INTEL_DMG }}.dmg \
# ${{ needs.version.outputs.DIST_FLATPAK_X86_64 }}/${{ needs.version.outputs.DIST_FLATPAK_X86_64 }}.flatpak 2>&1 | tee transfer.log
# echo "::warning title=访问下方链接免登录下载测试版 (有效期至:`date -u +"%FT%TZ" -d "7day"`)::$(cat transfer.log | grep https | cut -f3 -d" ")"
#
# - name: Upload CatBox
# if: github.event.inputs.release != 'true' && !cancelled()
# continue-on-error: true
# run: |
# tree
# curl -fsSL git.io/file-transfer | sh
# ./transfer wet -s -p 16 --no-progress \
# ${{ needs.version.outputs.DIST_EXE }}/${{ needs.version.outputs.DIST_EXE }}.tar.gz \
# ${{ needs.version.outputs.DIST_NRO }}/${{ needs.version.outputs.DIST_NRO }}.tar.gz \
# ${{ needs.version.outputs.DIST_INTEL_DMG }}/${{ needs.version.outputs.DIST_INTEL_DMG }}.dmg \
# ${{ needs.version.outputs.DIST_FLATPAK_X86_64 }}/${{ needs.version.outputs.DIST_FLATPAK_X86_64 }}.flatpak 2>&1 | tee transfer.log
# echo "::warning title=访问下方链接免登录下载测试版::$(cat transfer.log)"

build-win-x64:
needs: [ version ]
runs-on: windows-2022
Expand Down Expand Up @@ -168,11 +149,9 @@ jobs:
7z e mpv.7z -ompv
cp mpv/mpv-2.dll wiliwili/libmpv-2.dll
tar -czvf ../${{ needs.version.outputs.DIST_EXE }}.tar.gz wiliwili
echo "status=success" >> $GITHUB_OUTPUT
- name: Upload dist
uses: actions/upload-artifact@v3
if: steps.compile.outputs.status == 'success'
with:
name: ${{ needs.version.outputs.DIST_EXE }}
path: "${{ needs.version.outputs.DIST_EXE }}.tar.gz"
Expand Down Expand Up @@ -239,18 +218,21 @@ jobs:
docker run --rm -v $(pwd):/data devkitpro/devkita64:20230622 sh -c "/data/scripts/build_switch.sh"
cd cmake-build-switch
tar -czvf ../${{ needs.version.outputs.DIST_NRO }}.tar.gz wiliwili.nro
echo "status=success" >> $GITHUB_OUTPUT
- name: Upload dist
uses: actions/upload-artifact@v3
if: steps.compile.outputs.status == 'success'
with:
name: ${{ needs.version.outputs.DIST_NRO }}
path: "${{ needs.version.outputs.DIST_NRO }}.tar.gz"

build-macos-intel:
build-macos:
needs: [ version ]
runs-on: macos-11
strategy:
matrix:
arch: [ IntelChip, AppleSilicon, Universal ]
# Don't fail the whole workflow if one architecture fails
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -261,51 +243,51 @@ jobs:

- name: install deps
run: |
brew install create-dmg dylibbundler webp
brew install create-dmg dylibbundler webp boost
brew tap xfangfang/wiliwili
brew install -v mpv-wiliwili
- name: Readme
run: |
mkdir -p dist
echo "wiliwili" > dist/readme.txt
echo "" >> dist/readme.txt
echo "if you see any of these after open this application:" >> dist/readme.txt
echo "1: wiliwili.app is damaged and can't be opened. You should move it to he Trash." >> dist/readme.txt
echo "2: wiliwili.app can't be opened because it is from an unidentified developer." >> dist/readme.txt
echo "" >> dist/readme.txt
echo "Please run this command in your terminal:" >> dist/readme.txt
echo "sudo xattr -rd com.apple.quarantine /Applications/wiliwili.app" >> dist/readme.txt
- name: SSH connection to Actions
uses: P3TERX/ssh2actions@v1.0.0
if: (github.event.inputs.ssh_darwin == 'true' && github.event.inputs.ssh_darwin != 'false') || contains(github.event.action, 'ssh_darwin')
env:
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}

- name: Build
id: compile
- name: Update gamepad mappings
id: gamepad
run: |
BRLS_GLFW="library/borealis/library/lib/extern/glfw/"
cmake -P ${BRLS_GLFW}/CMake/GenerateMappings.cmake ${BRLS_GLFW}/src/mappings.h.in ${BRLS_GLFW}/src/mappings.h
cmake -B build -DPLATFORM_DESKTOP=ON -DCMAKE_BUILD_TYPE=Release
- name: Build
id: compile
run: |
cmake -B build -DPLATFORM_DESKTOP=ON -DCMAKE_BUILD_TYPE=Release -DMAC_${{ matrix.arch }}=ON -DMAC_DOWNLOAD_DYLIB=ON
make -C build wiliwili.app -j$(sysctl -n hw.ncpu)
- name: Name
id: name
run: |
echo "DMG=${{ needs.version.outputs.DIST_DMG_PREFIX }}-${{ matrix.arch }}-${{ needs.version.outputs.version }}" >> $GITHUB_OUTPUT
- name: Bundle
id: bundle
run: |
mkdir -p dist
mv build/wiliwili.app dist/
cp ./scripts/mac/readme.txt dist/readme.txt
create-dmg --window-pos 200 120 --window-size 800 400 \
--icon-size 100 --icon "wiliwili.app" 200 190 \
--icon "readme.txt" 400 100 --hide-extension "wiliwili.app" \
--app-drop-link 600 185 --volicon ./scripts/mac/dmg.icns \
--volname "wiliwili (${{ needs.version.outputs.version }})" ${{ needs.version.outputs.DIST_INTEL_DMG }}.dmg "dist/"
echo "status=success" >> $GITHUB_OUTPUT
--volname "wiliwili (${{ needs.version.outputs.version }})" ${{ steps.name.outputs.DMG }}.dmg "dist/"
- name: Upload dist
uses: actions/upload-artifact@v3
if: steps.compile.outputs.status == 'success'
with:
name: ${{ needs.version.outputs.DIST_INTEL_DMG }}
path: "${{ needs.version.outputs.DIST_INTEL_DMG }}.dmg"
name: ${{ steps.name.outputs.DMG }}
path: "${{ steps.name.outputs.DMG }}.dmg"

build-flatpak:
needs: [ version ]
Expand Down
58 changes: 30 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(PLATFORM_DESKTOP
)
set(BUILTIN_NSP
OFF
CACHE BOOL "Built in NSP forwarder"
CACHE BOOL "Built in NSP forwarder (only for NintendoSwitch)"
)
set(WIN32_TERMINAL
ON
Expand All @@ -25,6 +25,10 @@ set(USE_SHARED_LIB
OFF
CACHE BOOL "Whether to use shared libs provided by system"
)
set(DEBUG_SANITIZER
OFF
CACHE BOOL "Turn on sanitizers (only available in debug build)"
)

# analytics
set(ANALYTICS
Expand All @@ -40,15 +44,24 @@ set(ANALYTICS_KEY
CACHE STRING "Google Analytics key"
)

# Strongly depends on the environment, these options may lead to build errors
set(MAC_10_15
# These four options are only for macOS app bundling usage.
# Do not use it until you know what you are doing.
set(MAC_IntelChip
OFF
CACHE BOOL "Set the Minimum OS X deployment version to 10.11 (x86_64)"
)
set(MAC_AppleSilicon
OFF
CACHE BOOL "Set the Minimum OS X deployment version to 10.15"
CACHE BOOL "Set the Minimum OS X deployment version to 11.0 (aarch64)"
)
set(MAC_UNIVERSAL
set(MAC_Universal
OFF
CACHE BOOL "Support x86_64;arm64 at the same time"
)
set(MAC_DOWNLOAD_DYLIB
OFF
CACHE BOOL "Using precompiled dylib instead of system provided"
)

# mpv related
set(MPV_SW_RENDER
Expand Down Expand Up @@ -86,12 +99,12 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/extra.cmake)

# toolchain
if (PLATFORM_DESKTOP)
message("building for Desktop")
message(STATUS "building for Desktop")
set(TARGET_PLATFORM
desktop
CACHE STRING ""
)
message("Build Type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -g2 -ggdb -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
if (USE_SHARED_LIB)
Expand All @@ -100,9 +113,9 @@ if (PLATFORM_DESKTOP)
set(USE_SYSTEM_CURL ON)
endif ()
else ()
message("building for SWITCH")
message("Build Type: ${CMAKE_BUILD_TYPE}")
message("DEVKITPRO: $ENV{DEVKITPRO}")
message(STATUS "building for SWITCH")
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
message(STATUS "DEVKITPRO: $ENV{DEVKITPRO}")
set(CMAKE_USE_SYSTEM_ENVIRONMENT_PATH OFF)
file(TO_CMAKE_PATH "$ENV{DEVKITPRO}" DEVKITPRO)
if (NOT IS_DIRECTORY ${DEVKITPRO})
Expand Down Expand Up @@ -268,6 +281,9 @@ else ()
add_executable(${PROJECT_NAME} ${MAIN_SRC})
endif ()

# download macos dylib dependencies
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/macos.cmake)

# set google analytics
if (ANALYTICS)
if (NOT ANALYTICS_ID OR NOT ANALYTICS_KEY)
Expand Down Expand Up @@ -325,27 +341,13 @@ if (PLATFORM_DESKTOP)
add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}.data)

if (APPLE)
if (MAC_10_15)
message(STATUS "CMAKE_OSX_DEPLOYMENT_TARGET: 10.15")
set(CMAKE_OSX_DEPLOYMENT_TARGET
"10.15"
CACHE STRING "Minimum OS X deployment version" FORCE
)
endif ()
if (MAC_UNIVERSAL)
message(STATUS "CMAKE_OSX_ARCHITECTURES: x86_64;arm64")
set(CMAKE_OSX_ARCHITECTURES
"x86_64;arm64"
CACHE STRING "Architectures" FORCE
)
set(CMAKE_XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET[arch=arm64]
"11.0"
CACHE STRING "arm 64 minimum deployment target" FORCE
)
if (MAC_DOWNLOAD_DYLIB)
set(bundle_args1 "-nb")
set(bundle_args2 "${CMAKE_BINARY_DIR}/deps/${MAC_OS_ARCH}")
endif ()
add_custom_target(
${PROJECT_NAME}.app
COMMAND "bash" "${CMAKE_BINARY_DIR}/../scripts/build_mac.sh"
COMMAND "bash" "${CMAKE_BINARY_DIR}/../scripts/build_mac.sh" "${bundle_args1}" "${bundle_args2}"
)
add_dependencies(${PROJECT_NAME}.app ${PROJECT_NAME})
elseif (UNIX)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ wiliwili 拥有非常接近官方PC客户端的B站浏览体验
无论是电脑还是游戏掌机都能获得全新的使用体验
<br>

[![GitHub release (latest by date)](https://img.shields.io/github/v/release/xfangfang/wiliwili)](https://github.com/xfangfang/wiliwili/releases) ![GitHub All Releases](https://img.shields.io/github/downloads/xfangfang/wiliwili/total) ![GitHub stars](https://img.shields.io/github/stars/xfangfang/wiliwili?style=flat) ![GitHub forks](https://img.shields.io/github/forks/xfangfang/wiliwili) [![Crowdin](https://badges.crowdin.net/wiliwili/localized.svg)](https://crowdin.com/project/wiliwili) ![NS](https://img.shields.io/badge/-Nintendo%20Switch-e4000f?style=flat&logo=Nintendo%20Switch) ![MS](https://img.shields.io/badge/-Windows%207-357ec7?style=flat&logo=Windows) ![mac](https://img.shields.io/badge/-macOS%2010.15-black?style=flat&logo=Apple) ![Linux](https://img.shields.io/badge/-Linux-lightgrey?style=flat&logo=Linux)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/xfangfang/wiliwili)](https://github.com/xfangfang/wiliwili/releases) ![GitHub All Releases](https://img.shields.io/github/downloads/xfangfang/wiliwili/total) ![GitHub stars](https://img.shields.io/github/stars/xfangfang/wiliwili?style=flat) ![GitHub forks](https://img.shields.io/github/forks/xfangfang/wiliwili) [![Crowdin](https://badges.crowdin.net/wiliwili/localized.svg)](https://crowdin.com/project/wiliwili) ![NS](https://img.shields.io/badge/-Nintendo%20Switch-e4000f?style=flat&logo=Nintendo%20Switch) ![MS](https://img.shields.io/badge/-Windows%207-357ec7?style=flat&logo=Windows) ![mac](https://img.shields.io/badge/-macOS%2010.11-black?style=flat&logo=Apple) ![Linux](https://img.shields.io/badge/-Linux-lightgrey?style=flat&logo=Linux)

<br>

Expand Down
41 changes: 39 additions & 2 deletions cmake/extra.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ cmake_minimum_required(VERSION 3.15)
IF (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
message("Build Type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")
ENDIF ()

if (CMAKE_BUILD_TYPE STREQUAL Debug)
add_definitions(-D_DEBUG)
add_definitions(-D_GLIBCXX_ASSERTIONS)
if (DEBUG_SANITIZER)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -O0 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined,address")
endif ()
endif ()

# Add git info
Expand All @@ -27,4 +32,36 @@ execute_process(COMMAND git rev-parse --short HEAD
add_definitions(-DBUILD_TAG_VERSION=${GIT_TAG_VERSION} -DBUILD_TAG_SHORT=${GIT_TAG_SHORT})

message(STATUS "building from git tag ${GIT_TAG_VERSION}")
message(STATUS "building from git commit ${GIT_TAG_SHORT}")
message(STATUS "building from git commit ${GIT_TAG_SHORT}")

if (APPLE)
if (MAC_IntelChip)
message(STATUS "CMAKE_OSX_ARCHITECTURES: x86_64")
message(STATUS "CMAKE_OSX_DEPLOYMENT_TARGET: 10.11")
set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "" FORCE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "" FORCE)

set(CPR_USE_BOOST_FILESYSTEM ON)
set(USE_BOOST_FILESYSTEM ON)
add_definitions(-DCPR_USE_BOOST_FILESYSTEM)
add_definitions(-DUSE_BOOST_FILESYSTEM)
endif ()
if(MAC_AppleSilicon)
# Build a Universal binary on macOS
message(STATUS "CMAKE_OSX_ARCHITECTURES: arm64")
set(CMAKE_OSX_ARCHITECTURES "arm64" CACHE STRING "" FORCE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "" FORCE)
endif()
if(MAC_Universal)
# Build a Universal binary on macOS
message(STATUS "CMAKE_OSX_ARCHITECTURES: x86_64;arm64")
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "" FORCE)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "" FORCE)
set(CMAKE_XCODE_ATTRIBUTE_MACOSX_DEPLOYMENT_TARGET[arch=arm64] "11.0" CACHE STRING "" FORCE)

set(CPR_USE_BOOST_FILESYSTEM ON)
set(USE_BOOST_FILESYSTEM ON)
add_definitions(-DCPR_USE_BOOST_FILESYSTEM)
add_definitions(-DUSE_BOOST_FILESYSTEM)
endif()
endif()
Loading

0 comments on commit c65f833

Please sign in to comment.