Skip to content

Commit 627112a

Browse files
committed
try to build gdisk
1 parent 4272ad8 commit 627112a

File tree

4 files changed

+186
-0
lines changed

4 files changed

+186
-0
lines changed

.github/workflows/build.yml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Build on-device support tools
2+
3+
on:
4+
push:
5+
paths:
6+
- 'tools/**'
7+
workflow_dispatch:
8+
9+
jobs:
10+
build-darwin:
11+
strategy:
12+
matrix:
13+
include:
14+
- arch: x86_64
15+
gnu_triple: aarch64-apple-darwin
16+
os: iphoneos
17+
minos: 11.0
18+
- arch: arm64
19+
gnu_triple: aarch64-apple-darwin
20+
os: appletvos
21+
minos: 11.0
22+
runs-on: macos-15
23+
env:
24+
GPTFDISK_VERSION: 1.0.10
25+
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v4
29+
with:
30+
fetch-depth: 0
31+
32+
- name: Install dependencies (packages)
33+
run: |
34+
brew install make
35+
curl -LO https://github.com/ProcursusTeam/ldid/releases/download/v2.1.5-procursus7/ldid_macosx_x86_64
36+
sudo install -m755 ldid_macosx_x86_64 /usr/local/bin/ldid
37+
38+
- name: Download dependencies
39+
run: |
40+
echo "SDK=$(xcrun -sdk ${{ matrix.os }} --show-sdk-path)" >> $GITHUB_ENV
41+
curl -LO https://sourceforge.net/projects/gptfdisk/files/gptfdisk/${{ env.GPTFDISK_VERSION }}/gptfdisk-${{ env.GPTFDISK_VERSION }}.tar.gz
42+
tar -xf gptfdisk-${{ env.GPTFDISK_VERSION }}.tar.gz
43+
44+
- name: Setup environment
45+
run: |
46+
mkdir sysroot out
47+
echo "DESTDIR=$(pwd)/sysroot" >> $GITHUB_ENV
48+
echo "PREFIX=/usr/local" >> $GITHUB_ENV
49+
echo "PKG_CONFIG_PATH=$(pwd)/sysroot/usr/local/lib/pkgconfig" >> $GITHUB_ENV
50+
echo "CONFIGURE_ARGS=--prefix=/usr/local --disable-shared --enable-static --build=x86_64-apple-darwin --host=${{ matrix.gnu_triple }}" >> $GITHUB_ENV
51+
echo "CC=$(xcrun --find cc)" >> $GITHUB_ENV
52+
echo "CXX=$(xcrun --find c++)" >> $GITHUB_ENV
53+
echo "CPP=$(xcrun --find cc) -E" >> $GITHUB_ENV
54+
echo "CFLAGS=-g -Os -isystem ${{ env.SDK }}/usr/include/c++/v1 -arch ${{ matrix.arch }} -m${{ matrix.os }}-version-min=${{ matrix.minos }} -isysroot ${{ env.SDK }} -isystem $(pwd)/sysroot/usr/local/include -Os -g -flto=full -Wl,-object_path_lto,lto.o -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64" >> $GITHUB_ENV
55+
echo "CPPFLAGS=-g -Os -isystem ${{ env.SDK }}/usr/include/c++/v1 -arch ${{ matrix.arch }} -m${{ matrix.os }}-version-min=${{ matrix.minos }} -isysroot ${{ env.SDK }} -isystem $(pwd)/sysroot/usr/local/include -Wno-error-implicit-function-declaration -Os -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64" >> $GITHUB_ENV
56+
echo "CXXFLAGS=-stdlib=libc++ -g -Os -isystem$(TARGET_SYSROOT)/usr/include/c++/v1 -isysroot ${{ env.SDK }} -arch ${{ matrix.arch }} -m${{ matrix.os }}-version-min=${{ matrix.minos }} -isystem $(pwd)/sysroot/usr/local/include -Os -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64" >> $GITHUB_ENV
57+
echo "LDFLAGS=-g -Wl,-dead_strip -arch ${{ matrix.arch }} -isysroot ${{ env.SDK }} -m${{ matrix.os }}-version-min=${{ matrix.minos }} -L$(pwd)/sysroot/usr/local/lib" >> $GITHUB_ENV
58+
echo "CFLAGS_FOR_BUILD=-arch $(uname -m) -isysroot $(xcrun -sdk macosx --show-sdk-path) -Os" >> $GITHUB_ENV
59+
echo "CXXFLAGS_FOR_BUILD=-stdlib=libc++ -arch $(uname -m) -isysroot $(xcrun -sdk macosx --show-sdk-path) -Os" >> $GITHUB_ENV
60+
echo "CPPFLAGS_FOR_BUILD=-arch $(uname -m) -isysroot $(xcrun -sdk macosx --show-sdk-path) -Wno-error-implicit-function-declaration -Os" >> $GITHUB_ENV
61+
echo "LDFLAGS_FOR_BUILD=-Wl,-dead_strip" >> $GITHUB_ENV
62+
63+
- name: Prepare headers
64+
if: matrix.os != 'macosx'
65+
run: |
66+
mkdir -p sysroot/{{,System}/Library/Frameworks,/usr/{local/include/{bsm,objc,os/internal,sys,firehose,CoreFoundation,FSEvents,IOKit/kext,libkern,kern,arm,{mach/,}machine,CommonCrypto,Security,CoreSymbolication,Kernel/{kern,IOKit,libkern},rpc,rpcsvc,xpc/private,ktrace,mach-o,dispatch},lib/pkgconfig,/local/lib}}
67+
MACOSX_SYSROOT=$(xcrun -sdk macosx --show-sdk-path)
68+
TARGET_SYSROOT=$(xcrun -sdk ${{ matrix.os }} --show-sdk-path)
69+
cp -af ${MACOSX_SYSROOT}/usr/include/{arpa,bsm,hfs,net,xpc,netinet,servers,timeconv.h,launch.h} sysroot/usr/local/include
70+
cp -af ${MACOSX_SYSROOT}/usr/include/objc/objc-runtime.h sysroot/usr/local/include/objc
71+
cp -af ${MACOSX_SYSROOT}/usr/include/libkern/{OSDebug.h,OSKextLib.h,OSReturn.h,OSThermalNotification.h,OSTypes.h,machine} sysroot/usr/local/include/libkern
72+
cp -af ${MACOSX_SYSROOT}/usr/include/kern sysroot/usr/local/include
73+
cp -af ${MACOSX_SYSROOT}/usr/include/sys/{tty*,ptrace,kern*,random,reboot,user,vnode,disk,vmmeter,conf}.h sysroot/usr/local/include/sys
74+
cp -af ${MACOSX_SYSROOT}/System/Library/Frameworks/Kernel.framework/Versions/Current/Headers/sys/disklabel.h sysroot/usr/local/include/sys
75+
cp -af ${MACOSX_SYSROOT}/System/Library/Frameworks/IOKit.framework/Headers/{AppleConvergedIPCKeys.h,IOBSD.h,IOCFBundle.h,IOCFPlugIn.h,IOCFURLAccess.h,IOKitServer.h,IORPC.h,IOSharedLock.h,IOUserServer.h,audio,avc,firewire,graphics,hid,hidsystem,i2c,iokitmig.h,kext,ndrvsupport,network,ps,pwr_mgt,sbp2,scsi,serial,storage,stream,usb,video} sysroot/usr/local/include/IOKit
76+
cp -af ${MACOSX_SYSROOT}/System/Library/Frameworks/Security.framework/Headers/{mds_schema,oidsalg,SecKeychainSearch,certextensions,Authorization,eisl,SecDigestTransform,SecKeychainItem,oidscrl,cssmcspi,CSCommon,cssmaci,SecCode,CMSDecoder,oidscert,SecRequirement,AuthSession,SecReadTransform,oids,cssmconfig,cssmkrapi,SecPolicySearch,SecAccess,cssmtpi,SecACL,SecEncryptTransform,cssmapi,cssmcli,mds,x509defs,oidsbase,SecSignVerifyTransform,cssmspi,cssmkrspi,SecTask,cssmdli,SecAsn1Coder,cssm,SecTrustedApplication,SecCodeHost,SecCustomTransform,oidsattr,SecIdentitySearch,cssmtype,SecAsn1Types,emmtype,SecTransform,SecTrustSettings,SecStaticCode,emmspi,SecTransformReadTransform,SecKeychain,SecDecodeTransform,CodeSigning,AuthorizationPlugin,cssmerr,AuthorizationTags,CMSEncoder,SecEncodeTransform,SecureDownload,SecAsn1Templates,AuthorizationDB,SecCertificateOIDs,cssmapple}.h sysroot/usr/local/include/Security
77+
cp -af ${MACOSX_SYSROOT}/usr/include/{ar,bootstrap,launch,libc,libcharset,localcharset,nlist,NSSystemDirectories,tzfile,vproc}.h sysroot/usr/local/include
78+
cp -af ${MACOSX_SYSROOT}/usr/include/mach/{*.defs,{mach_vm,shared_region}.h} sysroot/usr/local/include/mach
79+
cp -af ${MACOSX_SYSROOT}/usr/include/mach/machine/*.defs sysroot/usr/local/include/mach/machine
80+
cp -af ${MACOSX_SYSROOT}/usr/include/rpc/pmap_clnt.h sysroot/usr/local/include/rpc
81+
cp -af ${MACOSX_SYSROOT}/usr/include/rpcsvc/yp{_prot,clnt}.h sysroot/usr/local/include/rpcsvc
82+
cp -af ${TARGET_SYSROOT}/usr/include/mach/machine/thread_state.h sysroot/usr/local/include/mach/machine
83+
cp -af ${TARGET_SYSROOT}/usr/include/mach/arm sysroot/usr/local/include/mach
84+
cp -af ${MACOSX_SYSROOT}/System/Library/Frameworks/IOKit.framework/Headers/* sysroot/usr/local/include/IOKit
85+
gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < ${TARGET_SYSROOT}/usr/include/stdlib.h > sysroot/usr/local/include/stdlib.h
86+
gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < ${TARGET_SYSROOT}/usr/include/time.h > sysroot/usr/local/include/time.h
87+
gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < ${TARGET_SYSROOT}/usr/include/unistd.h > sysroot/usr/local/include/unistd.h
88+
gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < ${TARGET_SYSROOT}/usr/include/mach/task.h > sysroot/usr/local/include/mach/task.h
89+
gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < ${TARGET_SYSROOT}/usr/include/mach/mach_host.h > sysroot/usr/local/include/mach/mach_host.h
90+
gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < ${TARGET_SYSROOT}/usr/include/ucontext.h > sysroot/usr/local/include/ucontext.h
91+
gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < ${TARGET_SYSROOT}/usr/include/signal.h > sysroot/usr/local/include/signal.h
92+
gsed -E /'__API_UNAVAILABLE'/d < ${TARGET_SYSROOT}/usr/include/pthread.h > sysroot/usr/local/include/pthread.h
93+
gsed -i -E s/'__API_UNAVAILABLE\(.*\)'// sysroot/usr/local/include/IOKit/IOKitLib.h
94+
95+
- name: Build resize tool
96+
run: |
97+
${{ env.CC }} ${{ env.CFLAGS }} ${{ env.LDFLAGS}} tools/resize.c -o out/resize_apfs
98+
ldid -Stools/resize.xml out/resize_apfs
99+
100+
- name: Build gdisk
101+
run: |
102+
cd gptfdisk-${{ env.GPTFDISK_VERSION }}
103+
sed -i -e 's|/local/|/meow/|g' Makefile.mac
104+
gmake -j$(sysctl -n hw.ncpu) -f Makefile.mac gdisk
105+
ldid -S../tools/gdisk.xml gdisk
106+
install -m755 gdisk ../out
107+
108+
- uses: actions/upload-artifact@v4
109+
with:
110+
name: hoolock-support
111+
path: |
112+
out/gdisk
113+
out/resize_apfs

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.DS_Store
2+
tools/resize

tools/resize.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <stdio.h>
2+
#include <stdint.h>
3+
#include <dlfcn.h>
4+
#include <stdlib.h>
5+
#include <mach/mach.h>
6+
#include <TargetConditionals.h>
7+
8+
#if TARGET_OS_OSX || TARGET_OS_SIMULATOR
9+
#define APFS_FW_PATH "/System/Library/PrivateFrameworks/APFS.framework/Versions/A/APFS"
10+
#else
11+
#define APFS_FW_PATH "/System/Library/PrivateFrameworks/APFS.framework/APFS"
12+
#endif
13+
14+
int (*APFSContainerResize)(const char *bsdname, uint64_t newSize);
15+
16+
int main(int argc, const char * argv[]) {
17+
size_t new_size;
18+
char* endptr;
19+
20+
if (argc != 3) {
21+
fprintf(stderr, "usage: %s <APFS container BSD name> <new size in bytes>\n", argv[0]);
22+
return -1;
23+
}
24+
25+
new_size = strtoull(argv[2], &endptr, 0);
26+
27+
if (argv[2] == endptr) {
28+
fprintf(stderr, "Invalid new size given\n");
29+
return -1;
30+
}
31+
32+
void *handle = dlopen(APFS_FW_PATH, RTLD_LAZY);
33+
34+
if (!handle) {
35+
fprintf(stderr, "Could not load APFS.framework: %s", dlerror());
36+
return -1;
37+
}
38+
39+
APFSContainerResize = dlsym(handle, "APFSContainerResize");
40+
if (!APFSContainerResize) {
41+
fprintf(stderr, "Function APFSContainerResize not found: %s", dlerror());
42+
dlclose(handle);
43+
return -1;
44+
}
45+
46+
printf("About to resize %s to %s bytes, in an online resize, device will become unresponsive.\n", argv[1], argv[2]);
47+
48+
int result = APFSContainerResize(argv[1], new_size);
49+
if (result != 0) {
50+
fprintf(stderr,"APFSContainerResize failed: %d: %s\n", result, mach_error_string(result));
51+
return -1;
52+
}
53+
54+
printf("The operation completed successfully\n");
55+
56+
dlclose(handle);
57+
return 0;
58+
}

tools/resize.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>com.apple.security.iokit-user-client-class</key>
6+
<array>
7+
<string>AppleAPFSUserClient</string>
8+
</array>
9+
<key>com.apple.private.security.no-container</key>
10+
<true/>
11+
<key>platform-application</key>
12+
<true/>
13+
</dict>
14+
</plist>

0 commit comments

Comments
 (0)