]> git.cameronkatri.com Git - trustcache.git/commitdiff
Add actions and artifacts
authorCameron Katri <me@cameronkatri.com>
Thu, 26 May 2022 02:22:08 +0000 (22:22 -0400)
committerCameron Katri <me@cameronkatri.com>
Thu, 26 May 2022 02:22:08 +0000 (22:22 -0400)
.github/workflows/build.yml [new file with mode: 0644]

diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644 (file)
index 0000000..61770c4
--- /dev/null
@@ -0,0 +1,156 @@
+name: build
+on:
+  push:
+    paths:
+      - '*.c'
+      - '.github/workflows/*'
+      - 'Makefile'
+  pull_request:
+    paths:
+      - '*.c'
+      - '.github/workflows/*'
+      - 'Makefile'
+  workflow_dispatch:
+  release:
+    types:
+      - created
+
+env:
+  OPENSSL_VERSION: 3.0.3
+  SCCACHE_VERSION: 0.2.15
+
+jobs:
+  build-linux:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        triple:
+        - aarch64-linux-musl
+        - x86_64-linux-musl
+
+    env:
+      TOOLCHAIN: ${{ matrix.triple }}-cross
+      TRIPLE: ${{ matrix.triple }}
+
+    steps:
+    - uses: actions/checkout@v1
+      with:
+        submodules: recursive
+
+    - name: Cache Deps
+      uses: actions/cache@v3
+      id: cache-deps
+      with:
+        path: |
+          ~/.cache/sccache
+          ~/dep_src
+          ~/build
+        key: build-linux-${{ matrix.triple }}
+
+    - name: setup environment
+      run: |
+        export DOWNLOAD_PATH=${HOME}/dep_src
+        export DEP_PATH=${HOME}/build
+        mkdir -p ${DOWNLOAD_PATH} ${DEP_PATH}
+        echo "DOWNLOAD_PATH=${DOWNLOAD_PATH}" >> $GITHUB_ENV
+        echo "DEP_PATH=${DEP_PATH}" >> $GITHUB_ENV
+        echo "ARCH=$(echo ${{ matrix.triple }} | cut -d- -f 1)" >> $GITHUB_ENV
+        echo "${HOME}/${TOOLCHAIN}/bin" >> $GITHUB_PATH
+        echo "CC=sccache ${TRIPLE}-gcc" >> $GITHUB_ENV
+        echo "CXX=sccache ${TRIPLE}-g++" >> $GITHUB_ENV
+        echo "AR=${TRIPLE}-gcc-ar" >> $GITHUB_ENV
+        echo "NM=${TRIPLE}-gcc-nm" >> $GITHUB_ENV
+        echo "RANLIB=${TRIPLE}-gcc-ranlib" >> $GITHUB_ENV
+        echo "CFLAGS=-Os -fPIC -fno-pie -no-pie -static -flto -ffunction-sections -fdata-sections" >> $GITHUB_ENV
+        echo "LDFLAGS=-Wl,--gc-sections -Wl,-strip-all -flto" >> $GITHUB_ENV
+
+    - name: setup toolchain
+      if: steps.cache-deps.outputs.cache-hit != true
+      run: |
+        # Download Toolchain
+        wget -q -nc -P ${DOWNLOAD_PATH} https://musl.cc/${TOOLCHAIN}.tgz
+        tar xf ${DOWNLOAD_PATH}/${TOOLCHAIN}.tgz -C ${HOME}
+
+        # Download sccache
+        wget -q -nc -P ${DOWNLOAD_PATH} \
+          https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VERSION}/sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz
+        tar xf ${DOWNLOAD_PATH}/sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz -C ${HOME}
+        mv ${HOME}/sccache-v${SCCACHE_VERSION}-x86_64-unknown-linux-musl/sccache ${HOME}/${TOOLCHAIN}/bin
+        chmod +x ${HOME}/${TOOLCHAIN}/bin/sccache
+
+    - name: build openssl
+      if: steps.cache-deps.outputs.cache-hit != true
+      run: |
+        export PLATFORM="linux-${ARCH}"
+
+        wget -q -nc -P ${DOWNLOAD_PATH} https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
+        tar xf ${DOWNLOAD_PATH}/openssl-${OPENSSL_VERSION}.tar.gz -C ${DEP_PATH}
+        cd ${DEP_PATH}/openssl-${OPENSSL_VERSION}
+        ./config --prefix=/usr --static -static ${PLATFORM}
+        make -j$(nproc) build_generated libcrypto.a
+
+        echo "CPPFLAGS=${CPPFLAGS} -I${DEP_PATH}/openssl-${OPENSSL_VERSION}/include" >> $GITHUB_ENV
+        echo "LDFLAGS=${LDFLAGS} -L${DEP_PATH}/openssl-${OPENSSL_VERSION}" >> $GITHUB_ENV
+
+    - name: build
+      run: |
+        make -j$(nproc) \
+          LDFLAGS="-static ${LDFLAGS}"
+        ${TRIPLE}-strip tc
+
+    - uses: actions/upload-artifact@v1
+      with:
+        name: tc_linux_${{ env.ARCH }}
+        path: tc
+
+    - name: Upload Release Asset Linux
+      uses: actions/upload-release-asset@v1
+      if: ${{ github.event_name == 'release' }}
+      env:
+        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+      with:
+        upload_url: ${{ github.event.release.upload_url }}
+        asset_path: tc
+        asset_name: tc_linux_${{ env.ARCH }}
+        asset_content_type: application/octet-stream
+
+  build-macos:
+    runs-on: macos-11
+    strategy:
+      matrix:
+        arch:
+        - x86_64
+        - arm64
+    env:
+      ARCH: ${{ matrix.arch }}
+    steps:
+    - uses: actions/checkout@v1
+      with:
+        submodules: recursive
+
+    - name: setup environment
+      run: |
+        echo "CC=clang -arch ${ARCH} -mmacosx-version-min=10.13" >> $GITHUB_ENV
+        echo "CFLAGS=-Os -flto=thin" >> $GITHUB_ENV
+
+    - name: build
+      run: |
+        make -j$(sysctl -n hw.ncpu) \
+          COMMONCRYPTO=1
+        strip tc
+
+    - uses: actions/upload-artifact@v1
+      with:
+        name: tc_macos_${{ matrix.arch }}
+        path: tc
+
+    - name: Upload Release Asset Linux
+      uses: actions/upload-release-asset@v1
+      if: ${{ github.event_name == 'release' }}
+      env:
+        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+      with:
+        upload_url: ${{ github.event.release.upload_url }}
+        asset_path: tc
+        asset_name: tc_macos_${{ matrix.arch }}
+        asset_content_type: application/octet-stream