File tree Expand file tree Collapse file tree 5 files changed +52
-1
lines changed Expand file tree Collapse file tree 5 files changed +52
-1
lines changed Original file line number Diff line number Diff line change 82
82
printf '[profile.release]\nlto = "fat"\n' >> build/build_sysroot/sysroot_src/library/Cargo.toml
83
83
EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot --keep-lto-tests ${{ matrix.commands }}
84
84
85
- - name : Run y.sh cargo build
85
+ - name : LTO test
86
86
run : |
87
87
EMBED_LTO_BITCODE=1 CHANNEL="release" ./y.sh cargo build --release --manifest-path tests/hello-world/Cargo.toml
88
88
call_found=$(objdump -dj .text tests/hello-world/target/release/hello_world | grep -c "call .*mylib.*my_func" ) ||:
92
92
exit 1
93
93
fi
94
94
95
+ - name : Cross-language LTO test
96
+ run : |
97
+ pushd tests/cross_lang_lto
98
+ gcc -c -flto add.c -masm=intel -fPIC -O3
99
+ ar rcs libadd.a add.o
100
+ popd
101
+
102
+ 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
103
+ call_found=$(objdump -dj .text tests/cross_lang_lto/target/release/cross_lang_lto | grep -c "call .*my_add" ) ||:
104
+ if [ $call_found -gt 0 ]; then
105
+ echo "ERROR: call my_add found in asm"
106
+ echo "Test is done with cross-language LTO enabled, hence inlining should occur across object files"
107
+ exit 1
108
+ fi
109
+
95
110
# Summary job for the merge queue.
96
111
# ALL THE PREVIOUS JOBS NEED TO BE ADDED TO THE `needs` SECTION OF THIS JOB!
97
112
success_release :
Original file line number Diff line number Diff line change
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package ]]
6
+ name = " cross_lang_lto"
7
+ version = " 0.1.0"
Original file line number Diff line number Diff line change
1
+ [package ]
2
+ name = " cross_lang_lto"
3
+ version = " 0.1.0"
4
+ edition = " 2024"
5
+
6
+ [dependencies ]
Original file line number Diff line number Diff line change
1
+ #include <stdint.h>
2
+
3
+ uint32_t my_add (uint32_t a , uint32_t b ) {
4
+ return a + b ;
5
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Compile the C code with:
3
+ * gcc -c -flto add.c -ffat-lto-objects
4
+ * ar rcs libadd.a add.o
5
+ *
6
+ * Compile the Rust code with:
7
+ * EMBED_LTO_BITCODE=1 CG_RUSTFLAGS="-L native=. -Clinker-plugin-lto -Clinker=gcc" y cargo run --release
8
+ */
9
+
10
+ #[ link( name="add" ) ]
11
+ unsafe extern "C" {
12
+ fn my_add ( a : u32 , b : u32 ) -> u32 ;
13
+ }
14
+
15
+ fn main ( ) {
16
+ let res = unsafe { my_add ( 30 , 12 ) } ;
17
+ println ! ( "{}" , res) ;
18
+ }
You can’t perform that action at this time.
0 commit comments