Skip to content

Commit 32f7fae

Browse files
authored
Merge pull request #4026 from Vi-shub/DockerWrapper
[Docker] Extract duplicated compiler wrapper setup into shared script
2 parents 442c252 + 5c90465 commit 32f7fae

4 files changed

Lines changed: 35 additions & 21 deletions

File tree

build_openroad.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Options:
6969
-n, --nice Nice all jobs. Use all cpus unless --threads is
7070
also given, then use N threads.
7171
72-
--yosys-args-overwrite Do not use default flags set by this scrip during
72+
--yosys-args-overwrite Do not use default flags set by this script during
7373
Yosys compilation.
7474
7575
--yosys-args STRING Additional compilation flags for Yosys compilation.
@@ -78,7 +78,7 @@ Options:
7878
to the Verific source folder.
7979
8080
--openroad-args-overwrite
81-
Do not use default flags set by this scrip during
81+
Do not use default flags set by this script during
8282
OpenROAD app compilation.
8383
8484
--openroad-args STRING Additional compilation flags for OpenROAD app

docker/Dockerfile.builder

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,9 @@ COPY --link build_openroad.sh build_openroad.sh
1515
1616
FROM orfs-base AS orfs-builder-base
1717
18-
# Inject compiler wrapper scripts that append the macros
19-
RUN mkdir -p /usr/local/bin/wrapped-cc && \
20-
echo '#!/bin/sh' > /usr/local/bin/wrapped-cc/gcc && \
21-
echo 'exec /usr/bin/gcc -D__TIME__="\"0\"" -D__DATE__="\"0\"" -D__TIMESTAMP__="\"0\"" -Wno-builtin-macro-redefined "$@"' >> /usr/local/bin/wrapped-cc/gcc && \
22-
chmod +x /usr/local/bin/wrapped-cc/gcc && \
23-
ln -sf /usr/local/bin/wrapped-cc/gcc /usr/local/bin/wrapped-cc/cc && \
24-
echo '#!/bin/sh' > /usr/local/bin/wrapped-cc/g++ && \
25-
echo 'exec /usr/bin/g++ -D__TIME__="\"0\"" -D__DATE__="\"0\"" -D__TIMESTAMP__="\"0\"" -Wno-builtin-macro-redefined "$@"' >> /usr/local/bin/wrapped-cc/g++ && \
26-
chmod +x /usr/local/bin/wrapped-cc/g++
18+
# Add compiler wrapper scripts for reproducible builds
19+
COPY --link etc/setup_compiler_wrappers.sh /tmp/
20+
RUN sh /tmp/setup_compiler_wrappers.sh && rm /tmp/setup_compiler_wrappers.sh
2721

2822
# Prepend wrapper directory to PATH so they override system compilers
2923
ENV PATH="/usr/local/bin/wrapped-cc:$PATH"

docker/Dockerfile.dev

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,9 @@ COPY InstallerOpenROAD.sh \
1515
ARG options=""
1616
ARG constantBuildDir="-constant-build-dir"
1717

18-
# add compiler wrapper scripts
19-
# inject the macro definitions during compilation only
20-
RUN mkdir -p /usr/local/bin/wrapped-cc && \
21-
echo '#!/bin/sh' > /usr/local/bin/wrapped-cc/gcc && \
22-
echo 'exec /usr/bin/gcc -D__TIME__="\"0\"" -D__DATE__="\"0\"" -D__TIMESTAMP__="\"0\"" -Wno-builtin-macro-redefined "$@"' >> /usr/local/bin/wrapped-cc/gcc && \
23-
chmod +x /usr/local/bin/wrapped-cc/gcc && \
24-
ln -sf /usr/local/bin/wrapped-cc/gcc /usr/local/bin/wrapped-cc/cc && \
25-
echo '#!/bin/sh' > /usr/local/bin/wrapped-cc/g++ && \
26-
echo 'exec /usr/bin/g++ -D__TIME__="\"0\"" -D__DATE__="\"0\"" -D__TIMESTAMP__="\"0\"" -Wno-builtin-macro-redefined "$@"' >> /usr/local/bin/wrapped-cc/g++ && \
27-
chmod +x /usr/local/bin/wrapped-cc/g++
18+
# add compiler wrapper scripts for reproducible builds
19+
COPY setup_compiler_wrappers.sh /tmp/
20+
RUN sh /tmp/setup_compiler_wrappers.sh && rm /tmp/setup_compiler_wrappers.sh
2821

2922
ENV PATH="/usr/local/bin/wrapped-cc:$PATH"
3023

etc/setup_compiler_wrappers.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
# setup_compiler_wrappers.sh
3+
# Creates compiler wrapper scripts for reproducible builds by overriding
4+
# __TIME__, __DATE__, and __TIMESTAMP__ macros with constant values.
5+
# This ensures Docker image builds are deterministic regardless of build time.
6+
7+
set -e
8+
9+
WRAPPER_DIR="/usr/local/bin/wrapped-cc"
10+
mkdir -p "$WRAPPER_DIR"
11+
12+
# GCC wrapper
13+
cat > "$WRAPPER_DIR/gcc" << 'WRAPPER'
14+
#!/bin/sh
15+
exec /usr/bin/gcc -D__TIME__="\"0\"" -D__DATE__="\"0\"" -D__TIMESTAMP__="\"0\"" -Wno-builtin-macro-redefined "$@"
16+
WRAPPER
17+
chmod +x "$WRAPPER_DIR/gcc"
18+
19+
# Symlink cc to gcc wrapper
20+
ln -sf "$WRAPPER_DIR/gcc" "$WRAPPER_DIR/cc"
21+
22+
# G++ wrapper
23+
cat > "$WRAPPER_DIR/g++" << 'WRAPPER'
24+
#!/bin/sh
25+
exec /usr/bin/g++ -D__TIME__="\"0\"" -D__DATE__="\"0\"" -D__TIMESTAMP__="\"0\"" -Wno-builtin-macro-redefined "$@"
26+
WRAPPER
27+
chmod +x "$WRAPPER_DIR/g++"

0 commit comments

Comments
 (0)