This commit is contained in:
Your Name 2025-05-26 21:13:02 +12:00
parent f9f07a3bb8
commit 4d89b95eb7
7 changed files with 71 additions and 15 deletions

7
Dockerfile.arm64 Normal file
View File

@ -0,0 +1,7 @@
FROM dockcross/linux-arm64-full
ENV DEFAULT_DOCKCROSS_IMAGE=gitea.jde.nz/public/jcross-linux-arm64-full
RUN apt-get update && apt-get install -y \
ccache \
mold

50
Dockerfile.x86_64 Normal file
View File

@ -0,0 +1,50 @@
FROM dockcross/linux-x86_64-full
ENV DEFAULT_DOCKCROSS_IMAGE=gitea.jde.nz/public/jcross-linux-x86_64-full
RUN apt-get update && apt-get install -y \
ccache \
mold \
libcpp-httplib-dev
########################################
# nlohmann/json (compiled static .a) #
########################################
ARG JSON_VERSION=3.11.3
RUN git clone --depth 1 --branch v${JSON_VERSION} https://github.com/nlohmann/json.git /tmp/json && \
cmake -S /tmp/json -B /tmp/json/build \
-DJSON_BuildTests=OFF \
-DJSON_MultipleHeaders=OFF \
-DBUILD_SHARED_LIBS=OFF && \
cmake --build /tmp/json/build --config Release && \
cmake --install /tmp/json/build
##################################
# libassert (build static .a) #
##################################
ARG LIBASSERT_VERSION=v2.1.5
RUN git clone --depth 1 --branch ${LIBASSERT_VERSION} https://github.com/jeremy-rifkin/libassert.git /tmp/libassert && \
cmake -S /tmp/libassert -B /tmp/libassert/build \
-DLIBASSERT_BUILD_TESTS=OFF \
-DLIBASSERT_BUILD_EXAMPLES=OFF \
-DLIBASSERT_BUILD_STATIC=ON && \
cmake --build /tmp/libassert/build --config Release && \
cmake --install /tmp/libassert/build
#####################
# zlib (static .a) #
#####################
ARG ZLIB_VERSION=1.3.1
RUN wget -q https://zlib.net/zlib-${ZLIB_VERSION}.tar.gz && \
tar xzf zlib-${ZLIB_VERSION}.tar.gz && \
cd zlib-${ZLIB_VERSION} && \
./configure --static && \
make -j$(nproc) && \
make install && \
cd .. && rm -rf zlib-${ZLIB_VERSION}*
##############################
# Reduce size of .a archives #
##############################
RUN strip --strip-unneeded /usr/local/lib/*.a

7
build.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
set -e
docker build -f Dockerfile.arm64 -t gitea.jde.nz/public/jcross-linux-arm64-full:latest .
docker build -f Dockerfile.x86_64 -t gitea.jde.nz/public/jcross-linux-x86_64-full:latest .

View File

@ -6,7 +6,7 @@ targets=(
) )
for target in ${targets[@]}; do for target in ${targets[@]}; do
docker pull dockcross/${target} docker pull gitea.jde.nz/public/jcross-$target
done done
BIN_DIR=${HOME}/.local/bin BIN_DIR=${HOME}/.local/bin
@ -14,7 +14,7 @@ BIN_DIR=${HOME}/.local/bin
mkdir -p ${BIN_DIR} mkdir -p ${BIN_DIR}
for target in ${targets[@]}; do for target in ${targets[@]}; do
docker run dockcross/$target > ${BIN_DIR}/dockcross-$target && chmod u+x ${BIN_DIR}/dockcross-$target docker run gitea.jde.nz/public/jcross-$target > ${BIN_DIR}/dockcross-$target && chmod u+x ${BIN_DIR}/dockcross-$target
echo "Installed ${BIN_DIR}/dockcross-$target" echo "Installed ${BIN_DIR}/dockcross-$target"
done done

View File

@ -1,5 +1,4 @@
#!/bin/bash #!/bin/bash
docker build -t cpp-httplib-builder . docker push gitea.jde.nz/public/jcross-linux-arm64-full:latest
docker tag cpp-httplib-builder:latest gitea.jde.nz/public/cpp-httplib-builder:latest docker push gitea.jde.nz/public/jcross-linux-x86_64-full:latest
docker push cpp-httplib-builder:latest

View File

@ -8,7 +8,5 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
include_directories(/usr/local/include)
add_executable(ipdemo main.cpp) add_executable(ipdemo main.cpp)
target_link_libraries(ipdemo pthread assert cpptrace dwarf z zstd) target_link_libraries(ipdemo pthread assert cpptrace dwarf z zstd)

View File

@ -23,9 +23,6 @@ function build() {
exit 1 exit 1
fi fi
# Create volume if it doesn't exist
docker volume create cppbuild-cache-$ARCH
# Directory to copy the executable to # Directory to copy the executable to
OUTDIR="$SCRIPT_DIR/output" OUTDIR="$SCRIPT_DIR/output"
WORKDIR="$SCRIPT_DIR/build/${ARCH}" WORKDIR="$SCRIPT_DIR/build/${ARCH}"
@ -37,8 +34,6 @@ function build() {
echo "OUTDIR: $OUTDIR" echo "OUTDIR: $OUTDIR"
echo "SCRIPT_DIR: $SCRIPT_DIR" echo "SCRIPT_DIR: $SCRIPT_DIR"
BUILD_IMAGE="gitea.jde.nz/public/cpp-httplib-builder:$ARCH"
case $ARCH in case $ARCH in
"arm64") export DOCKCROSS="dockcross-linux-arm64-full";; "arm64") export DOCKCROSS="dockcross-linux-arm64-full";;
"amd64") export DOCKCROSS="dockcross-linux-x86_64-full";; "amd64") export DOCKCROSS="dockcross-linux-x86_64-full";;
@ -51,8 +46,8 @@ function build() {
export CCACHE_DIR=${WORKDIR}/.ccache export CCACHE_DIR=${WORKDIR}/.ccache
cd $SCRIPT_DIR cd $SCRIPT_DIR
$DOCKCROSS bash -c "cmake -B$WORKDIR . -GNinja" $DOCKCROSS bash -c "cmake -B./build/${ARCH} . -GNinja"
$DOCKCROSS bash -c "ninja -j$(nproc) -Cbuild/${ARCH}" $DOCKCROSS bash -c "ninja -j$(nproc) -C./build/${ARCH}"
cp "${WORKDIR}/$PROJECT" "${OUTDIR}/$PROJECT.$ARCH" cp "${WORKDIR}/$PROJECT" "${OUTDIR}/$PROJECT.$ARCH"
# Run the executable if it exists # Run the executable if it exists
@ -72,6 +67,6 @@ function build() {
file $OUTDIR/$PROJECT.$ARCH file $OUTDIR/$PROJECT.$ARCH
} }
build arm64
build amd64 build amd64
build arm64