From 02f98ebf5503149e1fb0fbd68c22fb47dcb40601 Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Thu, 19 Aug 2021 23:42:40 +1000 Subject: [PATCH 01/16] SWIFT_VERSION=5.4; BUILD_LIBRARY_FOR_DISTRIBUTION = YES --- CiteprocRsKit/Common.xcconfig | 3 ++- CiteprocRsKit/Link-citeproc-rs.xcconfig | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CiteprocRsKit/Common.xcconfig b/CiteprocRsKit/Common.xcconfig index 3c52a17..687a169 100644 --- a/CiteprocRsKit/Common.xcconfig +++ b/CiteprocRsKit/Common.xcconfig @@ -8,7 +8,8 @@ // Configuration settings file format documentation can be found at: // https://help.apple.com/xcode/#/dev745c5c974 -SWIFT_VERSION = 5.0 +SWIFT_VERSION = 5.4 +BUILD_LIBRARY_FOR_DISTRIBUTION = YES // Makes archive builds in carthage build for all these platforms // If you want e.g. watchos support, then add handling anywhere $PLATFORM_NAME appears in the build script diff --git a/CiteprocRsKit/Link-citeproc-rs.xcconfig b/CiteprocRsKit/Link-citeproc-rs.xcconfig index d9a9595..516284b 100644 --- a/CiteprocRsKit/Link-citeproc-rs.xcconfig +++ b/CiteprocRsKit/Link-citeproc-rs.xcconfig @@ -21,7 +21,7 @@ CLANG_ENABLE_MODULES = YES // Finding citeproc-rs' ffi static library -// Finds a modulemap file at citeproc-rs/bindings/ffi/module.modulemap +// Finds a modulemap file at citeproc-rs/bindings/ffi/modules/swift/module.modulemap SWIFT_INCLUDE_PATHS = citeproc-rs/bindings/ffi/modules/swift // If you're embedding in an objc project, etc, using only headers no modules // HEADER_SEARCH_PATHS = $(inherited) "$(PROJECT_DIR)/citeproc-rs/bindings/ffi/include" From 87d70233cd27ead2b2397a3aef3b42c42bca1076 Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Mon, 30 Aug 2021 15:07:05 +1000 Subject: [PATCH 02/16] less cleanup required for release script --- Scripts/release | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Scripts/release b/Scripts/release index fbb3776..ff90d61 100755 --- a/Scripts/release +++ b/Scripts/release @@ -74,7 +74,7 @@ build() { # `zip -y` is the key here, it preserves the Versions/Current (etc) symlinks inside the frameworks. # These otherwise cause `unzip` to fail and SwiftPM to give you "TSCBasic.StringError error 1". (cd Carthage/Build \ - && rm CiteprocRsKit.xcframework.zip \ + && rm -f CiteprocRsKit.xcframework.zip \ && zip -y -r CiteprocRsKit.xcframework.zip CiteprocRsKit.xcframework) } @@ -155,11 +155,11 @@ fi CHECKSUM=$(checksum) if $IS_DRAFT; then - gh release delete "$RELEASE_TAG" - git push origin ":$TAG" - git tag -d "$TAG" + gh release delete "$RELEASE_TAG" || echo "no draft release to delete; continuing" + git push origin ":$TAG" || echo "no tag $DRAFT_TAG_999 on remote" + git tag -d "$TAG" || echo "no tag $DRAFT_TAG_999 locally" git tag -m 'draft/test release' "$TAG" - git push "$TAG" + git push origin "$TAG" RELEASE_TAG=$(gh release create "$TAG" -n "Checksum: $CHECKSUM" | xargs basename) upload "$RELEASE_TAG" elif $EXR; then From 6f523f5653e9d90b1bef85a04cdacc033738811a Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Mon, 30 Aug 2021 16:26:50 +1000 Subject: [PATCH 03/16] use SPM! --- CiteprocRsKit/Logger.swift | 1 + Package.swift | 36 ++++++++++++++++++++++++++++++++++++ citeproc-rs | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 Package.swift diff --git a/CiteprocRsKit/Logger.swift b/CiteprocRsKit/Logger.swift index 8695ec6..cad5c17 100644 --- a/CiteprocRsKit/Logger.swift +++ b/CiteprocRsKit/Logger.swift @@ -131,6 +131,7 @@ public class CROSLogger: CRLog { } } +@available(macOS 10.12, iOS 10, macCatalyst 13, *) extension CRLogLevel { /// A reasonable conversion from the Rust `log` crate's level to `os.OSLogType` levels. public func osLogType() -> OSLogType { diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..1d3514c --- /dev/null +++ b/Package.swift @@ -0,0 +1,36 @@ +// swift-tools-version:5.3 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "CiteprocRsKit", + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "CiteprocRsKit", + targets: ["CiteprocRsKit"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .binaryTarget( + name: "CiteprocRs", + path: "citeproc-rs/target/xcodeframework/CiteprocRs.xcframework" + ), + .target( + name: "CiteprocRsKit", + dependencies: ["CiteprocRs"], + path: "CiteprocRsKit" + ), + .testTarget( + name: "CiteprocRsKitTests", + dependencies: ["CiteprocRsKit"], + path: "CiteprocRsKitTests" + ), + ] +) diff --git a/citeproc-rs b/citeproc-rs index ffbb886..7507f14 160000 --- a/citeproc-rs +++ b/citeproc-rs @@ -1 +1 @@ -Subproject commit ffbb88638e11325ab3ed90672cc5ff611097beec +Subproject commit 7507f14c411a1bfdcd4403a4385689b26d7a4dc4 From 3016a2285aa6b6ed3977f58a6dfc2ea094b14e3a Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Wed, 1 Sep 2021 19:41:02 +1000 Subject: [PATCH 04/16] Make Xcode work with citeproc-rs/bindings/xcframework --- .ignore | 1 + CiteprocRsKit.xcodeproj/project.pbxproj | 83 +++++++++++++++++++++---- CiteprocRsKit/Common.xcconfig | 4 +- Package.swift | 6 +- Scripts/xcframework | 14 +++++ citeproc-rs | 2 +- 6 files changed, 94 insertions(+), 16 deletions(-) create mode 100644 .ignore create mode 100755 Scripts/xcframework diff --git a/.ignore b/.ignore new file mode 100644 index 0000000..b71f0f8 --- /dev/null +++ b/.ignore @@ -0,0 +1 @@ +citeproc-rs diff --git a/CiteprocRsKit.xcodeproj/project.pbxproj b/CiteprocRsKit.xcodeproj/project.pbxproj index 786746e..81f43f8 100644 --- a/CiteprocRsKit.xcodeproj/project.pbxproj +++ b/CiteprocRsKit.xcodeproj/project.pbxproj @@ -24,23 +24,24 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 851A4945260AD10B00AD1322 /* PBXContainerItemProxy */ = { + 8518340526DF7D6600F7A1DE /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 850B71D026085A0200EB37D0 /* Project object */; proxyType = 1; - remoteGlobalIDString = 851A493A260AD10B00AD1322; - remoteInfo = CiteprocRsKit; + remoteGlobalIDString = 8518340126DF7D3000F7A1DE; + remoteInfo = CiteprocRs; }; - 85A2F41E260AE1DC00B8DCE6 /* PBXContainerItemProxy */ = { + 851A4945260AD10B00AD1322 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 850B71D026085A0200EB37D0 /* Project object */; proxyType = 1; - remoteGlobalIDString = 85A2F410260AE08400B8DCE6; - remoteInfo = "cargo-build-x"; + remoteGlobalIDString = 851A493A260AD10B00AD1322; + remoteInfo = CiteprocRsKit; }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 8518340026DF7D0B00F7A1DE /* CiteprocRs.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = CiteprocRs.xcframework; path = "citeproc-rs/target/xcframework/CiteprocRs.xcframework"; sourceTree = ""; }; 851A493B260AD10B00AD1322 /* CiteprocRsKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CiteprocRsKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 851A4948260AD10B00AD1322 /* CiteprocRsKitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CiteprocRsKitTests.swift; sourceTree = ""; }; 851A494A260AD10B00AD1322 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -87,6 +88,7 @@ 850B71CF26085A0200EB37D0 = { isa = PBXGroup; children = ( + 8518340026DF7D0B00F7A1DE /* CiteprocRs.xcframework */, 856B441926086D410088EBFC /* Scripts */, 851A493B260AD10B00AD1322 /* CiteprocRsKit.framework */, 851A493C260AD10B00AD1322 /* CiteprocRsKit */, @@ -141,6 +143,20 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXLegacyTarget section */ + 8518340126DF7D3000F7A1DE /* CiteprocRs */ = { + isa = PBXLegacyTarget; + buildArgumentsString = "$(ACTION)"; + buildConfigurationList = 8518340226DF7D3000F7A1DE /* Build configuration list for PBXLegacyTarget "CiteprocRs" */; + buildPhases = ( + ); + buildToolPath = Scripts/xcframework; + buildWorkingDirectory = ""; + dependencies = ( + ); + name = CiteprocRs; + passBuildSettingsInEnvironment = 0; + productName = CiteprocRs; + }; 85A2F410260AE08400B8DCE6 /* libciteproc_rs */ = { isa = PBXLegacyTarget; buildArgumentsString = "bash \"$PROJECT_DIR/Scripts/cargo-build\""; @@ -170,7 +186,7 @@ buildRules = ( ); dependencies = ( - 85A2F41F260AE1DC00B8DCE6 /* PBXTargetDependency */, + 8518340626DF7D6600F7A1DE /* PBXTargetDependency */, ); name = CiteprocRsKit; productName = CiteprocRsKit; @@ -204,6 +220,9 @@ LastSwiftUpdateCheck = 1240; LastUpgradeCheck = 1250; TargetAttributes = { + 8518340126DF7D3000F7A1DE = { + CreatedOnToolsVersion = 12.5.1; + }; 851A493A260AD10B00AD1322 = { CreatedOnToolsVersion = 12.4; LastSwiftMigration = 1240; @@ -232,6 +251,7 @@ 851A493A260AD10B00AD1322 /* CiteprocRsKit */, 851A4942260AD10B00AD1322 /* CiteprocRsKitTests */, 85A2F410260AE08400B8DCE6 /* libciteproc_rs */, + 8518340126DF7D3000F7A1DE /* CiteprocRs */, ); }; /* End PBXProject section */ @@ -284,16 +304,16 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ + 8518340626DF7D6600F7A1DE /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 8518340126DF7D3000F7A1DE /* CiteprocRs */; + targetProxy = 8518340526DF7D6600F7A1DE /* PBXContainerItemProxy */; + }; 851A4946260AD10B00AD1322 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 851A493A260AD10B00AD1322 /* CiteprocRsKit */; targetProxy = 851A4945260AD10B00AD1322 /* PBXContainerItemProxy */; }; - 85A2F41F260AE1DC00B8DCE6 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 85A2F410260AE08400B8DCE6 /* libciteproc_rs */; - targetProxy = 85A2F41E260AE1DC00B8DCE6 /* PBXContainerItemProxy */; - }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ @@ -408,6 +428,36 @@ }; name = Release; }; + 8518340326DF7D3000F7A1DE /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Automatic; + DEBUGGING_SYMBOLS = YES; + DEBUG_INFORMATION_FORMAT = dwarf; + GCC_GENERATE_DEBUGGING_SYMBOLS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + ONLY_ACTIVE_ARCH = YES; + OTHER_CFLAGS = ""; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 8518340426DF7D3000F7A1DE /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Automatic; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + OTHER_CFLAGS = ""; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; 851A494D260AD10B00AD1322 /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = 85A2F50D260C38BD00B8DCE6 /* Link-citeproc-rs.xcconfig */; @@ -541,6 +591,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 8518340226DF7D3000F7A1DE /* Build configuration list for PBXLegacyTarget "CiteprocRs" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 8518340326DF7D3000F7A1DE /* Debug */, + 8518340426DF7D3000F7A1DE /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 851A494C260AD10B00AD1322 /* Build configuration list for PBXNativeTarget "CiteprocRsKit" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/CiteprocRsKit/Common.xcconfig b/CiteprocRsKit/Common.xcconfig index 687a169..4bd7c2e 100644 --- a/CiteprocRsKit/Common.xcconfig +++ b/CiteprocRsKit/Common.xcconfig @@ -20,8 +20,8 @@ SUPPORTED_PLATFORMS = iphonesimulator iphoneos macosx // {aarch64,x86_64}-apple-ios targets with custom LLVM target triples. This is all in the name of avoiding // a bunch of linker or xcframework creation errors where the static libraries have bad versions embedded // in the Mach-O load directives. This is only a problem for iphoneos/iphonesimulator. -IPHONEOS_DEPLOYMENT_TARGET = 11.0 -MACOSX_DEPLOYMENT_TARGET = 10.13 +IPHONEOS_DEPLOYMENT_TARGET = 13.0 +MACOSX_DEPLOYMENT_TARGET = 10.9 // Because we set important env variables in this file, // make sure the external build tool target gets this xcconfig. diff --git a/Package.swift b/Package.swift index 1d3514c..675b2bd 100644 --- a/Package.swift +++ b/Package.swift @@ -5,6 +5,10 @@ import PackageDescription let package = Package( name: "CiteprocRsKit", + platforms: [ + .macOS("10.9"), + .iOS("13.0") + ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( @@ -20,7 +24,7 @@ let package = Package( // Targets can depend on other targets in this package, and on products in packages this package depends on. .binaryTarget( name: "CiteprocRs", - path: "citeproc-rs/target/xcodeframework/CiteprocRs.xcframework" + path: "citeproc-rs/target/xcframework/CiteprocRs.xcframework" ), .target( name: "CiteprocRsKit", diff --git a/Scripts/xcframework b/Scripts/xcframework new file mode 100755 index 0000000..3c2d008 --- /dev/null +++ b/Scripts/xcframework @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -eu +set -o pipefail + +CARGO_TARGET_DIR="citeproc-rs/target" +WORK_DIR="citeproc-rs/bindings/xcframework" + +source Scripts/environment + +cd $WORK_DIR + +export CONFIGURATION=test +./build.sh diff --git a/citeproc-rs b/citeproc-rs index 7507f14..c60e8e7 160000 --- a/citeproc-rs +++ b/citeproc-rs @@ -1 +1 @@ -Subproject commit 7507f14c411a1bfdcd4403a4385689b26d7a4dc4 +Subproject commit c60e8e743a7b104b31ee27fff502e6f31ffe7fbc From ea12d1924e5d7f9488064986ed3616aade17dcba Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Wed, 1 Sep 2021 19:45:43 +1000 Subject: [PATCH 05/16] Move swift sources into SPM-style Sources folder --- CiteprocRsKit.xcodeproj/project.pbxproj | 18 +++++++++++++----- Package.swift | 6 ++---- .../CiteprocRsKit}/Buffer.swift | 0 .../CiteprocRsKit}/Cluster.swift | 0 .../CiteprocRsKit}/Common.xcconfig | 0 .../CiteprocRsKit}/Debug.xcconfig | 0 .../Documentation.docc/CRDriver.md | 0 .../Documentation.docc/Documentation.md | 0 .../CiteprocRsKit}/Documentation.docc/Tour.md | 0 .../CiteprocRsKit}/Driver.swift | 0 .../CiteprocRsKit}/Errors.swift | 0 .../CiteprocRsKit}/FFIUserData.swift | 0 .../CiteprocRsKit}/FetchContext.swift | 0 .../CiteprocRsKit}/Info.plist | 0 .../CiteprocRsKit}/Link-citeproc-rs.xcconfig | 0 .../CiteprocRsKit}/Logger.swift | 0 .../CiteprocRsKit}/Release.xcconfig | 0 .../CiteprocRsKitTests.swift | 0 .../CiteprocRsKitTests}/ClusterTests.swift | 0 .../CiteprocRsKitTests}/Info.plist | 0 .../CiteprocRsKitTests}/LoggerTests.swift | 0 .../CiteprocRsKitTests}/MemoryTests.swift | 0 .../CiteprocRsKitTests}/PanicTests.swift | 0 23 files changed, 15 insertions(+), 9 deletions(-) rename {CiteprocRsKit => Sources/CiteprocRsKit}/Buffer.swift (100%) rename {CiteprocRsKit => Sources/CiteprocRsKit}/Cluster.swift (100%) rename {CiteprocRsKit => Sources/CiteprocRsKit}/Common.xcconfig (100%) rename {CiteprocRsKit => Sources/CiteprocRsKit}/Debug.xcconfig (100%) rename {CiteprocRsKit => Sources/CiteprocRsKit}/Documentation.docc/CRDriver.md (100%) rename {CiteprocRsKit => Sources/CiteprocRsKit}/Documentation.docc/Documentation.md (100%) rename {CiteprocRsKit => Sources/CiteprocRsKit}/Documentation.docc/Tour.md (100%) rename {CiteprocRsKit => Sources/CiteprocRsKit}/Driver.swift (100%) rename {CiteprocRsKit => Sources/CiteprocRsKit}/Errors.swift (100%) rename {CiteprocRsKit => Sources/CiteprocRsKit}/FFIUserData.swift (100%) rename {CiteprocRsKit => Sources/CiteprocRsKit}/FetchContext.swift (100%) rename {CiteprocRsKit => Sources/CiteprocRsKit}/Info.plist (100%) rename {CiteprocRsKit => Sources/CiteprocRsKit}/Link-citeproc-rs.xcconfig (100%) rename {CiteprocRsKit => Sources/CiteprocRsKit}/Logger.swift (100%) rename {CiteprocRsKit => Sources/CiteprocRsKit}/Release.xcconfig (100%) rename {CiteprocRsKitTests => Sources/CiteprocRsKitTests}/CiteprocRsKitTests.swift (100%) rename {CiteprocRsKitTests => Sources/CiteprocRsKitTests}/ClusterTests.swift (100%) rename {CiteprocRsKitTests => Sources/CiteprocRsKitTests}/Info.plist (100%) rename {CiteprocRsKitTests => Sources/CiteprocRsKitTests}/LoggerTests.swift (100%) rename {CiteprocRsKitTests => Sources/CiteprocRsKitTests}/MemoryTests.swift (100%) rename {CiteprocRsKitTests => Sources/CiteprocRsKitTests}/PanicTests.swift (100%) diff --git a/CiteprocRsKit.xcodeproj/project.pbxproj b/CiteprocRsKit.xcodeproj/project.pbxproj index 81f43f8..49b8c8d 100644 --- a/CiteprocRsKit.xcodeproj/project.pbxproj +++ b/CiteprocRsKit.xcodeproj/project.pbxproj @@ -88,13 +88,21 @@ 850B71CF26085A0200EB37D0 = { isa = PBXGroup; children = ( + 8518340726DF827C00F7A1DE /* Sources */, 8518340026DF7D0B00F7A1DE /* CiteprocRs.xcframework */, 856B441926086D410088EBFC /* Scripts */, 851A493B260AD10B00AD1322 /* CiteprocRsKit.framework */, + 851A495A260AD31D00AD1322 /* CiteprocRsKitTests.xctest */, + ); + sourceTree = ""; + }; + 8518340726DF827C00F7A1DE /* Sources */ = { + isa = PBXGroup; + children = ( 851A493C260AD10B00AD1322 /* CiteprocRsKit */, 851A4947260AD10B00AD1322 /* CiteprocRsKitTests */, - 851A495A260AD31D00AD1322 /* CiteprocRsKitTests.xctest */, ); + path = Sources; sourceTree = ""; }; 851A493C260AD10B00AD1322 /* CiteprocRsKit */ = { @@ -469,7 +477,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = CiteprocRsKit/Info.plist; + INFOPLIST_FILE = Sources/CiteprocRsKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -498,7 +506,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = CiteprocRsKit/Info.plist; + INFOPLIST_FILE = Sources/CiteprocRsKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -524,7 +532,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "-"; CODE_SIGN_STYLE = Manual; DEVELOPMENT_TEAM = ""; - INFOPLIST_FILE = CiteprocRsKitTests/Info.plist; + INFOPLIST_FILE = Sources/CiteprocRsKitTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -545,7 +553,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "-"; CODE_SIGN_STYLE = Manual; DEVELOPMENT_TEAM = ""; - INFOPLIST_FILE = CiteprocRsKitTests/Info.plist; + INFOPLIST_FILE = Sources/CiteprocRsKitTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/Package.swift b/Package.swift index 675b2bd..0e1a740 100644 --- a/Package.swift +++ b/Package.swift @@ -28,13 +28,11 @@ let package = Package( ), .target( name: "CiteprocRsKit", - dependencies: ["CiteprocRs"], - path: "CiteprocRsKit" + dependencies: ["CiteprocRs"] ), .testTarget( name: "CiteprocRsKitTests", - dependencies: ["CiteprocRsKit"], - path: "CiteprocRsKitTests" + dependencies: ["CiteprocRsKit"] ), ] ) diff --git a/CiteprocRsKit/Buffer.swift b/Sources/CiteprocRsKit/Buffer.swift similarity index 100% rename from CiteprocRsKit/Buffer.swift rename to Sources/CiteprocRsKit/Buffer.swift diff --git a/CiteprocRsKit/Cluster.swift b/Sources/CiteprocRsKit/Cluster.swift similarity index 100% rename from CiteprocRsKit/Cluster.swift rename to Sources/CiteprocRsKit/Cluster.swift diff --git a/CiteprocRsKit/Common.xcconfig b/Sources/CiteprocRsKit/Common.xcconfig similarity index 100% rename from CiteprocRsKit/Common.xcconfig rename to Sources/CiteprocRsKit/Common.xcconfig diff --git a/CiteprocRsKit/Debug.xcconfig b/Sources/CiteprocRsKit/Debug.xcconfig similarity index 100% rename from CiteprocRsKit/Debug.xcconfig rename to Sources/CiteprocRsKit/Debug.xcconfig diff --git a/CiteprocRsKit/Documentation.docc/CRDriver.md b/Sources/CiteprocRsKit/Documentation.docc/CRDriver.md similarity index 100% rename from CiteprocRsKit/Documentation.docc/CRDriver.md rename to Sources/CiteprocRsKit/Documentation.docc/CRDriver.md diff --git a/CiteprocRsKit/Documentation.docc/Documentation.md b/Sources/CiteprocRsKit/Documentation.docc/Documentation.md similarity index 100% rename from CiteprocRsKit/Documentation.docc/Documentation.md rename to Sources/CiteprocRsKit/Documentation.docc/Documentation.md diff --git a/CiteprocRsKit/Documentation.docc/Tour.md b/Sources/CiteprocRsKit/Documentation.docc/Tour.md similarity index 100% rename from CiteprocRsKit/Documentation.docc/Tour.md rename to Sources/CiteprocRsKit/Documentation.docc/Tour.md diff --git a/CiteprocRsKit/Driver.swift b/Sources/CiteprocRsKit/Driver.swift similarity index 100% rename from CiteprocRsKit/Driver.swift rename to Sources/CiteprocRsKit/Driver.swift diff --git a/CiteprocRsKit/Errors.swift b/Sources/CiteprocRsKit/Errors.swift similarity index 100% rename from CiteprocRsKit/Errors.swift rename to Sources/CiteprocRsKit/Errors.swift diff --git a/CiteprocRsKit/FFIUserData.swift b/Sources/CiteprocRsKit/FFIUserData.swift similarity index 100% rename from CiteprocRsKit/FFIUserData.swift rename to Sources/CiteprocRsKit/FFIUserData.swift diff --git a/CiteprocRsKit/FetchContext.swift b/Sources/CiteprocRsKit/FetchContext.swift similarity index 100% rename from CiteprocRsKit/FetchContext.swift rename to Sources/CiteprocRsKit/FetchContext.swift diff --git a/CiteprocRsKit/Info.plist b/Sources/CiteprocRsKit/Info.plist similarity index 100% rename from CiteprocRsKit/Info.plist rename to Sources/CiteprocRsKit/Info.plist diff --git a/CiteprocRsKit/Link-citeproc-rs.xcconfig b/Sources/CiteprocRsKit/Link-citeproc-rs.xcconfig similarity index 100% rename from CiteprocRsKit/Link-citeproc-rs.xcconfig rename to Sources/CiteprocRsKit/Link-citeproc-rs.xcconfig diff --git a/CiteprocRsKit/Logger.swift b/Sources/CiteprocRsKit/Logger.swift similarity index 100% rename from CiteprocRsKit/Logger.swift rename to Sources/CiteprocRsKit/Logger.swift diff --git a/CiteprocRsKit/Release.xcconfig b/Sources/CiteprocRsKit/Release.xcconfig similarity index 100% rename from CiteprocRsKit/Release.xcconfig rename to Sources/CiteprocRsKit/Release.xcconfig diff --git a/CiteprocRsKitTests/CiteprocRsKitTests.swift b/Sources/CiteprocRsKitTests/CiteprocRsKitTests.swift similarity index 100% rename from CiteprocRsKitTests/CiteprocRsKitTests.swift rename to Sources/CiteprocRsKitTests/CiteprocRsKitTests.swift diff --git a/CiteprocRsKitTests/ClusterTests.swift b/Sources/CiteprocRsKitTests/ClusterTests.swift similarity index 100% rename from CiteprocRsKitTests/ClusterTests.swift rename to Sources/CiteprocRsKitTests/ClusterTests.swift diff --git a/CiteprocRsKitTests/Info.plist b/Sources/CiteprocRsKitTests/Info.plist similarity index 100% rename from CiteprocRsKitTests/Info.plist rename to Sources/CiteprocRsKitTests/Info.plist diff --git a/CiteprocRsKitTests/LoggerTests.swift b/Sources/CiteprocRsKitTests/LoggerTests.swift similarity index 100% rename from CiteprocRsKitTests/LoggerTests.swift rename to Sources/CiteprocRsKitTests/LoggerTests.swift diff --git a/CiteprocRsKitTests/MemoryTests.swift b/Sources/CiteprocRsKitTests/MemoryTests.swift similarity index 100% rename from CiteprocRsKitTests/MemoryTests.swift rename to Sources/CiteprocRsKitTests/MemoryTests.swift diff --git a/CiteprocRsKitTests/PanicTests.swift b/Sources/CiteprocRsKitTests/PanicTests.swift similarity index 100% rename from CiteprocRsKitTests/PanicTests.swift rename to Sources/CiteprocRsKitTests/PanicTests.swift From 4872c793a2ca3c637fa4820dc3a8751228637782 Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Fri, 3 Sep 2021 16:33:22 +1000 Subject: [PATCH 06/16] new rust-toolchain file with more targets, debug/release split --- CiteprocRsKit.xcodeproj/project.pbxproj | 4 ++-- citeproc-rs | 2 +- rust-toolchain | 15 --------------- rust-toolchain.toml | 16 ++++++++++++++++ 4 files changed, 19 insertions(+), 18 deletions(-) delete mode 100644 rust-toolchain create mode 100644 rust-toolchain.toml diff --git a/CiteprocRsKit.xcodeproj/project.pbxproj b/CiteprocRsKit.xcodeproj/project.pbxproj index 49b8c8d..2ea63b6 100644 --- a/CiteprocRsKit.xcodeproj/project.pbxproj +++ b/CiteprocRsKit.xcodeproj/project.pbxproj @@ -41,7 +41,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 8518340026DF7D0B00F7A1DE /* CiteprocRs.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = CiteprocRs.xcframework; path = "citeproc-rs/target/xcframework/CiteprocRs.xcframework"; sourceTree = ""; }; + 8518340826DF8C4900F7A1DE /* CiteprocRs.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = CiteprocRs.xcframework; path = "citeproc-rs/target/xcframework/debug/CiteprocRs.xcframework"; sourceTree = ""; }; 851A493B260AD10B00AD1322 /* CiteprocRsKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CiteprocRsKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 851A4948260AD10B00AD1322 /* CiteprocRsKitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CiteprocRsKitTests.swift; sourceTree = ""; }; 851A494A260AD10B00AD1322 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -88,8 +88,8 @@ 850B71CF26085A0200EB37D0 = { isa = PBXGroup; children = ( + 8518340826DF8C4900F7A1DE /* CiteprocRs.xcframework */, 8518340726DF827C00F7A1DE /* Sources */, - 8518340026DF7D0B00F7A1DE /* CiteprocRs.xcframework */, 856B441926086D410088EBFC /* Scripts */, 851A493B260AD10B00AD1322 /* CiteprocRsKit.framework */, 851A495A260AD31D00AD1322 /* CiteprocRsKitTests.xctest */, diff --git a/citeproc-rs b/citeproc-rs index c60e8e7..33878f4 160000 --- a/citeproc-rs +++ b/citeproc-rs @@ -1 +1 @@ -Subproject commit c60e8e743a7b104b31ee27fff502e6f31ffe7fbc +Subproject commit 33878f491f85efb20f31bb514cffcf19c05a03bb diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index 1e60925..0000000 --- a/rust-toolchain +++ /dev/null @@ -1,15 +0,0 @@ -[toolchain] -channel = "nightly" -profile = "minimal" -components = [ "rust-src" ] -targets = [ -# intel macs - "x86_64-apple-darwin", -# arm macs - "aarch64-apple-darwin", -# simulator - "x86_64-apple-ios", -# ios devices - "aarch64-apple-ios", -] - diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..b527231 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,16 @@ +[toolchain] +# needs PR https://github.com/rust-lang/rust/pull/87699 +channel = "nightly-2021-08-30" +profile = "minimal" +components = [ "rust-src" ] +targets = [ + # intel & arm macs + "x86_64-apple-darwin", "aarch64-apple-darwin", + # ios devices + "aarch64-apple-ios", + # ios simulator (odd one out -- no such target x86_64-apple-ios-sim) + "x86_64-apple-ios", "aarch64-apple-ios-sim", + # intel & arm catalyst + # "x86_64-apple-ios-macabi", "aarch64-apple-ios-macabi", +] + From a1969ca66fc809dc6e21e218cebc97fed2e55f94 Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Fri, 3 Sep 2021 16:33:46 +1000 Subject: [PATCH 07/16] release script now pushes rust-only CiteprocRs.xcframework --- Scripts/BinaryPackage/Package.swift | 6 +-- Scripts/release | 73 ++++++++++++++++------------- 2 files changed, 43 insertions(+), 36 deletions(-) diff --git a/Scripts/BinaryPackage/Package.swift b/Scripts/BinaryPackage/Package.swift index b69b9b1..e002ce1 100644 --- a/Scripts/BinaryPackage/Package.swift +++ b/Scripts/BinaryPackage/Package.swift @@ -5,12 +5,12 @@ let package = Package( name: "CiteprocRsKit", products: [ .library( - name: "CiteprocRsKit", - targets: ["CiteprocRsKit"]), + name: "CiteprocRs", + targets: ["CiteprocRs"]), ], targets: [ .binaryTarget( - name: "CiteprocRsKit", + name: "CiteprocRs", url: "XCFRAMEWORK_ZIP_URL", checksum: "XCFRAMEWORK_ZIP_CHECKSUM" ), diff --git a/Scripts/release b/Scripts/release index ff90d61..81cdccb 100755 --- a/Scripts/release +++ b/Scripts/release @@ -37,7 +37,6 @@ TAG="" PUSH_BINARY_REPO=false IS_DRAFT=false BINARY_BRANCH=master -RELEASE_DRAFT_FLAG="" FORCE_PUSH_BINARY="" parse_params() { @@ -66,24 +65,35 @@ parse_params() { parse_params $@ +BUILD_RIR="$DIR/citeproc-rs/bindings/xcframework" +TARGET_DIR="$DIR/citeproc-rs/target/xcframework/release" + build() { set -euo pipefail - rustup show - carthage build --use-xcframeworks --no-skip-current --verbose + ( + cd "$BUILD_DIR" + env CONFIGURATION=release ./build.sh + ) + # carthage build --use-xcframeworks --no-skip-current --verbose # see https://bugs.swift.org/browse/SR-14257, commment by @cormacrelf # `zip -y` is the key here, it preserves the Versions/Current (etc) symlinks inside the frameworks. # These otherwise cause `unzip` to fail and SwiftPM to give you "TSCBasic.StringError error 1". - (cd Carthage/Build \ - && rm -f CiteprocRsKit.xcframework.zip \ - && zip -y -r CiteprocRsKit.xcframework.zip CiteprocRsKit.xcframework) + (cd "$TARGET_DIR" \ + && rm -f CiteprocRs.xcframework.zip \ + && zip -y -r CiteprocRs.xcframework.zip CiteprocRs.xcframework) +} + +upload() { + set +e + gh release upload "$1" "$TARGET_DIR/CiteprocRs.xcframework.zip" } checksum () { set +e # SHORT_SHA=$(git rev-parse --short "$GITHUB_SHA") - cd Carthage/Build - touch Package.swift - local CHECKSUM=$(swift package compute-checksum CiteprocRsKit.xcframework.zip) + cd "$TARGET_DIR" + touch Package.swift + local CHECKSUM=$(swift package compute-checksum CiteprocRs.xcframework.zip) rm Package.swift echo $CHECKSUM } @@ -108,8 +118,8 @@ push_binary_repo() { fi cd "$TMP" - git clone https://github.com/cormacrelf/CiteprocRsKit-Binary.git --branch master - cd CiteprocRsKit-Binary + git clone https://github.com/citeproc-rs/ffi-xcframework.git --branch master + cd ffi-xcframework # https://stackoverflow.com/a/26961416 git switch -c $BINARY_BRANCH cp -R "$DIR"/Scripts/BinaryPackage/* . @@ -119,20 +129,15 @@ push_binary_repo() { < "$DIR/Scripts/BinaryPackage/Package.swift" \ > "./Package.swift" git add . - git commit -m "release $TAG from $RELEASE_SHA" \ + git commit -m "release $TAG for $RELEASE_SHA" \ -m "https://github.com/cormacrelf/CiteprocRsKit/releases/tag/$TAG" - git tag -f -a -m "release $TAG from $RELEASE_SHA" $TAG + git tag -f -a -m "release $TAG for $RELEASE_SHA" $TAG echo $(pwd) git push $FORCE_PUSH_BINARY origin $BINARY_BRANCH git push --force --tags cd "$DIR" } -upload() { - set +e - gh release upload "$1" Carthage/Build/CiteprocRsKit.xcframework.zip -} - edit_release() { local TAG="$1" local CHECKSUM="$2" @@ -154,21 +159,23 @@ fi CHECKSUM=$(checksum) -if $IS_DRAFT; then - gh release delete "$RELEASE_TAG" || echo "no draft release to delete; continuing" - git push origin ":$TAG" || echo "no tag $DRAFT_TAG_999 on remote" - git tag -d "$TAG" || echo "no tag $DRAFT_TAG_999 locally" - git tag -m 'draft/test release' "$TAG" - git push origin "$TAG" - RELEASE_TAG=$(gh release create "$TAG" -n "Checksum: $CHECKSUM" | xargs basename) - upload "$RELEASE_TAG" -elif $EXR; then - RELEASE_TAG="$EXISTING_RELEASE" - upload "$RELEASE_TAG" - edit_release "$RELEASE_TAG" "$CHECKSUM" -elif $RELEASE; then - RELEASE_TAG=$(gh release create "$TAG" -n "Checksum: $CHECKSUM" | xargs basename) - upload "$RELEASE_TAG" +if $RELEASE; then + if $IS_DRAFT; then + gh release delete "$RELEASE_TAG" || echo "no draft release to delete; continuing" + git push origin ":$TAG" || echo "no tag $DRAFT_TAG_999 on remote" + git tag -d "$TAG" || echo "no tag $DRAFT_TAG_999 locally" + git tag -m 'draft/test release' "$TAG" + git push origin "$TAG" + RELEASE_TAG=$(gh release create "$TAG" -n "Checksum: $CHECKSUM" | xargs basename) + upload "$RELEASE_TAG" + elif $EXR; then + RELEASE_TAG="$EXISTING_RELEASE" + upload "$RELEASE_TAG" + edit_release "$RELEASE_TAG" "$CHECKSUM" + else + RELEASE_TAG=$(gh release create "$TAG" -n "Checksum: $CHECKSUM" | xargs basename) + upload "$RELEASE_TAG" + fi fi if $PUSH_BINARY_REPO && ! [ -z "$TAG" ]; then From 7ede15c76e464f9d843f2bd9c5b81802aa98707d Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Fri, 3 Sep 2021 16:39:02 +1000 Subject: [PATCH 08/16] Simplify the readme for SwiftPM --- README.md | 73 +++++++++---------------------------------------------- 1 file changed, 12 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index c01ec46..3ad1de0 100644 --- a/README.md +++ b/README.md @@ -3,16 +3,20 @@ A set of Swift bindings for [`citeproc-rs`](https://github.com/zotero/citeproc-rs). -## Pre-built Binaries +This is a SwiftPM package that has a dependency on a pre-built copy of +`citeproc-rs`' FFI library. -Add the repo [`https://github.com/cormacrelf/CiteprocRsKit-Binary`][bin] as a -dependency in a Package.swift file, or in Xcode's Swift packages list. Versions -in that repo align with tagged releases in this repo. It is a cross-platform -xcframework built for macOS, iOS and the iOS Simulator. +## Installation -For Package.swift, follow the docs [here][v1] and [here][v2] for version requirements. +### Via Xcode + +Open up your project's settings page, look under the 'Swift Packages' tab and +add this GitHub repo as a dependency. + +### Via Package.swift + +For Package.swift, add as below. Follow the docs [here][v1] and [here][v2] for version requirements. -[bin]: https://github.com/cormacrelf/CiteprocRsKit-Binary [v1]: https://github.com/apple/swift-package-manager/blob/main/Documentation/PackageDescription.md#package-dependency [v2]: https://github.com/apple/swift-package-manager/blob/main/Documentation/PackageDescription.md#package-dependency-requirement @@ -22,63 +26,10 @@ For Package.swift, follow the docs [here][v1] and [here][v2] for version require dependencies: [ // exact version best for sub-1.0.0 releases as SwiftPM doesn't consider an // 0.x to 0.x+1 change a "major version" despite Semver - .package(name: "CiteprocRsKit", url: "https://github.com/cormacrelf/CiteprocRsKit-Binary", .exact("0.2.1")), + .package(url: "https://github.com/cormacrelf/CiteprocRsKit", .exact("0.4.0")), ], targets: [ // and add it as a dependency to a target in your own project .target(name: "MyApp", dependencies: ["CiteprocRsKit"]) ] ``` - -## Using Carthage - -### Prerequisites for building - -* Xcode 12 (not tested on lesser Xcodes) -* `rustup` (installed any method, must have nightly toolchain installed. tip: `brew install rustup`) -* `jq` (must be Homebrew or in Xcode's default path somehow, `brew install jq`) - -You'll need [Carthage](https://github.com/Carthage/Carthage) v0.37+ (e.g. `brew install -carthage`) to follow the instructions below. Which are probably the easiest -possible way and quite neat indeed. You probably want to .gitignore the -Carthage folder. - -### Adding as a dependency to an Xcode project - -Add this repo as a Carthage dependency. - -``` -# Cartfile -git "cormacrelf/CiteprocRsKit" "master" # or a tag -``` - -Then use Carthage in XCFramework mode. The legacy mode does not work because -CiteprocRsKit is a multi-arch target and it will fail to `lipo` all the archs -together because there are archs in common between -macos,iphonesimulator,iphoneos platforms these days. - -```sh -carthage update --use-xcframeworks -# add `--platform ios` if you don't need the macos build as well - -# if you have CiteprocRsKit in your lockfile already and don't want to update, run -carthage build --use-xcframeworks - -# basically just read the carthage docs -``` - -Drag the Carthage/Build/CiteprocRsKit.xcframework into your target's Frameworks -and Libraries list in the configuration editor. - -This is a static library, so you need to select `Do Not Embed` when you drag it -in. Embedding is for dylib frameworks who need to be copied to the output (e.g. -inside a .app/ipa) and signed, but this one is statically linked to your Swift -code. - -Then in a swift file: - -```swift -import CiteprocRsKit -// follow the test suite in CiteprocRsKitTests for usage so far -``` - From 692d0c02984efe08ae55e327fd9833b921bf40d3 Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Fri, 3 Sep 2021 16:42:17 +1000 Subject: [PATCH 09/16] fix a typo in release script --- Scripts/release | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/release b/Scripts/release index 81cdccb..30800d4 100755 --- a/Scripts/release +++ b/Scripts/release @@ -65,7 +65,7 @@ parse_params() { parse_params $@ -BUILD_RIR="$DIR/citeproc-rs/bindings/xcframework" +BUILD_DIR="$DIR/citeproc-rs/bindings/xcframework" TARGET_DIR="$DIR/citeproc-rs/target/xcframework/release" build() { From 97430eb3930c3da64fa2efd86d423cdaf0d6ee35 Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Fri, 3 Sep 2021 17:52:28 +1000 Subject: [PATCH 10/16] Move xcconfig out of SPM's way --- CiteprocRsKit.xcodeproj/project.pbxproj | 14 ++------------ .../Common.xcconfig | 2 +- .../CiteprocRsKit => Configuration}/Debug.xcconfig | 0 .../Link-citeproc-rs.xcconfig | 0 .../Release.xcconfig | 0 5 files changed, 3 insertions(+), 13 deletions(-) rename {Sources/CiteprocRsKit => Configuration}/Common.xcconfig (97%) rename {Sources/CiteprocRsKit => Configuration}/Debug.xcconfig (100%) rename {Sources/CiteprocRsKit => Configuration}/Link-citeproc-rs.xcconfig (100%) rename {Sources/CiteprocRsKit => Configuration}/Release.xcconfig (100%) diff --git a/CiteprocRsKit.xcodeproj/project.pbxproj b/CiteprocRsKit.xcodeproj/project.pbxproj index 2ea63b6..638ce69 100644 --- a/CiteprocRsKit.xcodeproj/project.pbxproj +++ b/CiteprocRsKit.xcodeproj/project.pbxproj @@ -48,6 +48,7 @@ 851A4954260AD12300AD1322 /* Driver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Driver.swift; sourceTree = ""; }; 851A495A260AD31D00AD1322 /* CiteprocRsKitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CiteprocRsKitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 851A495F260AD3EE00AD1322 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 851F28B226E209210010D76E /* Configuration */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Configuration; sourceTree = ""; }; 852DD4AD26B15497002AED8D /* FetchContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchContext.swift; sourceTree = ""; }; 852DD4AF26B154BC002AED8D /* Errors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Errors.swift; sourceTree = ""; }; 852DD4B126B3E410002AED8D /* FFIUserData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FFIUserData.swift; sourceTree = ""; }; @@ -60,10 +61,6 @@ 857D733B26B1320100C34654 /* Buffer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Buffer.swift; sourceTree = ""; }; 8583B29926B7F26F007FF5AB /* ClusterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClusterTests.swift; sourceTree = ""; }; 8583B29B26B80563007FF5AB /* PanicTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PanicTests.swift; sourceTree = ""; }; - 85A2F50D260C38BD00B8DCE6 /* Link-citeproc-rs.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Link-citeproc-rs.xcconfig"; sourceTree = ""; }; - 85E4B4D2260D99E4001B9ED1 /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; - 85E4B4E1260D9DA7001B9ED1 /* Common.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Common.xcconfig; sourceTree = ""; }; - 85E4B4E4260D9E1A001B9ED1 /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -88,6 +85,7 @@ 850B71CF26085A0200EB37D0 = { isa = PBXGroup; children = ( + 851F28B226E209210010D76E /* Configuration */, 8518340826DF8C4900F7A1DE /* CiteprocRs.xcframework */, 8518340726DF827C00F7A1DE /* Sources */, 856B441926086D410088EBFC /* Scripts */, @@ -116,10 +114,6 @@ 852DD4AD26B15497002AED8D /* FetchContext.swift */, 852DD4B126B3E410002AED8D /* FFIUserData.swift */, 857D733B26B1320100C34654 /* Buffer.swift */, - 85A2F50D260C38BD00B8DCE6 /* Link-citeproc-rs.xcconfig */, - 85E4B4E4260D9E1A001B9ED1 /* Debug.xcconfig */, - 85E4B4E1260D9DA7001B9ED1 /* Common.xcconfig */, - 85E4B4D2260D99E4001B9ED1 /* Release.xcconfig */, 854CF4A526CAD5EE00363E4B /* Documentation.docc */, ); path = CiteprocRsKit; @@ -327,7 +321,6 @@ /* Begin XCBuildConfiguration section */ 850B71DD26085A0200EB37D0 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 85E4B4E4260D9E1A001B9ED1 /* Debug.xcconfig */; buildSettings = { CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; @@ -385,7 +378,6 @@ }; 850B71DE26085A0200EB37D0 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 85E4B4D2260D99E4001B9ED1 /* Release.xcconfig */; buildSettings = { CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; @@ -468,7 +460,6 @@ }; 851A494D260AD10B00AD1322 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 85A2F50D260C38BD00B8DCE6 /* Link-citeproc-rs.xcconfig */; buildSettings = { CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Manual; @@ -497,7 +488,6 @@ }; 851A494E260AD10B00AD1322 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 85A2F50D260C38BD00B8DCE6 /* Link-citeproc-rs.xcconfig */; buildSettings = { CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Manual; diff --git a/Sources/CiteprocRsKit/Common.xcconfig b/Configuration/Common.xcconfig similarity index 97% rename from Sources/CiteprocRsKit/Common.xcconfig rename to Configuration/Common.xcconfig index 4bd7c2e..dbd8bc6 100644 --- a/Sources/CiteprocRsKit/Common.xcconfig +++ b/Configuration/Common.xcconfig @@ -21,7 +21,7 @@ SUPPORTED_PLATFORMS = iphonesimulator iphoneos macosx // a bunch of linker or xcframework creation errors where the static libraries have bad versions embedded // in the Mach-O load directives. This is only a problem for iphoneos/iphonesimulator. IPHONEOS_DEPLOYMENT_TARGET = 13.0 -MACOSX_DEPLOYMENT_TARGET = 10.9 +MACOSX_DEPLOYMENT_TARGET = 10.10 // Because we set important env variables in this file, // make sure the external build tool target gets this xcconfig. diff --git a/Sources/CiteprocRsKit/Debug.xcconfig b/Configuration/Debug.xcconfig similarity index 100% rename from Sources/CiteprocRsKit/Debug.xcconfig rename to Configuration/Debug.xcconfig diff --git a/Sources/CiteprocRsKit/Link-citeproc-rs.xcconfig b/Configuration/Link-citeproc-rs.xcconfig similarity index 100% rename from Sources/CiteprocRsKit/Link-citeproc-rs.xcconfig rename to Configuration/Link-citeproc-rs.xcconfig diff --git a/Sources/CiteprocRsKit/Release.xcconfig b/Configuration/Release.xcconfig similarity index 100% rename from Sources/CiteprocRsKit/Release.xcconfig rename to Configuration/Release.xcconfig From c7b0f2d13331e609f53b65aa4c12a8b20868ef03 Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Fri, 3 Sep 2021 17:53:29 +1000 Subject: [PATCH 11/16] Delete carthage files and ignore Package.resolved --- .gitignore | 5 +++++ Cartfile | 0 Cartfile.resolved | 0 3 files changed, 5 insertions(+) delete mode 100644 Cartfile delete mode 100644 Cartfile.resolved diff --git a/.gitignore b/.gitignore index ca9cb71..24e50b1 100644 --- a/.gitignore +++ b/.gitignore @@ -88,3 +88,8 @@ fastlane/test_output # https://github.com/johnno1962/injectionforxcode iOSInjectionProject/ + +# This is ignored when a repo is used as a dependency anyway. +Package.resolved + +.DS_Store diff --git a/Cartfile b/Cartfile deleted file mode 100644 index e69de29..0000000 diff --git a/Cartfile.resolved b/Cartfile.resolved deleted file mode 100644 index e69de29..0000000 From 97577ed3ba2c069bea3539c132e3b26699245de9 Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Fri, 3 Sep 2021 17:53:50 +1000 Subject: [PATCH 12/16] Fixes for releasing binaries --- Scripts/BinaryPackage/Package.swift | 2 +- Scripts/release | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Scripts/BinaryPackage/Package.swift b/Scripts/BinaryPackage/Package.swift index e002ce1..ce7305d 100644 --- a/Scripts/BinaryPackage/Package.swift +++ b/Scripts/BinaryPackage/Package.swift @@ -2,7 +2,7 @@ import PackageDescription let package = Package( - name: "CiteprocRsKit", + name: "CiteprocRs", products: [ .library( name: "CiteprocRs", diff --git a/Scripts/release b/Scripts/release index 30800d4..d26be3b 100755 --- a/Scripts/release +++ b/Scripts/release @@ -105,7 +105,7 @@ push_binary_repo() { local TMP="$(mktemp -d)" trap "rm -rf -- $TMP" EXIT - local DL=$(gh api "/repos/cormacrelf/CiteprocRsKit/releases/tags/$RELEASE_TAG" -q '.assets[] | select(.name == "CiteprocRsKit.xcframework.zip") | .browser_download_url') + local DL=$(gh api "/repos/cormacrelf/CiteprocRsKit/releases/tags/$RELEASE_TAG" -q '.assets[] | select(.name == "CiteprocRs.xcframework.zip") | .browser_download_url') # could dereference this locally, but this makes sure we pushed it somewhere local RELEASE_SHA=$(gh api /repos/cormacrelf/CiteprocRsKit/commits/$TAG -q '.sha') @@ -143,7 +143,7 @@ edit_release() { local CHECKSUM="$2" local RELEASE=$(gh api /repos/cormacrelf/CiteprocRsKit/releases/tags/$TAG -q '.url') local BODY=$(gh api /repos/cormacrelf/CiteprocRsKit/releases/tags/$TAG -q '.body') - local DL=$(gh api /repos/cormacrelf/CiteprocRsKit/releases/tags/$TAG -q '.assets[] | select(.name == "CiteprocRsKit.xcframework.zip") | .browser_download_url') + local DL=$(gh api /repos/cormacrelf/CiteprocRsKit/releases/tags/$TAG -q '.assets[] | select(.name == "CiteprocRs.xcframework.zip") | .browser_download_url') if ! (echo $BODY | grep -q $CHECKSUM); then echo "patching body" gh api -X PATCH $RELEASE -f "body=$BODY\n\nChecksum: $CHECKSUM" @@ -151,7 +151,7 @@ edit_release() { echo $DL } -if $SKIP_BUILD && [[ -f Carthage/Build/CiteprocRsKit.xcframework.zip ]]; then +if $SKIP_BUILD && [[ -f "$TARGET_DIR/CiteprocRs.xcframework.zip" ]]; then echo -n else build From 25e561ed3b98ca9b0b6e8e63b8d013060e5d27f6 Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Fri, 3 Sep 2021 17:54:23 +1000 Subject: [PATCH 13/16] env-var-configurable binary location in Package.swift --- Package.swift | 108 +++++++++++++++++++++++++++++++++++++++----------- citeproc-rs | 2 +- 2 files changed, 85 insertions(+), 25 deletions(-) diff --git a/Package.swift b/Package.swift index 0e1a740..06cafeb 100644 --- a/Package.swift +++ b/Package.swift @@ -3,36 +3,96 @@ import PackageDescription +// https://gist.github.com/Sorix/21e61347f478ae2e83ef4d8a92d933af +#if os(Linux) +import Glibc +#else +import Darwin.C +#endif + +enum Environment { + static let `default`: Environment = .preBuiltRelease + + case preBuiltRelease + case preBuiltDraft + case localBinary + + struct EnvError: Error { + let msg: String + init(env: String) { + msg = "unrecognised env variable setting CITEPROC_RS_BINARY=\(env)" + } + } + + static func get() throws -> Environment { + if let envPointer = getenv("CITEPROC_RS_BINARY") { + let env = String(cString: envPointer) + switch env { + case "draft": return .preBuiltDraft + case "local": return .localBinary + default: throw EnvError(env: env) + } + } else { + return .default + } + } +} + +func releasedPackage(from version: Version) -> Package.Dependency { + .package( + name: "CiteprocRs", + url: "https://github.com/citeproc-rs/ffi-xcframework", + from: version + ) +} + +let draftBranchPackage: Package.Dependency = .package( + name: "CiteprocRs", + url: "https://github.com/citeproc-rs/ffi-xcframework", + .branch("draft") +) + + +let localTarget: Target = .binaryTarget( + name: "CiteprocRs", + path: "citeproc-rs/target/xcframework/CiteprocRs.xcframework" +) + +var dependencies: [Package.Dependency] = [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), +] +var targets: [Target] = [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "CiteprocRsKit", + dependencies: ["CiteprocRs"], + exclude: ["Info.plist", "Documentation.docc"] + ), + .testTarget( + name: "CiteprocRsKitTests", + dependencies: ["CiteprocRsKit"], + exclude: ["Info.plist"] + ), +] + +switch try Environment.get() { + case .preBuiltRelease: dependencies.append(releasedPackage(from: "1.0.0")); break; + case .preBuiltDraft: dependencies.append(draftBranchPackage); break; + case .localBinary: targets.append(localTarget); break +} + let package = Package( name: "CiteprocRsKit", platforms: [ - .macOS("10.9"), + .macOS("10.10"), .iOS("13.0") ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "CiteprocRsKit", - targets: ["CiteprocRsKit"]), - ], - dependencies: [ - // Dependencies declare other packages that this package depends on. - // .package(url: /* package url */, from: "1.0.0"), + .library(name: "CiteprocRsKit", targets: ["CiteprocRsKit"]), ], - targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages this package depends on. - .binaryTarget( - name: "CiteprocRs", - path: "citeproc-rs/target/xcframework/CiteprocRs.xcframework" - ), - .target( - name: "CiteprocRsKit", - dependencies: ["CiteprocRs"] - ), - .testTarget( - name: "CiteprocRsKitTests", - dependencies: ["CiteprocRsKit"] - ), - ] + dependencies: dependencies, + targets: targets ) diff --git a/citeproc-rs b/citeproc-rs index 33878f4..8d11774 160000 --- a/citeproc-rs +++ b/citeproc-rs @@ -1 +1 @@ -Subproject commit 33878f491f85efb20f31bb514cffcf19c05a03bb +Subproject commit 8d1177462980ff2cb4b9b53e9042efa918c91884 From 9d362661a723d8c18f61e81ffa776b98e08cd020 Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Fri, 3 Sep 2021 18:06:02 +1000 Subject: [PATCH 14/16] document use of env vars in Package.swift --- Package.swift | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 06cafeb..1dfec5b 100644 --- a/Package.swift +++ b/Package.swift @@ -3,13 +3,26 @@ import PackageDescription -// https://gist.github.com/Sorix/21e61347f478ae2e83ef4d8a92d933af +// To use the debug copy built by Scripts/xcframework +// +// export CITEPROC_RS_BINARY=local +// swift test +// +// To test with a draft binary release: +// +// Scripts/release --release --draft --push-binary-repo +// export CITEPROC_RS_BINARY=draft +// # (swift test will fail because the _test_* symbols are not available on release builds) +// swift build + #if os(Linux) import Glibc #else import Darwin.C #endif + +// https://gist.github.com/Sorix/21e61347f478ae2e83ef4d8a92d933af enum Environment { static let `default`: Environment = .preBuiltRelease @@ -55,7 +68,7 @@ let draftBranchPackage: Package.Dependency = .package( let localTarget: Target = .binaryTarget( name: "CiteprocRs", - path: "citeproc-rs/target/xcframework/CiteprocRs.xcframework" + path: "citeproc-rs/target/xcframework/debug/CiteprocRs.xcframework" ) var dependencies: [Package.Dependency] = [ From 0d9a293a99a69af85e6ec2d58374fc4f0ff39d8e Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Fri, 3 Sep 2021 18:21:28 +1000 Subject: [PATCH 15/16] Update binary repo readme --- Scripts/BinaryPackage/README.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Scripts/BinaryPackage/README.md b/Scripts/BinaryPackage/README.md index ec3a99b..2cc2a76 100644 --- a/Scripts/BinaryPackage/README.md +++ b/Scripts/BinaryPackage/README.md @@ -1,16 +1,18 @@ -# CiteprocRsKit-Binary +# ffi-xcframework -This is a binary distribution of -[CiteprocRsKit](https://github.com/cormacrelf/CiteprocRsKit). You can install -this directly with SwiftPM by using this repo -(`https://github.com/cormacrelf/CiteprocRsKit-Binary`) as a dependency. +Distribution repo for pre-built binaries of CiteprocRs.xcframework, the FFI module +from [citeproc-rs](https://github.com/zotero/citeproc-rs), built for use in +the Swift bindings for it, +[CiteprocRsKit](https://github.com/cormacrelf/CiteprocRsKit). +The Package.swift file here simply refers to a download URL on the +CiteprocRsKit repo, along with a checksum. + +There's not much use depending on this directly in SwiftPM -- you want to add +CiteprocRsKit instead. ```swift // set TAG to an appropriate version etc -.package(name: "CiteprocRsKit", url: -"https://github.com/cormacrelf/CiteprocRsKit-Binary", from: "TAG"), +.package(url: "https://github.com/cormacrelf/CiteprocRsKit", from: "TAG"), ``` -Or add it via the Xcode UI. - From 6ec3e2b09b39fce3fcac43a22f392d30a71a025a Mon Sep 17 00:00:00 2001 From: Cormac Relf Date: Fri, 3 Sep 2021 20:06:30 +1000 Subject: [PATCH 16/16] rewrite scripts/release to publish binary repo only --- Package.swift | 1 + Scripts/release | 199 +++++++++++++++++++++++++++++++----------------- 2 files changed, 130 insertions(+), 70 deletions(-) diff --git a/Package.swift b/Package.swift index 1dfec5b..22781b5 100644 --- a/Package.swift +++ b/Package.swift @@ -43,6 +43,7 @@ enum Environment { switch env { case "draft": return .preBuiltDraft case "local": return .localBinary + case "": return .default default: throw EnvError(env: env) } } else { diff --git a/Scripts/release b/Scripts/release index d26be3b..ff405dc 100755 --- a/Scripts/release +++ b/Scripts/release @@ -27,40 +27,36 @@ fi # constants DRAFT_TAG_999="v999.0.0-alpha.999" +BINARY_REPO="citeproc-rs/ffi-xcframework" # variables SKIP_BUILD=false -EXR=false +OVERWRITE_EXISTING_RELEASE=false EXISTING_RELEASE="" -RELEASE=false -TAG="" -PUSH_BINARY_REPO=false IS_DRAFT=false +CLEANUP_DRAFT=false BINARY_BRANCH=master FORCE_PUSH_BINARY="" +BINARY_PRERELEASE="" parse_params() { while [[ "$#" > 0 ]]; do case $1 in --skip-build) SKIP_BUILD=true; shift;; - # --push-tags) PUSH_TAGS=true; OUTPUT="CHANGELOG.md"; shift;; - # --gh-release) SAVE=true; OUTPUT="CHANGELOG.md"; shift;; - --existing-release) - # e.g. you have a draft already (untagged-...) - EXR=true; EXISTING_RELEASE="$2"; shift 2;; - --release) RELEASE=true; shift;; - --tag) TAG="$2"; shift 2;; - --push-binary-repo) PUSH_BINARY_REPO=true; shift;; + # e.g. you have a draft already (untagged-...) + --existing-release) OVERWRITE_EXISTING_RELEASE=true; EXISTING_RELEASE="$2"; shift 2;; + --binary-tag) BINARY_TAG="$2"; shift 2;; --draft) IS_DRAFT=true; shift;; + --cleanup-draft) IS_DRAFT=true; CLEANUP_DRAFT=true; shift;; --|--help) bail "huh";; *) bail "Unknown parameter passed: $1";; esac; done if $IS_DRAFT; then BINARY_BRANCH=draft - TAG="$DRAFT_TAG_999" - RELEASE_TAG="$DRAFT_TAG_999" - FORCE_PUSH_BINARY="--force" + FORCE_PUSH_BINARY="--force-with-lease" + BINARY_TAG="$DRAFT_TAG_999" + BINARY_PRERELEASE="--prerelease" fi - if [ -z "$TAG" ]; then bail "empty tag. provide one with --tag TAG"; fi + if [ -z "$BINARY_TAG" ]; then bail "empty tag. provide one with --binary-tag TAG"; fi } parse_params $@ @@ -84,12 +80,13 @@ build() { } upload() { - set +e - gh release upload "$1" "$TARGET_DIR/CiteprocRs.xcframework.zip" + local RELEASE_TAG="$1" + set -x + gh release upload --repo "$BINARY_REPO" "$RELEASE_TAG" "$TARGET_DIR/CiteprocRs.xcframework.zip" } checksum () { - set +e + set -x # SHORT_SHA=$(git rev-parse --short "$GITHUB_SHA") cd "$TARGET_DIR" touch Package.swift @@ -98,52 +95,86 @@ checksum () { echo $CHECKSUM } -push_binary_repo() { - local TAG="$1" - local RELEASE_TAG="$2" - local CHECKSUM="$3" +cleanup_draft() { + set -x + local BRANCH="draft" local TMP="$(mktemp -d)" trap "rm -rf -- $TMP" EXIT + cd "$TMP" + git clone https://github.com/$BINARY_REPO.git --branch master + cd "$(echo $BINARY_REPO | xargs basename)" - local DL=$(gh api "/repos/cormacrelf/CiteprocRsKit/releases/tags/$RELEASE_TAG" -q '.assets[] | select(.name == "CiteprocRs.xcframework.zip") | .browser_download_url') - # could dereference this locally, but this makes sure we pushed it somewhere - local RELEASE_SHA=$(gh api /repos/cormacrelf/CiteprocRsKit/commits/$TAG -q '.sha') + # https://stackoverflow.com/a/26961416 + git switch -C $BRANCH - if [ -z "$DL" ]; then - bail "release asset not uploaded: $DL" + if $IS_DRAFT; then + # delete the draft tags from the binary repo + git push origin ":$DRAFT_TAG_999" || echo "no tag $DRAFT_TAG_999 on remote" + git tag -d "$DRAFT_TAG_999" || echo "no tag $DRAFT_TAG_999 locally" fi +} - if [ -z "$RELEASE_SHA" ]; then - bail "tag $TAG or commit referenced by tag $TAG was not uploaded to GitHub" - fi +push_binary_repo_core() { + set -x + local TAG="$1" + local BRANCH="$2" + local ZIP_URL="$3" + local ZIP_CHECKSUM="$4" + local MSG_SHA="$5" + local MSG_URL="$6" + local TMP="$(mktemp -d)" + trap "rm -rf -- $TMP" EXIT cd "$TMP" - git clone https://github.com/citeproc-rs/ffi-xcframework.git --branch master - cd ffi-xcframework + git clone https://github.com/$BINARY_REPO.git --branch master + cd "$(echo $BINARY_REPO | xargs basename)" + # https://stackoverflow.com/a/26961416 - git switch -c $BINARY_BRANCH + git switch -C $BRANCH + + if $IS_DRAFT; then + # delete the draft tags from the binary repo + git push origin ":$DRAFT_TAG_999" || echo "no tag $DRAFT_TAG_999 on remote" + git tag -d "$DRAFT_TAG_999" || echo "no tag $DRAFT_TAG_999 locally" + fi + cp -R "$DIR"/Scripts/BinaryPackage/* . sed \ - -e "s,XCFRAMEWORK_ZIP_URL,$DL,i" \ - -e "s,XCFRAMEWORK_ZIP_CHECKSUM,$CHECKSUM,i" \ + -e "s,XCFRAMEWORK_ZIP_URL,$ZIP_URL,i" \ + -e "s,XCFRAMEWORK_ZIP_CHECKSUM,$ZIP_CHECKSUM,i" \ < "$DIR/Scripts/BinaryPackage/Package.swift" \ > "./Package.swift" git add . - git commit -m "release $TAG for $RELEASE_SHA" \ - -m "https://github.com/cormacrelf/CiteprocRsKit/releases/tag/$TAG" - git tag -f -a -m "release $TAG for $RELEASE_SHA" $TAG + git commit -m "release $TAG for $MSG_SHA" \ + -m "$MSG_URL" + git tag -f -a -m "release $TAG for $MSG_SHA" $TAG echo $(pwd) - git push $FORCE_PUSH_BINARY origin $BINARY_BRANCH - git push --force --tags + git push $FORCE_PUSH_BINARY origin $BRANCH + git push --force-with-lease --tags cd "$DIR" } +push_binary_repo_v2() { + set -x + local CRS_SHA="$(cd "$DIR/citeproc-rs" && git rev-parse HEAD)" + local CRS_SHA_SHORT="$(cd "$DIR/citeproc-rs" && git rev-parse --short HEAD)" + + local GIT_TAG="$1" + local ZIP_URL="https://github.com/$BINARY_REPO/releases/download/$GIT_TAG/CiteprocRs.xcframework.zip" + local ZIP_CHECKSUM="$CHECKSUM" + local MSG_SHA="zotero/citeproc-rs commit $CRS_SHA_SHORT" + local MSG_URL="https://github.com/zotero/citeproc-rs/tree/$CRS_SHA" + + push_binary_repo_core "$GIT_TAG" "$BINARY_BRANCH" "$ZIP_URL" "$ZIP_CHECKSUM" "$MSG_SHA" "$MSG_URL" +} + edit_release() { + set -x local TAG="$1" local CHECKSUM="$2" - local RELEASE=$(gh api /repos/cormacrelf/CiteprocRsKit/releases/tags/$TAG -q '.url') - local BODY=$(gh api /repos/cormacrelf/CiteprocRsKit/releases/tags/$TAG -q '.body') - local DL=$(gh api /repos/cormacrelf/CiteprocRsKit/releases/tags/$TAG -q '.assets[] | select(.name == "CiteprocRs.xcframework.zip") | .browser_download_url') + local RELEASE=$(gh api /repos/$BINARY_REPO/releases/tags/$TAG -q '.url') + local BODY=$(gh api /repos/$BINARY_REPO/releases/tags/$TAG -q '.body') + local DL=$(gh api /repos/$BINARY_REPO/releases/tags/$TAG -q '.assets[] | select(.name == "CiteprocRs.xcframework.zip") | .browser_download_url') if ! (echo $BODY | grep -q $CHECKSUM); then echo "patching body" gh api -X PATCH $RELEASE -f "body=$BODY\n\nChecksum: $CHECKSUM" @@ -151,37 +182,65 @@ edit_release() { echo $DL } -if $SKIP_BUILD && [[ -f "$TARGET_DIR/CiteprocRs.xcframework.zip" ]]; then - echo -n -else - build -fi - -CHECKSUM=$(checksum) +function binary_release_and_upload() { + set -x + local GIT_TAG="$1" -if $RELEASE; then - if $IS_DRAFT; then - gh release delete "$RELEASE_TAG" || echo "no draft release to delete; continuing" - git push origin ":$TAG" || echo "no tag $DRAFT_TAG_999 on remote" - git tag -d "$TAG" || echo "no tag $DRAFT_TAG_999 locally" - git tag -m 'draft/test release' "$TAG" - git push origin "$TAG" - RELEASE_TAG=$(gh release create "$TAG" -n "Checksum: $CHECKSUM" | xargs basename) - upload "$RELEASE_TAG" - elif $EXR; then - RELEASE_TAG="$EXISTING_RELEASE" - upload "$RELEASE_TAG" - edit_release "$RELEASE_TAG" "$CHECKSUM" + # create a draft release, returns "untagged-$SOME_HASH" + local DRAFT_RELEASE_TAG="" + if $OVERWRITE_EXISTING_RELEASE; then + DRAFT_RELEASE_TAG="$EXISTING_RELEASE" else - RELEASE_TAG=$(gh release create "$TAG" -n "Checksum: $CHECKSUM" | xargs basename) - upload "$RELEASE_TAG" + DRAFT_RELEASE_TAG=$(gh release create \ + "$BINARY_TAG" \ + --repo "$BINARY_REPO" \ + --draft \ + $BINARY_PRERELEASE \ + -n "Checksum: $CHECKSUM" \ + | xargs basename) + fi + + # upload the zip file there + upload "$DRAFT_RELEASE_TAG" + + # push the binary repo with the url and the checksum already in it. + # that means for a short moment, the url referred to will point to a 404. + push_binary_repo_v2 "$BINARY_TAG" + + local DRAFT_RELEASE_URL="/repos/$BINARY_REPO/releases/tags/$DRAFT_RELEASE_TAG" + + local RELEASE_ID=$(gh api "/repos/$BINARY_REPO/releases/tags/$DRAFT_RELEASE_TAG" -q ".id") + echo "publishing release with release_id=$RELEASE_ID" + + # publish the draft release and set its tag name to be a real tag + # see ZIP_URL above + local REAL_ZIP_URL=$(gh api -X PATCH "/repos/$BINARY_REPO/releases/$RELEASE_ID" -F 'draft=false' -F "tag_name=$GIT_TAG" -q '.assets[] | .browser_download_url') + set +x + local GUESSED_ZIP_URL="https://github.com/$BINARY_REPO/releases/download/$GIT_TAG/CiteprocRs.xcframework.zip" + + if ! [ "$REAL_ZIP_URL" = "$GUESSED_ZIP_URL" ]; then + echo " real zip url: $REAL_ZIP_URL" + echo "guessed zip url: $GUESSED_ZIP_URL" + bail "real zip url did not match guessed" fi + +} + +if $IS_DRAFT; then + gh release delete --repo "$BINARY_REPO" "$BINARY_TAG" || echo "no draft release to delete; continuing" fi -if $PUSH_BINARY_REPO && ! [ -z "$TAG" ]; then - if [ -z "${RELEASE_TAG:-}" ]; then - bail "release tag unspecified" +if $CLEANUP_DRAFT; then + cleanup_draft +else + if $SKIP_BUILD && [[ -f "$TARGET_DIR/CiteprocRs.xcframework.zip" ]]; then + echo -n + else + build fi - push_binary_repo "$TAG" "$RELEASE_TAG" "$CHECKSUM" + CHECKSUM=$(checksum) + + binary_release_and_upload "$BINARY_TAG" fi +