Skip to content

Commit 496c47a

Browse files
timn-nexthopbenoit-nexthop
authored andcommitted
Support building with sccache
- Install sccache in Docker image - Add an extras mount directory and use it for sccache - Add --extra-cmake-defines argument to docker-build.py so the caller can pass CMAKE_C_COMPILER_LAUNCHER etc. to the build.
1 parent c3340ff commit 496c47a

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

fboss/oss/docker/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ RUN dnf install git sudo lsof -y
55
# Use /var/FBOSS as the set location to clone the git repository and store the outputs of the build.
66
WORKDIR /var/FBOSS/
77

8+
# Download and install sccache
9+
RUN version=v0.11.0 && \
10+
curl -L https://github.com/mozilla/sccache/releases/download/$version/sccache-$version-x86_64-unknown-linux-musl.tar.gz -o sccache.tar.gz && \
11+
tar xzf sccache.tar.gz && \
12+
mv sccache-$version-x86_64-unknown-linux-musl/sccache /usr/local/bin/ && \
13+
rm -rf sccache-$version-x86_64-unknown-linux-musl sccache.tar.gz
14+
15+
# Mount point for extra files.
16+
RUN mkdir -p /var/extras
17+
818
RUN mkdir -p /var/FBOSS/fboss
919
COPY . fboss
1020
WORKDIR fboss

fboss/oss/scripts/docker-build.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Copyright 2004-present Facebook. All Rights Reserved.
33

44
import argparse
5+
import json
56
import os
67
import re
78
import shlex
@@ -19,6 +20,8 @@
1920
OPT_ARG_ADD_BUILD_ENV_VAR = "--env-var"
2021
OPT_ARG_LOCAL = "--local"
2122
OPT_ARG_NUM_JOBS = "--num-jobs"
23+
OPT_ARG_EXTRAS_DIR = "--extras-dir"
24+
OPT_ARG_EXTRA_CMAKE_DEFINES = "--extra-cmake-defines"
2225

2326
FBOSS_IMAGE_NAME = "fboss_image"
2427
FBOSS_CONTAINER_NAME = "FBOSS_BUILD_CONTAINER"
@@ -157,6 +160,26 @@ def parse_args():
157160
"If unspecified, the default is the number of cpus. (CPU(s) in lspcu output)"
158161
),
159162
)
163+
parser.add_argument(
164+
OPT_ARG_EXTRAS_DIR,
165+
type=str,
166+
required=False,
167+
help=(
168+
"The contents of this directory will be mounted into the docker "
169+
"image at /var/extras."
170+
),
171+
)
172+
parser.add_argument(
173+
OPT_ARG_EXTRA_CMAKE_DEFINES,
174+
type=str,
175+
required=False,
176+
help=(
177+
"Extra cmake defines passed to getdeps.py: "
178+
"Input json map that contains extra cmake defines to be used "
179+
"when compiling the current project and all its deps. "
180+
'e.g: \'{"CMAKE_CXX_FLAGS": "--bla"}\''
181+
),
182+
)
160183

161184
return parser.parse_args()
162185

@@ -236,6 +259,8 @@ def run_fboss_build(
236259
env_vars: List[str],
237260
use_local: bool,
238261
num_jobs: Optional[int],
262+
extras_dir: Optional[str],
263+
extra_cmake_defines: Optional[str],
239264
):
240265
use_stable_hashes()
241266

@@ -261,15 +286,26 @@ def run_fboss_build(
261286
# Add TTY flags
262287
if docker_output:
263288
cmd_args.append("-it")
289+
if extras_dir:
290+
cmd_args.extend(["-v", f"{extras_dir}:/var/extras:rw"])
264291
# Add args for docker container name
265292
cmd_args.append(f"--name={FBOSS_CONTAINER_NAME}")
266293
# Add args for image name
267294
cmd_args.append(f"{FBOSS_IMAGE_NAME}:latest")
268295
# Add build command args
296+
extra_defines = {
297+
"CMAKE_BUILD_TYPE": "MinSizeRel",
298+
"CMAKE_CXX_STANDARD": "20",
299+
"CMAKE_C_COMPILER": "/opt/rh/gcc-toolset-12/root/usr/bin/gcc",
300+
"CMAKE_CXX_COMPILER": "/opt/rh/gcc-toolset-12/root/usr/bin/g++",
301+
}
302+
if extra_cmake_defines:
303+
for k, v in json.loads(extra_cmake_defines).items():
304+
extra_defines[k] = v
269305
build_cmd = [
270306
"./build/fbcode_builder/getdeps.py",
271307
"build",
272-
'--extra-cmake-defines={"CMAKE_BUILD_TYPE": "MinSizeRel", "CMAKE_CXX_STANDARD": "20", "CMAKE_C_COMPILER": "/opt/rh/gcc-toolset-12/root/usr/bin/gcc", "CMAKE_CXX_COMPILER": "/opt/rh/gcc-toolset-12/root/usr/bin/g++"}',
308+
f"--extra-cmake-defines={json.dumps(extra_defines)}",
273309
"--scratch-path",
274310
f"{CONTAINER_SCRATCH_PATH}",
275311
]
@@ -336,6 +372,8 @@ def main():
336372
args.env_vars,
337373
args.local,
338374
args.num_jobs,
375+
args.extras_dir,
376+
args.extra_cmake_defines,
339377
)
340378

341379
cleanup_fboss_build_container()

0 commit comments

Comments
 (0)