Skip to content

Commit

Permalink
Enable LTO support. (#11)
Browse files Browse the repository at this point in the history
Update to c-gull 0.15.10, which fixes LTO compatibility. Add an example
that uses LTO, and test it in the example-crates test.
  • Loading branch information
sunfishcode authored Oct 7, 2023
1 parent 9e38cc9 commit edb746a
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exclude = ["/.github", "ci"]
keywords = ["linux"]

[dependencies]
c-gull = { version = "0.15.2", default-features = false, features = ["eyra"] }
c-gull = { version = "0.15.10", default-features = false, features = ["eyra"] }

[dev-dependencies]
assert_cmd = "2.0.12"
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ Known limitations in `Eyra` include:
- Dynamic linking isn't implemented yet.
- Many libc C functions that aren't typically needed by most Rust programs
aren't implemented yet.
- Enabling LTO doesn't work yet.

## Background

Expand Down
2 changes: 2 additions & 0 deletions example-crates/hello-world-lto/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/target
Cargo.lock
15 changes: 15 additions & 0 deletions example-crates/hello-world-lto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "hello-world-lto"
version = "0.0.0"
edition = "2021"
publish = false

[dependencies]
std = { package = "eyra", path = "../.." }

# Enable LTO.
[profile.release]
lto = true

# This is just an example crate, and not part of the c-ward workspace.
[workspace]
5 changes: 5 additions & 0 deletions example-crates/hello-world-lto/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This crate demonstrates the use of Eyra with LTO!

This is the same as the [hello-world] example, but enables LTO.

[hello-world]: https://github.com/sunfishcode/eyra/tree/main/example-crates/hello-world/
4 changes: 4 additions & 0 deletions example-crates/hello-world-lto/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
// Pass -nostartfiles to the linker.
println!("cargo:rustc-link-arg=-nostartfiles");
}
3 changes: 3 additions & 0 deletions example-crates/hello-world-lto/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
12 changes: 12 additions & 0 deletions tests/example_crates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ fn example_crate_hello_world() {
test_crate("hello-world", &[], &[], "Hello, world!\n", "", None);
}

#[test]
fn example_crate_hello_world_lto() {
test_crate(
"hello-world",
&["--release"],
&[],
"Hello, world!\n",
"",
None,
);
}

#[test]
fn example_crate_extern_crate_hello_world() {
test_crate(
Expand Down

0 comments on commit edb746a

Please sign in to comment.