Skip to content

Commit

Permalink
bindings: put lto behind a flag
Browse files Browse the repository at this point in the history
The first hypothesis in the last commit was correct; it was compiler verion mismatch.

Unfortunately, though things now work locally, we can't enable LTO by default since we can't assume that all users will have the right version of clang/lld (or even be using clang/lld at all).
  • Loading branch information
rrbutani committed Jun 21, 2020
1 parent 3cf85f4 commit c8139dc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .cargo/config
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[build]
rustdocflags = ["--cfg", "docs"]
rustflags = ["-Clinker-plugin-lto", "-Clinker=clang", "-Clink-arg=-fuse-ld=lld"]

# Uncomment this when using the `lto` feature.
# rustflags = ["-Clinker-plugin-lto", "-Clinker=clang", "-Clink-arg=-fuse-ld=lld"]
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ syn = { version = "1.0", optional = true, default-features = false, features = [
[profile.release]
opt-level = 3
lto = true
codegen-units = 1


[features]
Expand All @@ -59,6 +60,7 @@ grader = ["frontend"]
frontend = []

generate-fresh = ["bindgen", "proc-macro2", "quote", "syn", "grader", "frontend"]
lto = []


[package.metadata.docs.rs]
Expand Down
6 changes: 4 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,11 @@ fn main() -> Result<()> {
build.flag("/EHsc");
}

if cfg!(feature = "lto") {
build.flag_if_supported("-flto=thin");
}

build
// .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 c8139dc

Please sign in to comment.