바이너리 크기 조정.

This commit is contained in:
Sangbum Kim 2024-07-22 02:27:12 +09:00
parent 45c3761fd9
commit 18097ff808
2 changed files with 13 additions and 8 deletions

View File

@ -17,7 +17,7 @@ errno = { version = "*", default-features = false }
panic = "abort"
[profile.release]
#opt-level = 'z' # Optimize for size.
opt-level = 'z' # Optimize for size.
lto = true # Enable Link Time Optimization
codegen-units = 1 # Reduce number of codegen units to increase optimizations.
panic = 'abort' # Abort on panic

View File

@ -3,14 +3,15 @@
##
## Build
##
FROM rust:1-alpine3.19 AS build
FROM rust:1-alpine3.20 AS build
LABEL org.opencontainers.image.authors="Sangbum Kim <sangbumkim@amuz.es>"
# set the workdir and copy the source into it
WORKDIR /app
COPY . /app
ENV RUSTFLAGS='-C panic=abort -C link-arg=-s -C link-arg=-fuse-ld=lld'
ENV RUSTFLAGS='-Cpanic=abort -Crelocation-model=static -Clink-args=-Wl,-x,-s,-fuse-ld=lld,--as-needed,--gc-sections,--no-gnu-unique,--nostdlib,--no-pie,--build-id=none,--no-eh-frame-hdr'
RUN set -x && \
apk add --no-cache \
@ -20,15 +21,19 @@ RUN set -x && \
musl-dev
RUN set -x && \
cargo build --release && \
ls -alh target/release/init-wrapper
cargo build --release -- -C prefer-dynamic&& \
objcopy -R .eh_frame -R .got.plt target/release/init-wrapper target/release/init-wrapper && \
ls -alh target/release/init-wrapper && \
readelf -W -S ./target/release/init-wrapper
# && \
# ./target/release/init-wrapper
# ldd target/release/init-wrapper && \
# && \
# ldd target/release/init-wrapper
# RUN --mount=type=bind,rw,source=.,target=/host \
# cp -avf target/release/init-wrapper /host/init-wrapper && \
# ./target/release/init-wrapper
RUN --mount=type=bind,rw,source=.,target=/host \
cp -avf target/release/init-wrapper /host/init-wrapper && \
./target/release/init-wrapper
FROM scratch