Skip to content

Commit cc0ef3b

Browse files
committed
Make builds more hermetic by using prebuilt gcc toolchain
Previously the Rust builds were using the system gcc toolchain for host builds. This CL adds the -B flag to the compiler wrappers to pass in the location of the prebuilt gcc toolchain. Test: ./build.py Change-Id: Ie53f16f2513d3335f00a25d205b3e93ce538070b
1 parent 1a1c595 commit cc0ef3b

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

config.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def instantiate_template_file(template_path: Path, output_path: Path, make_exec:
6666
output_path.chmod(output_path.stat().st_mode | stat.S_IEXEC)
6767

6868

69-
def host_config(target: str, sysroot_flags: str) -> str:
69+
def host_config(target: str, toolchain_flags: str) -> str:
7070
cc_wrapper_name = OUT_PATH_WRAPPERS / ('clang-%s' % target)
7171
cxx_wrapper_name = OUT_PATH_WRAPPERS / ('clang++-%s' % target)
7272

@@ -76,15 +76,15 @@ def host_config(target: str, sysroot_flags: str) -> str:
7676
real_cc=CC_PATH,
7777
ld_option=LD_OPTIONS,
7878
target=target,
79-
sysroot_flags=sysroot_flags)
79+
toolchain_flags=toolchain_flags)
8080

8181
instantiate_template_exec(
8282
HOST_CXX_WRAPPER_TEMPLATE,
8383
cxx_wrapper_name,
8484
real_cxx=CXX_PATH,
8585
ld_option=LD_OPTIONS,
8686
target=target,
87-
sysroot_flags=sysroot_flags,
87+
toolchain_flags=toolchain_flags,
8888
cxxstd=CXXSTD_PATH,
8989
cxx_linker_flags=CXX_LINKER_FLAGS)
9090

@@ -116,18 +116,21 @@ def device_config(target: str) -> str:
116116

117117
def configure():
118118
"""Generates config.toml for the rustc build."""
119-
sysroot = None
120-
# Apple removed the normal sysroot at / on Mojave+, so we need
121-
# to go hunt for it on OSX
122-
# On pre-Mojave, this command will output the empty string.
119+
host_toolchain_flags = None
120+
123121
if build_platform.system() == 'darwin':
122+
# Apple removed the normal sysroot at / on Mojave+, so we need
123+
# to go hunt for it on OSX
124+
# On pre-Mojave, this command will output the empty string.
124125
output = subprocess.check_output(
125126
['xcrun', '--sdk', 'macosx', '--show-sdk-path'])
126-
sysroot = output.rstrip().decode('utf-8')
127-
host_sysroot_flags = ("--sysroot " + sysroot) if sysroot else ""
127+
host_toolchain_flags = "--sysroot " + output.rstrip().decode('utf-8')
128+
else:
129+
# On Linux build hosts we need to set the path to the gcc toolchain.
130+
host_toolchain_flags = "-B " + GCC_TOOLCHAIN_PATH.as_posix()
128131

129132
host_configs = '\n'.join(
130-
[host_config(target, host_sysroot_flags) for target in HOST_TARGETS])
133+
[host_config(target, host_toolchain_flags) for target in HOST_TARGETS])
131134
device_configs = '\n'.join(
132135
[device_config(target) for target in DEVICE_TARGETS])
133136

paths.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
from pathlib import Path
1717
import build_platform
1818

19-
STAGE0_RUST_VERSION = '1.55.0'
20-
CLANG_REVISION = 'r433403'
21-
CLANG_NAME: str = 'clang-{0}'.format(CLANG_REVISION)
19+
STAGE0_RUST_VERSION: str = '1.55.0'
20+
CLANG_REVISION: str = 'r433403'
21+
CLANG_NAME: str = 'clang-{0}'.format(CLANG_REVISION)
22+
GLIBC_VERSION: str = '2.17-4.8'
2223

2324
TOOLCHAIN_PATH: Path = Path(__file__).parent.resolve()
2425
WORKSPACE_PATH: Path = (TOOLCHAIN_PATH / '..' / '..').resolve()
@@ -33,12 +34,13 @@
3334
OUT_PATH_STDLIB_SRCS: Path = OUT_PATH_PACKAGE / 'src' / 'stdlibs'
3435
OUT_PATH_WRAPPERS: Path = OUT_PATH / 'wrappers'
3536

36-
LLVM_BUILD_PATH: Path = OUT_PATH_RUST_SOURCE / 'build' / 'x86_64-unknown-linux-gnu' / 'llvm' / 'build'
37+
LLVM_BUILD_PATH: Path = OUT_PATH_RUST_SOURCE / 'build' / build_platform.triple() / 'llvm' / 'build'
3738

3839
PREBUILT_PATH: Path = WORKSPACE_PATH / 'prebuilts'
3940
RUST_PREBUILT_PATH: Path = PREBUILT_PATH / 'rust' / build_platform.prebuilt() / STAGE0_RUST_VERSION
4041
LLVM_PREBUILT_PATH: Path = PREBUILT_PATH / 'clang' / 'host' / build_platform.prebuilt() / CLANG_NAME
4142
LLVM_CXX_RUNTIME_PATH: Path = LLVM_PREBUILT_PATH / 'lib64'
43+
GCC_TOOLCHAIN_PATH: Path = PREBUILT_PATH / 'gcc' / build_platform.prebuilt() / 'host' / ('x86_64-linux-glibc' + GLIBC_VERSION)
4244

4345
# We live at prebuilts/rust/${BUILD_PLATFORM}/${VERSION}/bin
4446
# libc++ lives at prebuilts/clang/host/${BUILD_PLATFORM}

templates/host_cc_wrapper.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
$real_cc $$* $ld_option --target=$target $sysroot_flags
2+
$real_cc $$* $ld_option --target=$target $toolchain_flags

templates/host_cxx_wrapper.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/bin/bash
2-
$real_cxx -I$cxxstd $$* $ld_option --target=$target $sysroot_flags $cxx_linker_flags -stdlib=libc++
2+
$real_cxx -I$cxxstd $$* $ld_option --target=$target $toolchain_flags $cxx_linker_flags -stdlib=libc++

0 commit comments

Comments
 (0)