From 42c4441d054e05f7aec1a0c7ea9a73c3318cbcdb Mon Sep 17 00:00:00 2001 From: Lukhnos Liu Date: Wed, 19 Jan 2022 08:53:04 -0800 Subject: [PATCH] Introduce a Swift class to the Installer This is so that the Installer will be built with the correct Swift settings, especially those that instruct the Xcode to package the Swift runtime libraries. This is needed because the Installer now depends on InputSourceHelper, which is written in Swift. Without this, the app would not be packaged with the Swift runtime libraries, which caused the installer to be unusable on older but supported macOS versions. --- McBopomofo.xcodeproj/project.pbxproj | 22 +++++++++++++ Source/Installer/InstallerUtil.swift | 32 +++++++++++++++++++ .../McBopomofoInstaller-Bridging-Header.h | 4 +++ 3 files changed, 58 insertions(+) create mode 100644 Source/Installer/InstallerUtil.swift create mode 100644 Source/Installer/McBopomofoInstaller-Bridging-Header.h diff --git a/McBopomofo.xcodeproj/project.pbxproj b/McBopomofo.xcodeproj/project.pbxproj index dfa7dc8b..8293c7f4 100644 --- a/McBopomofo.xcodeproj/project.pbxproj +++ b/McBopomofo.xcodeproj/project.pbxproj @@ -27,6 +27,7 @@ 6A6ED16C2797650A0012872E /* template-data.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A6ED1652797650A0012872E /* template-data.txt */; }; 6A6ED16D2797650A0012872E /* template-exclude-phrases-plain-bpmf.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A6ED1672797650A0012872E /* template-exclude-phrases-plain-bpmf.txt */; }; 6A6ED16E2797650A0012872E /* template-exclude-phrases.txt in Resources */ = {isa = PBXBuildFile; fileRef = 6A6ED1692797650A0012872E /* template-exclude-phrases.txt */; }; + 6A93050E2798780000D370DA /* InstallerUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6A93050D2798780000D370DA /* InstallerUtil.swift */; }; 6ACA41CD15FC1D7500935EF6 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A0D4EA615FC0D2D00ABF4B3 /* Cocoa.framework */; }; 6ACA41F915FC1D9000935EF6 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ACA41E915FC1D9000935EF6 /* AppDelegate.m */; }; 6ACA41FA15FC1D9000935EF6 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6ACA41EA15FC1D9000935EF6 /* InfoPlist.strings */; }; @@ -167,6 +168,8 @@ 6A6ED170279765140012872E /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text; name = "zh-Hant"; path = "zh-Hant.lproj/template-exclude-phrases-plain-bpmf.txt"; sourceTree = ""; }; 6A6ED171279765170012872E /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text; name = "zh-Hant"; path = "zh-Hant.lproj/template-exclude-phrases.txt"; sourceTree = ""; }; 6A6ED1722797651A0012872E /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text; name = "zh-Hant"; path = "zh-Hant.lproj/template-phrases-replacement.txt"; sourceTree = ""; }; + 6A93050C279877FF00D370DA /* McBopomofoInstaller-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "McBopomofoInstaller-Bridging-Header.h"; sourceTree = ""; }; + 6A93050D2798780000D370DA /* InstallerUtil.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = InstallerUtil.swift; path = InstallerUtil.swift; sourceTree = ""; }; 6ACA41CB15FC1D7500935EF6 /* McBopomofoInstaller.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = McBopomofoInstaller.app; sourceTree = BUILT_PRODUCTS_DIR; }; 6ACA41E815FC1D9000935EF6 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = Source/Installer/AppDelegate.h; sourceTree = SOURCE_ROOT; }; 6ACA41E915FC1D9000935EF6 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = Source/Installer/AppDelegate.m; sourceTree = SOURCE_ROOT; }; @@ -447,6 +450,7 @@ 6ACA41E715FC1D9000935EF6 /* Installer */ = { isa = PBXGroup; children = ( + 6A93050D2798780000D370DA /* InstallerUtil.swift */, 6A225A212367A1D700F685C6 /* ArchiveUtil.h */, 6A225A222367A1D700F685C6 /* ArchiveUtil.m */, 6A225A1E23679F2600F685C6 /* NotarizedArchives */, @@ -459,6 +463,7 @@ 6ACA41F215FC1D9000935EF6 /* Installer-Info.plist */, 6ACA41F315FC1D9000935EF6 /* Installer-Prefix.pch */, 6ACA41F415FC1D9000935EF6 /* main.m */, + 6A93050C279877FF00D370DA /* McBopomofoInstaller-Bridging-Header.h */, ); path = Installer; sourceTree = ""; @@ -583,6 +588,9 @@ 6A0D4EA115FC0D2D00ABF4B3 = { LastSwiftMigration = 1240; }; + 6ACA41CA15FC1D7500935EF6 = { + LastSwiftMigration = 1320; + }; D485D3B52796A8A000657FF3 = { CreatedOnToolsVersion = 13.2.1; TestTargetID = 6A0D4EA115FC0D2D00ABF4B3; @@ -710,6 +718,7 @@ files = ( 6ACA41F915FC1D9000935EF6 /* AppDelegate.m in Sources */, 6A225A232367A1D700F685C6 /* ArchiveUtil.m in Sources */, + 6A93050E2798780000D370DA /* InstallerUtil.swift in Sources */, 6ACA41FF15FC1D9000935EF6 /* main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1118,6 +1127,7 @@ ALWAYS_SEARCH_USER_PATHS = NO; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_CXX_LANGUAGE_STANDARD = "c++17"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -1142,11 +1152,17 @@ GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ../; INFOPLIST_FILE = "Source/Installer/Installer-Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = "org.openvanilla.McBopomofo.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_OBJC_BRIDGING_HEADER = "Source/Installer/McBopomofoInstaller-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; WRAPPER_EXTENSION = app; }; @@ -1158,6 +1174,7 @@ ALWAYS_SEARCH_USER_PATHS = NO; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_CXX_LANGUAGE_STANDARD = "c++17"; + CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; CLANG_ENABLE_OBJC_WEAK = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -1176,10 +1193,15 @@ GCC_WARN_UNUSED_VARIABLE = YES; HEADER_SEARCH_PATHS = ../; INFOPLIST_FILE = "Source/Installer/Installer-Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "org.openvanilla.McBopomofo.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_OBJC_BRIDGING_HEADER = "Source/Installer/McBopomofoInstaller-Bridging-Header.h"; SWIFT_VERSION = 5.0; WRAPPER_EXTENSION = app; }; diff --git a/Source/Installer/InstallerUtil.swift b/Source/Installer/InstallerUtil.swift new file mode 100644 index 00000000..861d52a1 --- /dev/null +++ b/Source/Installer/InstallerUtil.swift @@ -0,0 +1,32 @@ +// Copyright (c) 2022 and onwards The McBopomofo Authors. +// +// Permission is hereby granted, free of charge, to any person +// obtaining a copy of this software and associated documentation +// files (the "Software"), to deal in the Software without +// restriction, including without limitation the rights to use, +// copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// OTHER DEALINGS IN THE SOFTWARE. + +import Cocoa +import Carbon + +public class InstallerUtil: NSObject { + @available(*, unavailable) + public override init() { + super.init() + } +} diff --git a/Source/Installer/McBopomofoInstaller-Bridging-Header.h b/Source/Installer/McBopomofoInstaller-Bridging-Header.h new file mode 100644 index 00000000..1b2cb5d6 --- /dev/null +++ b/Source/Installer/McBopomofoInstaller-Bridging-Header.h @@ -0,0 +1,4 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// +