Skip to content

Commit 118453c

Browse files
committed
[Meta] Rust builds always link with libc
1 parent 943e1b4 commit 118453c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

scripts/build_rust_toolchain.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from build_utils import run_and_check
1111
from build_utils import run_and_capture_output_and_check
1212

13-
1413
_REPO_ROOT = Path(__file__).parents[1]
1514
_RUST_PROGRAMS_DIR = _REPO_ROOT / "rust_programs"
1615
# TODO(PT): Template this file to include the full path to x86_64-elf-axle-gcc
@@ -84,14 +83,14 @@ def _build_rust_libc_port(temp_dir: Path) -> None:
8483
env = {'CC': toolchain_dir / 'bin' / 'x86_64-elf-axle-gcc'}
8584
run_and_check(
8685
[
87-
'cargo',
88-
'build',
89-
'--no-default-features',
90-
'-Zbuild-std=core,alloc',
86+
'cargo',
87+
'build',
88+
'--no-default-features',
89+
'-Zbuild-std=core,alloc',
9190
# '-Z macro-backtrace',
9291
f'--target={_TARGET_SPEC_FILE.as_posix()}',
9392
],
94-
cwd=libc_dir,
93+
cwd=libc_dir,
9594
env_additions=env
9695
)
9796

@@ -133,7 +132,7 @@ def test_rust_programs() -> None:
133132
],
134133
cwd=program_dir
135134
)
136-
135+
137136

138137
def build_rust_programs(check_only: bool = False) -> None:
139138
cargo_workspace_dir = _RUST_PROGRAMS_DIR
@@ -151,7 +150,11 @@ def build_rust_programs(check_only: bool = False) -> None:
151150
'features=host_dep',
152151
],
153152
cwd=cargo_workspace_dir,
154-
env_additions={"RUSTFLAGS": "-Cforce-frame-pointers=yes"},
153+
# PT: Without manually linking axle's newlib port, linking failed after adding some Rust code that
154+
# implicitly called `fmod`:
155+
# /libm.a(lib_a-w_fmod.o): in function `fmod':
156+
# .../newlib/libm/math/w_fmod.c:89: undefined reference to `__errno'
157+
env_additions={"RUSTFLAGS": "-Cforce-frame-pointers=yes -Clink-arg=-lc"},
155158
)
156159
for entry in cargo_workspace_dir.iterdir():
157160
if not entry.is_dir():

0 commit comments

Comments
 (0)