-
Notifications
You must be signed in to change notification settings - Fork 459
Description
Description
The compiler wrapper setup code for reproducible builds is identically duplicated across two Dockerfiles:
docker/Dockerfile.devdocker/Dockerfile.builder
Both contain the exact same block that creates wrapper scripts forgcc,cc, andg++to override__TIME__,__DATE__, and__TIMESTAMP__macros:
RUN mkdir -p /usr/local/bin/wrapped-cc && \
echo '#!/bin/sh' > /usr/local/bin/wrapped-cc/gcc && \
echo 'exec /usr/bin/gcc -D__TIME__="\"0\"" -D__DATE__="\"0\"" -D__TIMESTAMP__="\"0\"" -Wno-builtin-macro-redefined "$@"' >> /usr/local/bin/wrapped-cc/gcc && \
chmod +x /usr/local/bin/wrapped-cc/gcc && \
ln -sf /usr/local/bin/wrapped-cc/gcc /usr/local/bin/wrapped-cc/cc && \
echo '#!/bin/sh' > /usr/local/bin/wrapped-cc/g++ && \
echo 'exec /usr/bin/g++ -D__TIME__="\"0\"" -D__DATE__="\"0\"" -D__TIMESTAMP__="\"0\"" -Wno-builtin-macro-redefined "$@"' >> /usr/local/bin/wrapped-cc/g++ && \
chmod +x /usr/local/bin/wrapped-cc/g++
ENV PATH="/usr/local/bin/wrapped-cc:$PATH"Problems:
DRY violation: If the wrapper logic needs updating (e.g., adding clang support or changing flags), both files must be modified identically.
Maintenance risk: Divergence between the two copies could cause subtle, hard-to-debug build reproducibility issues.
Additionally, build_openroad.sh has a minor typo "scrip" → "script" in the help text for --yosys-args-overwrite and --openroad-args-overwrite.
Suggested Solution
Extract the compiler wrapper setup into a shared shell script docker/setup_compiler_wrappers.sh
#!/bin/sh
# docker/setup_compiler_wrappers.sh
# Sets up compiler wrapper scripts for reproducible builds
# by overriding __TIME__, __DATE__, and __TIMESTAMP__ macros.
set -e
mkdir -p /usr/local/bin/wrapped-cc
# GCC wrapper
cat > /usr/local/bin/wrapped-cc/gcc << 'WRAPPER'
#!/bin/sh
exec /usr/bin/gcc -D__TIME__="\"0\"" -D__DATE__="\"0\"" -D__TIMESTAMP__="\"0\"" -Wno-builtin-macro-redefined "$@"
WRAPPER
chmod +x /usr/local/bin/wrapped-cc/gcc
ln -sf /usr/local/bin/wrapped-cc/gcc /usr/local/bin/wrapped-cc/cc
# G++ wrapper
cat > /usr/local/bin/wrapped-cc/g++ << 'WRAPPER'
#!/bin/sh
exec /usr/bin/g++ -D__TIME__="\"0\"" -D__DATE__="\"0\"" -D__TIMESTAMP__="\"0\"" -Wno-builtin-macro-redefined "$@"
WRAPPER
chmod +x /usr/local/bin/wrapped-cc/g++
Then simplify both Dockerfiles to:
COPY setup_compiler_wrappers.sh /tmp/
RUN /tmp/setup_compiler_wrappers.sh && rm /tmp/setup_compiler_wrappers.sh
ENV PATH="/usr/local/bin/wrapped-cc:$PATH"Additional Context
This change aligns with the GSoC 2026 "Build, Release & Onboarding Simplification" project goals. The shared script also makes it easier to extend wrapper support to additional compilers (e.g., clang/clang++) in the future.
Files affected:
docker/Dockerfile.dev
docker/Dockerfile.builder
docker/setup_compiler_wrappers.sh
build_openroad.sh
Please assign this issue to me I'll work on this @gudeh @maliberty