[Solved] Avoid building LLVM?

Does anyone know how to avoid building LLVM. It more than doubles the build time.

I came across Building with system LLVM, but it is old and the issue is locked.

I still build with system LLVM. Here is how. In your build directory, create config.toml:

[target.<target>]
llvm-config = "/usr/bin/llvm-config-8"

That’s all.

2 Likes

Do you know if there is a minimum LLVM version? I get a linker error when using LLVM 7.

$ ./x.py build --stage 1
Updating only changed submodules
Submodules updated in 0.02 seconds
    Finished dev [unoptimized] target(s) in 0.25s
Building stage0 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized] target(s) in 0.28s
Copying stage0 std from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building stage0 test artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized] target(s) in 0.24s
Copying stage0 test from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building stage0 compiler artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized] target(s) in 0.29s
Copying stage0 rustc from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building stage0 codegen artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu, llvm)
    Finished release [optimized] target(s) in 0.25s
Assembling stage1 compiler (x86_64-unknown-linux-gnu)
Building stage1 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
error: process didn't exit successfully: `/nobackup/rust3/build/bootstrap/debug/rustc -vV` (exit code: 1)
--- stdout
rustc 1.36.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.36.0-dev

--- stderr
error: couldn't load codegen backend "/nobackup/rust3/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_codegen_llvm-llvm.so": "/nobackup/rust3/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/codegen-backends/librustc_codegen_llvm-llvm.so: undefined symbol: ffi_type_float"


command did not execute successfully: "/nobackup/rust3/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--features" "panic-unwind backtrace" "--manifest-path" "/nobackup/rust3/src/libstd/Cargo.toml" "--message-format" "json"
expected success, got: exit code: 101
failed to run: /nobackup/rust3/build/bootstrap/debug/bootstrap build --stage 1
Build completed unsuccessfully in 0:00:02

The minimum is LLVM 6, but your issue is with linking libffi – see:

There are a few ways to hack -lffi into the build, or you may have better luck linking LLVM dynamically, which is what most distros do. Try adding link-shared = true to your build config, and make sure libLLVM is in your dynamic search path – e.g. LD_LIBRARY_PATH if not already in a default location.

1 Like

That worked! Thanks :slight_smile: