Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
printf '[profile.release]\nlto = "fat"\n' >> build/build_sysroot/sysroot_src/library/Cargo.toml
EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot --keep-lto-tests ${{ matrix.commands }}

- name: Run y.sh cargo build
- name: LTO test
run: |
EMBED_LTO_BITCODE=1 CHANNEL="release" ./y.sh cargo build --release --manifest-path tests/hello-world/Cargo.toml
call_found=$(objdump -dj .text tests/hello-world/target/release/hello_world | grep -c "call .*mylib.*my_func" ) ||:
Expand All @@ -92,6 +92,21 @@ jobs:
exit 1
fi

- name: Cross-language LTO test
run: |
pushd tests/cross_lang_lto
gcc -c -flto add.c -masm=intel -fPIC -O3
ar rcs libadd.a add.o
popd

EMBED_LTO_BITCODE=1 CHANNEL="release" CG_RUSTFLAGS="-L native=. -Clinker-plugin-lto -Clinker=gcc" ./y.sh cargo build --release --manifest-path tests/cross_lang_lto/Cargo.toml
call_found=$(objdump -dj .text tests/cross_lang_lto/target/release/cross_lang_lto | grep -c "call .*my_add" ) ||:
if [ $call_found -gt 0 ]; then
echo "ERROR: call my_add found in asm"
echo "Test is done with cross-language LTO enabled, hence inlining should occur across object files"
exit 1
fi

# Summary job for the merge queue.
# ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB!
success_release:
Expand Down
7 changes: 7 additions & 0 deletions tests/cross_lang_lto/Cargo.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "cross_lang_lto"
version = "0.1.0"
6 changes: 6 additions & 0 deletions tests/cross_lang_lto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "cross_lang_lto"
version = "0.1.0"
edition = "2024"

[dependencies]
5 changes: 5 additions & 0 deletions tests/cross_lang_lto/add.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdint.h>

uint32_t my_add(uint32_t a, uint32_t b) {
return a + b;
}
18 changes: 18 additions & 0 deletions tests/cross_lang_lto/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Compile the C code with:
* gcc -c -flto add.c -ffat-lto-objects
* ar rcs libadd.a add.o
*
* Compile the Rust code with:
* EMBED_LTO_BITCODE=1 CG_RUSTFLAGS="-L native=. -Clinker-plugin-lto -Clinker=gcc" y cargo run --release
*/

#[link(name="add")]
unsafe extern "C" {
fn my_add(a: u32, b: u32) -> u32;
}

fn main() {
let res = unsafe { my_add(30, 12) };
println!("{}", res);
}