From 6d6aa38cfd7cfc329826c0899f1fcba771a09751 Mon Sep 17 00:00:00 2001 From: garikello3d Date: Mon, 25 Dec 2023 12:31:40 +0100 Subject: [PATCH 1/4] wip: primitive automation to build for different docker-based linuxes --- scripts/Dockerfile.template | 13 +++++++++++ scripts/PLATFORMS | 4 ++++ scripts/build-internal.sh | 13 +++++++++++ scripts/build.sh | 44 +++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 scripts/Dockerfile.template create mode 100644 scripts/PLATFORMS create mode 100755 scripts/build-internal.sh create mode 100755 scripts/build.sh diff --git a/scripts/Dockerfile.template b/scripts/Dockerfile.template new file mode 100644 index 0000000..be578bd --- /dev/null +++ b/scripts/Dockerfile.template @@ -0,0 +1,13 @@ +ARG OS +FROM $OS + +ARG PAC + +RUN rm /bin/sh && ln -s /bin/bash /bin/sh +RUN $PAC update && $PAC install -y git gcc curl + +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > /tmp/rustup && sh /tmp/rustup -y +ADD scripts/build-internal.sh / +RUN mkdir -p /dummy/src +COPY Cargo.toml /dummy +RUN source $HOME/.cargo/env && cd /dummy && echo "// dummy file" > src/lib.rs && cargo build --release diff --git a/scripts/PLATFORMS b/scripts/PLATFORMS new file mode 100644 index 0000000..1eba8f1 --- /dev/null +++ b/scripts/PLATFORMS @@ -0,0 +1,4 @@ +# short name # docker from # pac mgr cmd +centos7 centos:7.9.2009 yum +rocky9 rockylinux:9.3 yum +debian12 debian:12.4 apt-get diff --git a/scripts/build-internal.sh b/scripts/build-internal.sh new file mode 100755 index 0000000..0d97aba --- /dev/null +++ b/scripts/build-internal.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +if [ $# -ne 1 ]; then + echo usage $0 \ + exit 1 +fi + +cd / +git clone /src/ bigarchiver && \ +cd bigarchiver/ && \ +cargo test --release && cargo build --release && \ +mkdir -pv /src/scripts/build/$1/ && \ +cp -v target/release/bigarchiver /src/scripts/build/$1/ diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000..1db9b6f --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +set -e + +if [ $# -eq 0 ]; then + echo usage $0 --image\|--app [ os_ident ] + exit 1 +fi + +cat PLATFORMS | sed '/^#/d;/^[[:space:]]*$/d' | while read LINE; do + WORDS=($LINE) + if [ ${#WORDS[@]} -ne 3 ]; then + echo Invalid PLATFORMS file + exit 1 + fi + + IDENT=${WORDS[0]} + IMAGE_FROM=${WORDS[1]} + PAC_MGR=${WORDS[2]} + + if [ -n "$2" ]; then + if [ x"$IDENT" != x"$2" ] ; then + continue + fi + fi + + cd .. + case $1 in + --image) + echo preparing build image for $IDENT + docker build -t bigarchiver-$IDENT -f scripts/Dockerfile.template --build-arg OS=$IMAGE_FROM --build-arg PAC=$PAC_MGR . + ;; + --app) + echo building application for $IDENT + docker run -v=.:/src bigarchiver-$IDENT /bin/bash -l -c "/build-internal.sh $IDENT" + ;; + *) + echo invalid usage + exit 3 + esac + cd scripts +done + +echo all done From 9ac06a6f01f52b84fd4ee2cd4ee5524a920735f8 Mon Sep 17 00:00:00 2001 From: wayne Date: Mon, 25 Dec 2023 18:59:28 +0000 Subject: [PATCH 2/4] should build on stable rust (#6) This PR replaces the use of unsable feature https://github.com/rust-lang/rust/issues/91946 with its corresponding stable branch equivalent that is slightly more verbose. --- src/comp_decomp_2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/comp_decomp_2.rs b/src/comp_decomp_2.rs index 5d8cd48..0ba3170 100644 --- a/src/comp_decomp_2.rs +++ b/src/comp_decomp_2.rs @@ -15,7 +15,7 @@ impl<'a, T: DataSink> Conv<'a, T> { impl<'a, T: DataSink> Write for Conv<'a, T> { fn write(&mut self, data: &[u8]) -> std::io::Result { - self.t.add(data).map(|_|data.len()).map_err(|e| std::io::Error::other(e)) + self.t.add(data).map(|_|data.len()).map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e)) } fn flush(&mut self) -> std::io::Result<()> { Ok(()) From 5dddd4627ffd697799e8895c2d530a08806fa33d Mon Sep 17 00:00:00 2001 From: wayne Date: Tue, 26 Dec 2023 12:54:59 +0000 Subject: [PATCH 3/4] cargo.toml: reduce release binary size by 10x (#5) The new release profile options do the following: * `strip = true` causes debug symbols to be stripped from the final binary * `codegen-units = 1` reduces redundancies in codegen optimizations by forcing all code generation through a single unit * `lto = true` something something link-time optimization For me this took the binary size down from 7MB to roughly 682KB. --- Cargo.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index de1c140..9f8a235 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,11 @@ name = "bigarchiver" version = "0.1.0" edition = "2021" +[profile.release] +lto = true +codegen-units = 1 +strip = true + [dependencies] libc = "0.2.151" liblzma = { version = "0.2.1", features = ["parallel", "static"] } From aa4c250e790d6f089790a0ca71a5eeb21776a777 Mon Sep 17 00:00:00 2001 From: garikello3d Date: Tue, 26 Dec 2023 23:56:39 +0100 Subject: [PATCH 4/4] wip: working version for 3 linux distros based on docker --- .gitignore | 2 ++ scripts/Dockerfile.template | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6985cf1..c99350b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb + +scripts/build \ No newline at end of file diff --git a/scripts/Dockerfile.template b/scripts/Dockerfile.template index be578bd..42d598a 100644 --- a/scripts/Dockerfile.template +++ b/scripts/Dockerfile.template @@ -4,7 +4,7 @@ FROM $OS ARG PAC RUN rm /bin/sh && ln -s /bin/bash /bin/sh -RUN $PAC update && $PAC install -y git gcc curl +RUN $PAC -y update && $PAC install -y git gcc curl RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > /tmp/rustup && sh /tmp/rustup -y ADD scripts/build-internal.sh /