]> git.cameronkatri.com Git - ldid.git/blob - .github/workflows/build.yml
fd82d0738252ecf296124f14a182b02ced9822dd
[ldid.git] / .github / workflows / build.yml
1 name: build
2 on:
3 push:
4 paths:
5 - '*.c'
6 - '*.cpp'
7 - '.github/workflows/*'
8 - 'Makefile'
9 pull_request:
10 paths:
11 - '*.c'
12 - '*.cpp'
13 - '.github/workflows/*'
14 - 'Makefile'
15 workflow_dispatch:
16 release:
17 types:
18 - created
19
20 env:
21 LIBPLIST_VERSION: 2.2.0
22 OPENSSL_VERSION: 3.0.0
23 SCCACHE_VERSION: 0.2.15
24
25 jobs:
26 build-linux:
27 runs-on: ubuntu-latest
28 strategy:
29 matrix:
30 triple:
31 - arm-linux-musleabi
32 - aarch64-linux-musl
33 - i486-linux-musl
34 - riscv64-linux-musl
35 - x86_64-linux-musl
36 env:
37 TOOLCHAIN: ${{ matrix.triple }}-cross
38 TRIPLE: ${{ matrix.triple }}
39
40 steps:
41 - uses: actions/checkout@v1
42 with:
43 submodules: recursive
44
45 - uses: actions/cache@v2
46 with:
47 path: |
48 ~/.cache/sccache
49 ~/dep_src
50 key: build-linux-${{ matrix.triple }}-${{ env.GITHUB_SHA }}
51 restore-keys: |
52 build-linux-${{ matrix.triple }}
53
54 - name: setup environment
55 run: |
56 export DOWNLOAD_PATH=${HOME}/dep_src
57 export DEP_PATH=${HOME}/build
58 mkdir -p ${DOWNLOAD_PATH} ${DEP_PATH}
59 echo "DOWNLOAD_PATH=${DOWNLOAD_PATH}" >> $GITHUB_ENV
60 echo "DEP_PATH=${DEP_PATH}" >> $GITHUB_ENV
61 echo "ARCH=$(echo ${{ matrix.triple }} | cut -d- -f 1)" >> $GITHUB_ENV
62
63 - name: setup toolchain
64 run: |
65 # Download Toolchain
66 wget -q -nc -P ${DOWNLOAD_PATH} https://musl.cc/${TOOLCHAIN}.tgz
67 tar xf ${DOWNLOAD_PATH}/${TOOLCHAIN}.tgz -C ${HOME}
68
69 # Download sccache
70 wget -q -nc -P ${DOWNLOAD_PATH} \
71 https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz
72 tar xf ${DOWNLOAD_PATH}/sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz -C ${HOME}
73 mv ${HOME}/sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl/sccache ${HOME}/${TOOLCHAIN}/bin
74 chmod +x ${HOME}/${TOOLCHAIN}/bin/sccache
75
76 echo "${HOME}/${TOOLCHAIN}/bin" >> $GITHUB_PATH
77 echo "CC=sccache ${TRIPLE}-gcc" >> $GITHUB_ENV
78 echo "CXX=sccache ${TRIPLE}-g++" >> $GITHUB_ENV
79 echo "AR=${TRIPLE}-gcc-ar" >> $GITHUB_ENV
80 echo "NM=${TRIPLE}-gcc-nm" >> $GITHUB_ENV
81 echo "RANLIB=${TRIPLE}-gcc-ranlib" >> $GITHUB_ENV
82 echo "CFLAGS=-Os -fPIC -fno-pie -no-pie -static -flto -ffunction-sections -fdata-sections" >> $GITHUB_ENV
83 echo "LDFLAGS=-Wl,--gc-sections -Wl,-strip-all -flto" >> $GITHUB_ENV
84
85 - name: build libplist
86 run: |
87 wget -q -nc -P ${DOWNLOAD_PATH} https://github.com/libimobiledevice/libplist/releases/download/${LIBPLIST_VERSION}/libplist-${LIBPLIST_VERSION}.tar.bz2
88 tar xf ${DOWNLOAD_PATH}/libplist-${LIBPLIST_VERSION}.tar.bz2 -C ${DEP_PATH}
89 cd ${DEP_PATH}/libplist-${LIBPLIST_VERSION}
90 ./configure --host=${TRIPLE} --prefix=/usr --without-cython --enable-static --disable-shared
91 make -j$(nproc)
92
93 echo "CPPFLAGS=${CPPFLAGS} -I${DEP_PATH}/libplist-${LIBPLIST_VERSION}/include" >> $GITHUB_ENV
94 echo "LIBPLIST_LIB=${DEP_PATH}/libplist-${LIBPLIST_VERSION}/src/.libs/libplist-2.0.a" >> $GITHUB_ENV
95
96 - name: build openssl
97 run: |
98 export PLATFORM="linux-${ARCH}"
99 case ${ARCH} in
100 arm)
101 export PLATFORM="linux-generic32"
102 ;;
103 i486)
104 export PLATFORM="linux-x86"
105 ;;
106 riscv64)
107 export PLATFORM="linux64-riscv64"
108 ;;
109 esac
110
111 wget -q -nc -P ${DOWNLOAD_PATH} https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
112 tar xf ${DOWNLOAD_PATH}/openssl-${OPENSSL_VERSION}.tar.gz -C ${DEP_PATH}
113 cd ${DEP_PATH}/openssl-${OPENSSL_VERSION}
114 ./config --prefix=/usr --static -static ${PLATFORM}
115 make -j$(nproc) build_generated libcrypto.a
116
117 echo "CPPFLAGS=${CPPFLAGS} -I${DEP_PATH}/openssl-${OPENSSL_VERSION}/include" >> $GITHUB_ENV
118 echo "LIBCRYPTO_LIB=${DEP_PATH}/openssl-${OPENSSL_VERSION}/libcrypto.a" >> $GITHUB_ENV
119
120 - name: build
121 run: |
122 export LDID_VERSION=$(echo "$(git describe --tags --abbrev=0)")
123 make -j$(nproc) \
124 VERSION="${LDID_VERSION}" \
125 LDFLAGS="-static -static-libstdc++ ${LDFLAGS}" \
126 LIBS="${LIBPLIST_LIB} ${LIBCRYPTO_LIB}"
127 ${TRIPLE}-strip ldid
128
129 - uses: actions/upload-artifact@v1
130 with:
131 name: ldid_linux_${{ env.ARCH }}
132 path: ldid
133
134 - name: Upload Release Asset Linux
135 uses: actions/upload-release-asset@v1
136 if: ${{ github.event_name == 'release' }}
137 env:
138 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
139 with:
140 upload_url: ${{ github.event.release.upload_url }}
141 asset_path: ldid
142 asset_name: ldid_linux_${{ env.ARCH }}
143 asset_content_type: application/octet-stream
144
145 build-macos:
146 runs-on: macos-11
147 strategy:
148 matrix:
149 arch:
150 - x86_64
151 - arm64
152 env:
153 ARCH: ${{ matrix.arch }}
154 steps:
155 - uses: actions/checkout@v1
156 with:
157 submodules: recursive
158
159 - uses: actions/cache@v2
160 with:
161 path: |
162 ~/Library/Caches/Mozilla.sccache
163 ~/dep_src
164 key: build-macos-${{ matrix.arch }}-${ { env.GITHUB_SHA } }
165 restore-keys: |
166 build-macos-${{ matrix.arch }}-
167
168 - name: setup environment
169 run: |
170 export DOWNLOAD_PATH=${HOME}/dep_src
171 export DEP_PATH=${HOME}/build
172 mkdir -p ${DOWNLOAD_PATH} ${DEP_PATH}
173 echo "DOWNLOAD_PATH=${DOWNLOAD_PATH}" >> $GITHUB_ENV
174 echo "DEP_PATH=${DEP_PATH}" >> $GITHUB_ENV
175
176 if [ "${ARCH}" = "arm64" ]; then
177 echo "HOST_ARCH=aarch64" >> $GITHUB_ENV
178 else
179 echo "HOST_ARCH=${ARCH}" >> $GITHUB_ENV
180 fi
181
182 - name: setup toolchain
183 run: |
184 brew install libtool autoconf automake
185
186 # Download sccache
187 wget -nc -P ${DOWNLOAD_PATH} \
188 https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/sccache-v${SCCACHE_VERSION}-x86_64-apple-darwin.tar.gz
189 tar xf ${DOWNLOAD_PATH}/sccache-v${SCCACHE_VERSION}-x86_64-apple-darwin.tar.gz -C ${HOME}
190 chmod +x ${HOME}/sccache-v${SCCACHE_VERSION}-x86_64-apple-darwin/sccache
191
192 echo "${HOME}/sccache-v${SCCACHE_VERSION}-x86_64-apple-darwin" >> $GITHUB_PATH
193 echo "CC=sccache clang -arch ${ARCH} -mmacosx-version-min=10.13" >> $GITHUB_ENV
194 echo "CXX=sccache clang++ -arch ${ARCH} -mmacosx-version-min=10.13" >> $GITHUB_ENV
195 echo "CFLAGS=-Os" >> $GITHUB_ENV
196
197 - name: build libplist
198 run: |
199 wget -q -nc -P ${DOWNLOAD_PATH} https://github.com/libimobiledevice/libplist/releases/download/${LIBPLIST_VERSION}/libplist-${LIBPLIST_VERSION}.tar.bz2
200 tar xf ${DOWNLOAD_PATH}/libplist-${LIBPLIST_VERSION}.tar.bz2 -C ${DEP_PATH}
201 cd ${DEP_PATH}/libplist-${LIBPLIST_VERSION}
202 ./configure --host=${HOST_ARCH}-apple-darwin --without-cython --enable-static --disable-shared
203 make -j$(sysctl -n hw.ncpu)
204
205 echo "CFLAGS=${CFLAGS} -I${DEP_PATH}/libplist-${LIBPLIST_VERSION}/include" >> $GITHUB_ENV
206 echo "LIBPLIST_LIB=${DEP_PATH}/libplist-${LIBPLIST_VERSION}/src/.libs/libplist-2.0.a" >> $GITHUB_ENV
207
208 - name: build openssl
209 run: |
210 wget -q -nc -P ${DOWNLOAD_PATH} https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
211 tar xf ${DOWNLOAD_PATH}/openssl-${OPENSSL_VERSION}.tar.gz -C ${DEP_PATH}
212 cd ${DEP_PATH}/openssl-${OPENSSL_VERSION}
213 ./config --prefix=/usr no-shared darwin64-${ARCH}
214 make -j$(sysctl -n hw.ncpu) build_generated libcrypto.a
215
216 echo "CFLAGS=${CFLAGS} -I${DEP_PATH}/openssl-${OPENSSL_VERSION}/include" >> $GITHUB_ENV
217 echo "LIBCRYPTO_LIB=${DEP_PATH}/openssl-${OPENSSL_VERSION}/libcrypto.a" >> $GITHUB_ENV
218
219 - name: build
220 run: |
221 export LDID_VERSION=$(echo "$(git describe --tags --abbrev=0)")
222 make -j$(sysctl -n hw.ncpu) \
223 CFLAGS="${CFLAGS} -flto=thin" \
224 VERSION="${LDID_VERSION}" \
225 LIBS="${LIBPLIST_LIB} ${LIBCRYPTO_LIB}"
226 strip ldid
227
228 - uses: actions/upload-artifact@v1
229 with:
230 name: ldid_macos_${{ matrix.arch }}
231 path: ldid
232
233 - name: Upload Release Asset Linux
234 uses: actions/upload-release-asset@v1
235 if: ${{ github.event_name == 'release' }}
236 env:
237 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
238 with:
239 upload_url: ${{ github.event.release.upload_url }}
240 asset_path: ldid
241 asset_name: ldid_macos_${{ matrix.arch }}
242 asset_content_type: application/octet-stream