diff --git a/Dockerfile.arm64 b/Dockerfile.arm64 new file mode 100644 index 0000000..8d3a4fd --- /dev/null +++ b/Dockerfile.arm64 @@ -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 diff --git a/Dockerfile.x86_64 b/Dockerfile.x86_64 new file mode 100644 index 0000000..4d90f82 --- /dev/null +++ b/Dockerfile.x86_64 @@ -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 diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..6cde55d --- /dev/null +++ b/build.sh @@ -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 . + diff --git a/install_toolchain.sh b/install_toolchain.sh index 15f55f5..58aeac5 100755 --- a/install_toolchain.sh +++ b/install_toolchain.sh @@ -6,7 +6,7 @@ targets=( ) for target in ${targets[@]}; do - docker pull dockcross/${target} + docker pull gitea.jde.nz/public/jcross-$target done BIN_DIR=${HOME}/.local/bin @@ -14,7 +14,7 @@ BIN_DIR=${HOME}/.local/bin mkdir -p ${BIN_DIR} 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" done diff --git a/publish.sh b/publish.sh index ea5316d..ba79b8c 100755 --- a/publish.sh +++ b/publish.sh @@ -1,5 +1,4 @@ #!/bin/bash -docker build -t cpp-httplib-builder . -docker tag cpp-httplib-builder:latest gitea.jde.nz/public/cpp-httplib-builder:latest -docker push cpp-httplib-builder:latest +docker push gitea.jde.nz/public/jcross-linux-arm64-full:latest +docker push gitea.jde.nz/public/jcross-linux-x86_64-full:latest diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6956296..fb698cb 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,7 +8,5 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static") -include_directories(/usr/local/include) - add_executable(ipdemo main.cpp) target_link_libraries(ipdemo pthread assert cpptrace dwarf z zstd) diff --git a/test/build.sh b/test/build.sh index 33a79b9..5243202 100755 --- a/test/build.sh +++ b/test/build.sh @@ -23,9 +23,6 @@ function build() { exit 1 fi - # Create volume if it doesn't exist - docker volume create cppbuild-cache-$ARCH - # Directory to copy the executable to OUTDIR="$SCRIPT_DIR/output" WORKDIR="$SCRIPT_DIR/build/${ARCH}" @@ -37,8 +34,6 @@ function build() { echo "OUTDIR: $OUTDIR" echo "SCRIPT_DIR: $SCRIPT_DIR" - BUILD_IMAGE="gitea.jde.nz/public/cpp-httplib-builder:$ARCH" - case $ARCH in "arm64") export DOCKCROSS="dockcross-linux-arm64-full";; "amd64") export DOCKCROSS="dockcross-linux-x86_64-full";; @@ -51,8 +46,8 @@ function build() { export CCACHE_DIR=${WORKDIR}/.ccache cd $SCRIPT_DIR - $DOCKCROSS bash -c "cmake -B$WORKDIR . -GNinja" - $DOCKCROSS bash -c "ninja -j$(nproc) -Cbuild/${ARCH}" + $DOCKCROSS bash -c "cmake -B./build/${ARCH} . -GNinja" + $DOCKCROSS bash -c "ninja -j$(nproc) -C./build/${ARCH}" cp "${WORKDIR}/$PROJECT" "${OUTDIR}/$PROJECT.$ARCH" # Run the executable if it exists @@ -72,6 +67,6 @@ function build() { file $OUTDIR/$PROJECT.$ARCH } -build arm64 build amd64 +build arm64