Skip to content

Commit 9b26ff8

Browse files
authored
Merge pull request #4625 from The-OpenROAD-Project-staging/docker-builder-yosys-layer
feat(docker): build yosys into a reusable tools image
2 parents dfc688e + 239852e commit 9b26ff8

3 files changed

Lines changed: 87 additions & 10 deletions

File tree

‎build_openroad.sh‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function usage() {
3939
4040
Usage: $0 [-h|--help] [-o|--local] [-l|--latest]
4141
[--or_branch BRANCH_NAME] [--or_repo REPO_URL] [--no_init]
42+
[-s|--skip_openroad] [--openroad_only]
4243
[-n|--nice] [-t|--threads N]
4344
[--yosys-args-overwrite] [--yosys-args STRING]
4445
[--with-verific PATH]
@@ -57,6 +58,9 @@ Options:
5758
5859
-s, --skip_openroad Skip building and all git operations on OpenROAD.
5960
61+
--openroad_only Build only OpenROAD; skip Yosys, Verific and
62+
kepler-formal. Requires --local.
63+
6064
--or_branch BRANCH_NAME Use the head of branch BRANCH for tools/OpenROAD.
6165
6266
--or_repo REPO_URL Use a fork at REPO-URL (https/ssh) for tools/OpenROAD.
@@ -165,6 +169,9 @@ while (( "$#" )); do
165169
-s|--skip_openroad)
166170
SKIP_OPENROAD=1
167171
;;
172+
--openroad_only)
173+
OPENROAD_ONLY=1
174+
;;
168175
--or_branch)
169176
OPENROAD_APP_BRANCH="$2"
170177
shift
@@ -233,6 +240,17 @@ while (( "$#" )); do
233240
shift
234241
done
235242

243+
if [ ! -z "${OPENROAD_ONLY+x}" ]; then
244+
if [ -z "${LOCAL_BUILD+x}" ]; then
245+
echo "[ERROR FLW-0033] --openroad_only requires --local." >&2
246+
exit 1
247+
fi
248+
if [ ! -z "${SKIP_OPENROAD+x}" ]; then
249+
echo "[ERROR FLW-0033] --openroad_only and --skip_openroad are mutually exclusive." >&2
250+
exit 1
251+
fi
252+
fi
253+
236254
if [[ "$PROC" == "-1" ]]; then
237255
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
238256
PROC=$(nproc --all)
@@ -373,6 +391,10 @@ __local_build()
373391
${NICE} ./tools/OpenROAD/etc/Build.sh "${OPENROAD_APP_ARGS[@]}"
374392
fi
375393

394+
if [ ! -z "${OPENROAD_ONLY+x}" ]; then
395+
return
396+
fi
397+
376398
YOSYS_ABC_PATH=tools/yosys/abc
377399
if [[ -d "${YOSYS_ABC_PATH}/.git" ]]; then
378400
# update indexes to make sure git diff-index uses correct data

‎docker/Dockerfile.builder‎

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# instead use etc/DockerHelper.sh
77

88
ARG fromImage=openroad/flow-ubuntu22.04-dev:latest
9+
# Image holding the prebuilt tools/install of every tool except OpenROAD
10+
# (a build of the orfs-tools target). By default they are built here.
11+
ARG toolsImage=orfs-tools
912

1013
FROM $fromImage AS orfs-base
1114

@@ -22,7 +25,11 @@ RUN sh /tmp/setup_compiler_wrappers.sh && rm /tmp/setup_compiler_wrappers.sh
2225
# Prepend wrapper directory to PATH so they override system compilers
2326
ENV PATH="/usr/local/bin/wrapped-cc:$PATH"
2427

25-
COPY --link tools tools
28+
FROM orfs-builder-base AS orfs-tools-builder
29+
30+
# Exclude install so a local build's output (e.g. tools/install/OpenROAD)
31+
# cannot leak into the image; the build below starts from an empty install.
32+
COPY --link --exclude=OpenROAD --exclude=AutoTuner --exclude=install tools tools
2633
ARG numThreads=$(nproc)
2734
ARG verificPath=""
2835

@@ -36,30 +43,59 @@ else
3643
fi
3744
./build_openroad.sh --no_init \
3845
--local \
46+
--skip_openroad \
3947
--threads ${numThreads} \
4048
${verificArgs}
41-
if [ ! -x tools/install/OpenROAD/bin/openroad ]; then
42-
echo "Error: tools/install/OpenROAD/bin/openroad is missing or not executable." >&2
43-
exit 1
44-
fi
4549
if [ -n "${verificPath}" ]; then
4650
rm -rf "${verificPath}"
4751
fi
4852
EOF
4953

5054
# Collect LICENSE files from tool source trees into the install directory so
51-
# they are available in the final image. tools/OpenROAD/src/sta is excluded
52-
# because it is covered by a separate commercial license agreement.
55+
# they are available in the final image.
5356
RUN find /OpenROAD-flow-scripts/tools \( -name "*LICENSE*" -o -name "*LICENSES*" \) \
54-
| grep -v '/OpenROAD/src/sta/' \
55-
| grep -v '/AutoTuner/' \
5657
| grep -v '^/OpenROAD-flow-scripts/tools/install/' \
5758
| while IFS= read -r f; do \
5859
rel="${f#/OpenROAD-flow-scripts/tools/}"; \
5960
mkdir -p "/OpenROAD-flow-scripts/tools/install/licenses/$(dirname "$rel")"; \
6061
cp -r "$f" "/OpenROAD-flow-scripts/tools/install/licenses/$rel"; \
6162
done
6263

64+
# Yosys, kepler-formal and their licenses, without sources or build trees.
65+
FROM orfs-base AS orfs-tools
66+
67+
COPY --link --from=orfs-tools-builder /OpenROAD-flow-scripts/tools/install tools/install
68+
69+
FROM $toolsImage AS tools
70+
71+
FROM orfs-builder-base AS orfs-openroad-builder
72+
73+
COPY --link --from=tools /OpenROAD-flow-scripts/tools/install tools/install
74+
COPY --link tools/OpenROAD tools/OpenROAD
75+
ARG numThreads=$(nproc)
76+
77+
RUN <<EOF
78+
set -e
79+
./build_openroad.sh --no_init \
80+
--local \
81+
--openroad_only \
82+
--threads ${numThreads}
83+
if [ ! -x tools/install/OpenROAD/bin/openroad ]; then
84+
echo "Error: tools/install/OpenROAD/bin/openroad is missing or not executable." >&2
85+
exit 1
86+
fi
87+
EOF
88+
89+
# tools/OpenROAD/src/sta is excluded because it is covered by a separate
90+
# commercial license agreement.
91+
RUN find /OpenROAD-flow-scripts/tools/OpenROAD \( -name "*LICENSE*" -o -name "*LICENSES*" \) \
92+
| grep -v '/OpenROAD/src/sta/' \
93+
| while IFS= read -r f; do \
94+
rel="${f#/OpenROAD-flow-scripts/tools/}"; \
95+
mkdir -p "/OpenROAD-flow-scripts/tools/install/licenses/$(dirname "$rel")"; \
96+
cp -r "$f" "/OpenROAD-flow-scripts/tools/install/licenses/$rel"; \
97+
done
98+
6399
FROM orfs-base
64100

65101
# The order for copying the directories is based on the frequency of changes (ascending order),
@@ -74,7 +110,7 @@ COPY --link flow/scripts flow/scripts
74110
COPY --link flow/designs flow/designs
75111
COPY --link tools/AutoTuner tools/AutoTuner
76112

77-
COPY --link --from=orfs-builder-base /OpenROAD-flow-scripts/tools/install tools/install
113+
COPY --link --from=orfs-openroad-builder /OpenROAD-flow-scripts/tools/install tools/install
78114
COPY --link \
79115
--exclude=.git* --exclude=tools/ --exclude=docs/ --exclude=docker/ \
80116
--exclude=flow/designs --exclude=flow/platforms --exclude=flow/scripts \

‎etc/DockerTag.sh‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@ if [[ "$@" == "-dev" ]]; then
1313
"./tools/OpenROAD/etc/DependencyInstaller.sh"
1414
)
1515
cat "${file_list[@]}" | sha256sum | awk '{print substr($1, 1, 6)}'
16+
elif [[ "$@" == "-tools" ]]; then
17+
# Everything the orfs-tools target of Dockerfile.builder depends on:
18+
# the dev image, the build scripts, the ignore file that filters the
19+
# build context, and the checked-out tools except OpenROAD.
20+
ignore_file=./docker/Dockerfile.builder.dockerignore
21+
if [[ ! -f "${ignore_file}" ]]; then
22+
ignore_file=./.dockerignore
23+
fi
24+
{
25+
./etc/DockerTag.sh -dev
26+
cat ./build_openroad.sh ./dev_env.sh ./etc/setup_compiler_wrappers.sh
27+
cat "${ignore_file}"
28+
# Drop the trailing describe output, which depends on fetched tags.
29+
git submodule status tools/yosys tools/kepler-formal | awk '{print $1, $2}'
30+
git ls-tree HEAD tools/ | grep -v -e 'tools/OpenROAD$' -e 'tools/AutoTuner$' \
31+
-e 'tools/yosys$' -e 'tools/kepler-formal$'
32+
} | sha256sum | awk '{print substr($1, 1, 6)}'
1633
elif [[ "$@" == "-master" ]]; then
1734
git fetch --tags >&2
1835
git -C tools/OpenROAD fetch --tags >&2
@@ -21,6 +38,8 @@ else
2138
echo "Usage:"
2239
echo " To generate a tag for images that only have dev dependencies:"
2340
echo " $0 -dev"
41+
echo " To generate a tag for the image with the prebuilt tools other than OpenROAD:"
42+
echo " $0 -tools"
2443
echo " To generate a tag for full releases based on master branch"
2544
echo " $0 -master"
2645
exit 1

0 commit comments

Comments
 (0)