1
0
mirror of synced 2025-01-18 00:56:49 +01:00

build: Fix macOS M1 build entirely (#1480)

This commit is contained in:
Nik 2023-12-30 19:11:33 +01:00 committed by GitHub
parent 038b98eacf
commit 5a0a5ad445
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 105 additions and 34 deletions

View File

@ -244,9 +244,11 @@ jobs:
name: macOS DMG${{matrix.suffix}} x86_64
path: build/*.dmg
macos-arm64:
macos-arm64-build:
runs-on: ubuntu-22.04
name: 🍎 macOS 12.1 arm64
outputs:
IMHEX_VERSION: ${{ steps.build.outputs.IMHEX_VERSION }}
steps:
- name: 🧰 Checkout
uses: actions/checkout@v3
@ -266,13 +268,15 @@ jobs:
cache-target: /cache
- name: 🛠️ Build using docker
id: build
run: |
echo "IMHEX_VERSION=`cat VERSION`" >> $GITHUB_OUTPUT
docker buildx build . -f dist/macOS/arm64.Dockerfile --progress=plain --build-arg 'JOBS=4' --build-arg "BUILD_TYPE=$(BUILD_TYPE)" --build-context imhex=$(pwd) --output out
- name: ⬆️ Upload artifacts
uses: actions/upload-artifact@v4
with:
name: macOS ZIP arm64
name: macos_arm64_intermediate
path: out/
# See https://github.com/actions/cache/issues/342#issuecomment-1711054115
@ -284,6 +288,55 @@ jobs:
gh extension install actions/gh-actions-cache
gh actions-cache delete "build-macos-arm64-cache" --confirm || true
macos-arm64-package:
runs-on: macos-12
name: 🍎 macOS 12.1 arm64 Packaging
needs: macos-arm64-build
env:
IMHEX_VERSION: ${{ needs.macos-arm64-build.outputs.IMHEX_VERSION }}
steps:
- name: ⬇️ Download artifact
uses: actions/download-artifact@v4
with:
name: macos_arm64_intermediate
path: out
- name: 🗑️ Delete artifact
uses: geekyeggo/delete-artifact@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: macos_arm64_intermediate
- name: ✒️ Fix Signature
run: |
set -x
cd out
codesign --remove-signature ImHex.app
codesign --force --deep --sign - ImHex.app
- name: 📁 Fix permissions
run: |
set -x
cd out
chmod -R 755 ImHex.app/
- name: 📦 Create DMG
run: |
set -x
mkdir bundle
mv out/ImHex.app bundle
cd bundle
ln -s /Applications Applications
cd ..
hdiutil create -volname "ImHex" -srcfolder bundle -ov -format UDZO imhex-${{env.IMHEX_VERSION}}-macOS-arm64.dmg
- name: ⬆️ Upload DMG
uses: actions/upload-artifact@v4
with:
if-no-files-found: error
name: macOS DMG arm64
path: ./*.dmg
# Ubuntu build
ubuntu:
strategy:

View File

@ -111,8 +111,9 @@ macro(configurePackingResources)
)
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/resources/dist/windows/LICENSE.rtf")
endif()
elseif (APPLE)
elseif (APPLE OR ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
set(IMHEX_ICON "${IMHEX_BASE_FOLDER}/resources/dist/macos/AppIcon.icns")
set(BUNDLE_NAME "imhex.app")
if (IMHEX_GENERATE_PACKAGE)
set(APPLICATION_TYPE MACOSX_BUNDLE)
@ -129,9 +130,9 @@ macro(configurePackingResources)
string(TIMESTAMP CURR_YEAR "%Y")
set(MACOSX_BUNDLE_COPYRIGHT "Copyright © 2020 - ${CURR_YEAR} WerWolv. All rights reserved." )
if ("${CMAKE_GENERATOR}" STREQUAL "Xcode")
set (IMHEX_BUNDLE_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/imhex.app")
set (IMHEX_BUNDLE_PATH "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${BUNDLE_NAME}")
else ()
set (IMHEX_BUNDLE_PATH "${CMAKE_BINARY_DIR}/imhex.app")
set (IMHEX_BUNDLE_PATH "${CMAKE_BINARY_DIR}/${BUNDLE_NAME}")
endif()
set(PLUGINS_INSTALL_LOCATION "${IMHEX_BUNDLE_PATH}/Contents/MacOS/plugins")
@ -235,7 +236,8 @@ macro(createPackage)
endif()
if (IMHEX_GENERATE_PACKAGE AND APPLE)
if (APPLE)
if (IMHEX_GENERATE_PACKAGE)
include(PostprocessBundle)
set_target_properties(libimhex PROPERTIES SOVERSION ${IMHEX_VERSION})
@ -253,9 +255,6 @@ macro(createPackage)
install(FILES ${IMHEX_ICON} DESTINATION "${IMHEX_BUNDLE_PATH}/Contents/Resources")
install(TARGETS main BUNDLE DESTINATION ".")
install(TARGETS updater BUNDLE DESTINATION ".")
install(FILES $<TARGET_FILE:main> DESTINATION "${IMHEX_BUNDLE_PATH}")
install(FILES $<TARGET_FILE:updater> DESTINATION "${IMHEX_BUNDLE_PATH}")
# Update library references to make the bundle portable
postprocess_bundle(imhex_all main)
@ -264,7 +263,14 @@ macro(createPackage)
set(CPACK_GENERATOR "DragNDrop")
set(CPACK_BUNDLE_ICON "${CMAKE_SOURCE_DIR}/resources/dist/macos/AppIcon.icns")
set(CPACK_BUNDLE_PLIST "${CMAKE_BINARY_DIR}/imhex.app/Contents/Info.plist")
set(CPACK_BUNDLE_PLIST "${CMAKE_BINARY_DIR}/${BUNDLE_NAME}/Contents/Info.plist")
endif()
# Sign the bundle
find_program(CODESIGN_PATH codesign)
if (CODESIGN_PATH)
add_custom_command(TARGET imhex_all POST_BUILD COMMAND ${CODESIGN_PATH} --force --deep --sign - ${CMAKE_BINARY_DIR}/${BUNDLE_NAME})
endif()
else()
install(TARGETS main RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
if (TARGET updater)
@ -703,7 +709,7 @@ function(generateSDKDirectory)
if (WIN32)
set(SDK_PATH "./sdk")
elseif (APPLE)
set(SDK_PATH "imhex.app/Contents/Resources/sdk")
set(SDK_PATH "${BUNDLE_NAME}/Contents/Resources/sdk")
else()
set(SDK_PATH "share/imhex/sdk")
endif()

View File

@ -149,6 +149,7 @@ RUN --mount=type=cache,target=/cache --mount=type=cache,target=/mnt/ImHex/build/
-DIMHEX_GENERATE_PACKAGE=ON -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
`# other flags` \
-DIMHEX_STRICT_WARNINGS=OFF \
-DCMAKE_INSTALL_PREFIX=/mnt/ImHex/build/install \
-B build
## Build ImHex
RUN --mount=type=cache,target=/cache --mount=type=cache,target=/mnt/ImHex/build/_deps <<EOF
@ -156,11 +157,11 @@ RUN --mount=type=cache,target=/cache --mount=type=cache,target=/mnt/ImHex/build/
set -xe
cd /mnt/ImHex
cmake --build build --parallel $JOBS
cmake --build build --parallel $JOBS --target install
ccache -s
EOF
FROM scratch
COPY --from=build /mnt/ImHex/build/imhex.app imhex.app
COPY --from=build /mnt/ImHex/build/install/imhex.app ImHex.app

View File

@ -32,6 +32,10 @@
hex::log::info("Library plugin '{}' initialized successfully", WOLV_STRINGIFY(IMHEX_PLUGIN_NAME)); \
return 0; \
}(); \
IMHEX_PLUGIN_VISIBILITY_PREFIX void setImGuiContext(ImGuiContext *ctx) { \
ImGui::SetCurrentContext(ctx); \
GImGui = ctx; \
} \
extern "C" [[gnu::visibility("default")]] void WOLV_TOKEN_CONCAT(forceLinkPlugin_, IMHEX_PLUGIN_NAME)() { \
hex::PluginManager::addPlugin(hex::PluginFunctions { \
nullptr, \
@ -40,7 +44,7 @@
nullptr, \
nullptr, \
nullptr, \
nullptr, \
setImGuiContext, \
nullptr, \
nullptr \
}); \

View File

@ -1,14 +1,21 @@
project(updater)
add_executable(updater ${APPLICATION_TYPE}
add_executable(updater
source/main.cpp
)
add_compile_definitions(IMHEX_PROJECT_NAME="${PROJECT_NAME}")
target_link_libraries(updater PRIVATE libimhex wolv::io ${FMT_LIBRARIES})
add_dependencies(imhex_all updater)
add_dependencies(main updater)
if (APPLE)
set(OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${BUNDLE_NAME}/Contents/MacOS")
else ()
set(OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
endif()
set_target_properties(updater PROPERTIES
OUTPUT_NAME "imhex-updater"
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../..
RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIRECTORY}
POSITION_INDEPENDENT_CODE ON
)