Skip to content

Commit

Permalink
bindings: unfortunately, LTO does not seem to work...
Browse files Browse the repository at this point in the history
I'm not sure why this is happening. My best guess is that it's either because:
  - the specific compiler that `cc` ends up using doesn't play nice with the bitcode that rustc/the LLVM linker plugin end up producing and expecting
     + the linker-plugin based LTO page mentions this: https://doc.rust-lang.org/rustc/linker-plugin-lto.html#toolchain-compatibility
     + also, there's actually (afaik) no easy way to externally (outside of `build.rs`) set what compiler `cc` should use (there are env vars but not ones that are specific to `cc`) and it's probably best not to assume that users will be using `clang`..
  - or, we're not actually producing the ar format necessary, but this seems unlikely

In any case, this is probably a good thing to stick behind a feature flag since the LTO setup seems somewhat brittle and we can't/shouldn't expect users to have modern versions of lld/clang.
  • Loading branch information
rrbutani committed Jun 21, 2020
1 parent 85b404c commit 3cf85f4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[build]
rustdocflags = ["--cfg", "docs"]
rustflags = ["-Clinker-plugin-lto", "-Clinker=clang", "-Clink-arg=-fuse-ld=lld"]
3 changes: 2 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ fn main() -> Result<()> {
}

build
.flag_if_supported("-flto")
// .flag_if_supported("-flto")
// .flag_if_supported("-flto=thin")
.flag_if_supported("-std=c++14")
.flag_if_supported("-Wno-format-security")
.cargo_metadata(true)
Expand Down

0 comments on commit 3cf85f4

Please sign in to comment.