Skip to content

[Docker] Extract duplicated compiler wrapper setup into a shared script #4005

@Vi-shub

Description

@Vi-shub

Description

The compiler wrapper setup code for reproducible builds is identically duplicated across two Dockerfiles:

  1. docker/Dockerfile.dev
  2. docker/Dockerfile.builder
    Both contain the exact same block that creates wrapper scripts for gcc, cc, and g++ 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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions