diff --git a/build_openroad.sh b/build_openroad.sh index 74303aa69e..34dd9c5e02 100755 --- a/build_openroad.sh +++ b/build_openroad.sh @@ -67,7 +67,7 @@ Options: -n, --nice Nice all jobs. Use all cpus unless --threads is also given, then use N threads. - --yosys-args-overwrite Do not use default flags set by this scrip during + --yosys-args-overwrite Do not use default flags set by this script during Yosys compilation. --yosys-args STRING Additional compilation flags for Yosys compilation. @@ -76,7 +76,7 @@ Options: to the Verific source folder. --openroad-args-overwrite - Do not use default flags set by this scrip during + Do not use default flags set by this script during OpenROAD app compilation. --openroad-args STRING Additional compilation flags for OpenROAD app diff --git a/docker/Dockerfile.builder b/docker/Dockerfile.builder index 62419e533c..b2f756611b 100644 --- a/docker/Dockerfile.builder +++ b/docker/Dockerfile.builder @@ -15,15 +15,9 @@ COPY --link build_openroad.sh build_openroad.sh FROM orfs-base AS orfs-builder-base -# Inject compiler wrapper scripts that append the 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++ +# Add compiler wrapper scripts for reproducible builds +COPY --link etc/setup_compiler_wrappers.sh /tmp/ +RUN sh /tmp/setup_compiler_wrappers.sh && rm /tmp/setup_compiler_wrappers.sh # Prepend wrapper directory to PATH so they override system compilers ENV PATH="/usr/local/bin/wrapped-cc:$PATH" diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index a2a822b486..95acd0e27c 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -15,16 +15,9 @@ COPY InstallerOpenROAD.sh \ ARG options="" ARG constantBuildDir="-constant-build-dir" -# add compiler wrapper scripts -# inject the macro definitions during compilation only -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++ +# add compiler wrapper scripts for reproducible builds +COPY setup_compiler_wrappers.sh /tmp/ +RUN sh /tmp/setup_compiler_wrappers.sh && rm /tmp/setup_compiler_wrappers.sh ENV PATH="/usr/local/bin/wrapped-cc:$PATH" diff --git a/etc/setup_compiler_wrappers.sh b/etc/setup_compiler_wrappers.sh new file mode 100644 index 0000000000..64bcb7747b --- /dev/null +++ b/etc/setup_compiler_wrappers.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# setup_compiler_wrappers.sh +# Creates compiler wrapper scripts for reproducible builds by overriding +# __TIME__, __DATE__, and __TIMESTAMP__ macros with constant values. +# This ensures Docker image builds are deterministic regardless of build time. + +set -e + +WRAPPER_DIR="/usr/local/bin/wrapped-cc" +mkdir -p "$WRAPPER_DIR" + +# GCC wrapper +cat > "$WRAPPER_DIR/gcc" << 'WRAPPER' +#!/bin/sh +exec /usr/bin/gcc -D__TIME__="\"0\"" -D__DATE__="\"0\"" -D__TIMESTAMP__="\"0\"" -Wno-builtin-macro-redefined "$@" +WRAPPER +chmod +x "$WRAPPER_DIR/gcc" + +# Symlink cc to gcc wrapper +ln -sf "$WRAPPER_DIR/gcc" "$WRAPPER_DIR/cc" + +# G++ wrapper +cat > "$WRAPPER_DIR/g++" << 'WRAPPER' +#!/bin/sh +exec /usr/bin/g++ -D__TIME__="\"0\"" -D__DATE__="\"0\"" -D__TIMESTAMP__="\"0\"" -Wno-builtin-macro-redefined "$@" +WRAPPER +chmod +x "$WRAPPER_DIR/g++"