Skip to content

Commit 70d62b4

Browse files
committed
Add build macro plugin runner
1 parent efff693 commit 70d62b4

File tree

2 files changed

+145
-15
lines changed

2 files changed

+145
-15
lines changed

.github/workflows/release.yml

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: Build and Release Macro Plugin
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build-arm64:
9+
name: Build arm64
10+
runs-on: macos-15
11+
steps:
12+
- name: Git Checkout
13+
uses: actions/checkout@v4
14+
15+
- name: Build arm64 macro plugin
16+
run: |
17+
swift build -c release --product ReerCodableMacros
18+
cp .build/release/ReerCodableMacros-tool ./ReerCodableMacros-arm64
19+
file ./ReerCodableMacros-arm64
20+
21+
- name: Upload arm64 artifact
22+
uses: actions/upload-artifact@v4
23+
with:
24+
name: macro-plugin-arm64
25+
path: ReerCodableMacros-arm64
26+
27+
build-x86_64:
28+
name: Build x86_64
29+
runs-on: macos-15-intel
30+
steps:
31+
- name: Git Checkout
32+
uses: actions/checkout@v4
33+
34+
- name: Build x86_64 macro plugin
35+
run: |
36+
swift build -c release --product ReerCodableMacros
37+
cp .build/release/ReerCodableMacros-tool ./ReerCodableMacros-x86_64
38+
file ./ReerCodableMacros-x86_64
39+
40+
- name: Upload x86_64 artifact
41+
uses: actions/upload-artifact@v4
42+
with:
43+
name: macro-plugin-x86_64
44+
path: ReerCodableMacros-x86_64
45+
46+
create-universal-and-upload:
47+
name: Create Universal Macro Plugin and Upload
48+
needs: [build-arm64, build-x86_64]
49+
runs-on: macos-15
50+
permissions:
51+
contents: write
52+
steps:
53+
- name: Git Checkout
54+
uses: actions/checkout@v4
55+
56+
- name: Download arm64 artifact
57+
uses: actions/download-artifact@v4
58+
with:
59+
name: macro-plugin-arm64
60+
path: ./artifacts
61+
62+
- name: Download x86_64 artifact
63+
uses: actions/download-artifact@v4
64+
with:
65+
name: macro-plugin-x86_64
66+
path: ./artifacts
67+
68+
- name: Create Universal Macro Plugin and Artifact Bundle
69+
run: |
70+
cd artifacts
71+
72+
# Create Universal Macro Plugin
73+
lipo -create ReerCodableMacros-arm64 ReerCodableMacros-x86_64 \
74+
-output ReerCodableMacros
75+
76+
echo "=== Universal Macro Plugin Info ==="
77+
lipo -info ReerCodableMacros
78+
file ReerCodableMacros
79+
80+
# Create artifact bundle structure
81+
mkdir -p ReerCodableMacros.artifactbundle/macos/bin
82+
cp ReerCodableMacros ReerCodableMacros.artifactbundle/macos/bin/
83+
84+
# Create info.json
85+
cat > ReerCodableMacros.artifactbundle/info.json << EOF
86+
{
87+
"schemaVersion": "1.0",
88+
"artifacts": {
89+
"ReerCodableMacros": {
90+
"version": "${{ github.ref_name }}",
91+
"type": "executable",
92+
"variants": [
93+
{
94+
"path": "macos/bin/ReerCodableMacros",
95+
"supportedTriples": ["x86_64-apple-macosx", "arm64-apple-macosx"]
96+
}
97+
]
98+
}
99+
}
100+
}
101+
EOF
102+
103+
# Create zip archive
104+
zip -r ReerCodableMacros.artifactbundle.zip ReerCodableMacros.artifactbundle
105+
106+
echo "=== Artifact Bundle Contents ==="
107+
unzip -l ReerCodableMacros.artifactbundle.zip
108+
109+
- name: Upload to GitHub Release
110+
uses: softprops/action-gh-release@v2
111+
with:
112+
files: |
113+
artifacts/ReerCodableMacros
114+
artifacts/ReerCodableMacros.artifactbundle.zip

ReerCodable.podspec

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,43 @@ Pod::Spec.new do |s|
3030

3131
s.source_files = 'Sources/ReerCodable/**/*'
3232

33-
s.preserve_paths = ["Package.swift", "Sources/ReerCodableMacros", "Tests"]
33+
s.preserve_paths = ["Package.swift", "Sources/ReerCodableMacros", "Tests", "MacroPlugin"]
3434

3535
s.pod_target_xcconfig = {
36-
'OTHER_SWIFT_FLAGS' => '-Xfrontend -load-plugin-executable -Xfrontend $(PODS_BUILD_DIR)/ReerCodable/release/ReerCodableMacros-tool#ReerCodableMacros'
36+
'OTHER_SWIFT_FLAGS' => '-Xfrontend -load-plugin-executable -Xfrontend ${PODS_ROOT}/ReerCodable/MacroPlugin/ReerCodableMacros#ReerCodableMacros'
3737
}
3838

3939
s.user_target_xcconfig = {
40-
'OTHER_SWIFT_FLAGS' => '-Xfrontend -load-plugin-executable -Xfrontend $(PODS_BUILD_DIR)/ReerCodable/release/ReerCodableMacros-tool#ReerCodableMacros'
40+
'OTHER_SWIFT_FLAGS' => '-Xfrontend -load-plugin-executable -Xfrontend ${PODS_ROOT}/ReerCodable/MacroPlugin/ReerCodableMacros#ReerCodableMacros'
4141
}
4242

43-
script = <<-SCRIPT
44-
env -i PATH="$PATH" "$SHELL" -l -c "swift build -c release --package-path \\"$PODS_TARGET_SRCROOT\\" --build-path \\"${PODS_BUILD_DIR}/ReerCodable\\""
45-
SCRIPT
46-
47-
s.script_phase = {
48-
:name => 'Build ReerCodable macro plugin',
49-
:script => script,
50-
:execution_position => :before_compile,
51-
:output_files => [
52-
'$(PODS_BUILD_DIR)/ReerCodable/release/ReerCodableMacros-tool'
53-
]
54-
}
43+
# Download prebuilt universal macro plugin from GitHub Release
44+
s.prepare_command = <<-CMD
45+
set -e
46+
47+
PLUGIN_DIR="MacroPlugin"
48+
PLUGIN_NAME="ReerCodableMacros"
49+
VERSION="#{s.version}"
50+
DOWNLOAD_URL="https://github.com/reers/ReerCodable/releases/download/${VERSION}/${PLUGIN_NAME}"
51+
52+
mkdir -p "${PLUGIN_DIR}"
53+
54+
echo "Downloading prebuilt macro plugin from ${DOWNLOAD_URL}..."
55+
56+
if curl -L -f -o "${PLUGIN_DIR}/${PLUGIN_NAME}" "${DOWNLOAD_URL}"; then
57+
chmod +x "${PLUGIN_DIR}/${PLUGIN_NAME}"
58+
echo "Successfully downloaded prebuilt macro plugin"
59+
file "${PLUGIN_DIR}/${PLUGIN_NAME}"
60+
else
61+
echo "Warning: Failed to download prebuilt macro plugin, will build from source..."
62+
63+
# Fallback: build from source
64+
swift build -c release --package-path "." --product ReerCodableMacros
65+
cp ".build/release/ReerCodableMacros-tool" "${PLUGIN_DIR}/${PLUGIN_NAME}"
66+
chmod +x "${PLUGIN_DIR}/${PLUGIN_NAME}"
67+
echo "Built macro plugin from source"
68+
file "${PLUGIN_DIR}/${PLUGIN_NAME}"
69+
fi
70+
CMD
5571

5672
end

0 commit comments

Comments
 (0)