Build static binary (#29)

This commit is contained in:
Luke Street 2023-01-22 20:20:30 -05:00 committed by GitHub
parent aec6f0dbe9
commit 67f99ba1b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 30 deletions

View File

@ -4,25 +4,18 @@ jobs:
build_and_test:
name: Build and test
runs-on: ubuntu-latest
container:
image: ubuntu:focal
steps:
- uses: actions/checkout@v2
- name: Install GCC multilib
- name: Install dependencies
run: |
apt-get update
apt-get install -y cmake file gcc-multilib g++-multilib unzip wget
- name: Configure
# Replace with RelWithDebInfo when -O2 crash is fixed
run: |
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
sudo apt-get update
sudo apt-get install -y file unzip wget
- name: Build
run: cmake --build build
env:
DOCKER_BUILDKIT: 1
run: docker build --target export --output build .
- name: Test
run: |

View File

@ -1,26 +1,23 @@
FROM ubuntu:20.04 as build
# Build stage
FROM --platform=linux/i386 alpine:latest AS build
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
g++ \
g++-multilib \
cmake \
ninja-build
# Install dependencies
RUN apk add --no-cache cmake ninja g++ linux-headers binutils
# Copy source files
COPY . /wibo
# Build static binary
# Replace with RelWithDebInfo when -O2 crash is fixed
RUN cmake -S /wibo -B /wibo/build -G Ninja -DCMAKE_BUILD_TYPE=Debug
RUN cmake --build /wibo/build
RUN cmake -S /wibo -B /wibo/build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-static" \
&& cmake --build /wibo/build \
&& strip -g /wibo/build/wibo
# Export binary (usage: docker build --target export --output build .)
FROM scratch AS export
COPY --from=build /wibo/build/wibo .
FROM ubuntu:22.04
RUN dpkg --add-architecture i386 \
&& apt-get update \
&& apt-get install -y --no-install-recommends \
libstdc++6:i386
# Runnable container
FROM alpine:latest
COPY --from=build /wibo/build/wibo /usr/local/sbin/wibo
CMD /usr/local/sbin/wibo