Skip to content

Commit

Permalink
feat: use fat lto
Browse files Browse the repository at this point in the history
  • Loading branch information
iujakchu committed Jun 3, 2022
1 parent 2d60b3f commit bbc0a86
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ back/target/
**/Cargo.lock
.cache/
compile_commands.json
after/

# MacOS Cache
.DS_Store
Expand Down
4 changes: 4 additions & 0 deletions back/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ cxx = "1.0"
cxx-build = "1.0"
[lib]
crate-type = ["staticlib"]


[profile.release]
lto = true
1 change: 1 addition & 0 deletions back/src/lib.rs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(dead_code)]
use std::fmt;

#[cxx::bridge]
Expand Down
6 changes: 2 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ There are some tools I have used.

# Run
```shell
cd back
cargo build --release
cd ..
xmake
xmake run
```
Expand All @@ -21,4 +18,5 @@ xmake run
- [x] Dockerfile
# Credits
* This project is almost a fork of [cxx-cmake-example](https://github.com/XiangpengHao/cxx-cmake-example) .
* [lto](https://blog.llvm.org/2019/09/closing-gap-cross-language-lto-between.html)
* explain the steps of [lto](https://blog.llvm.org/2019/09/closing-gap-cross-language-lto-between.html)
* [rustc lto plugin](https://doc.rust-lang.org/rustc/linker-plugin-lto.html)
File renamed without changes.
32 changes: 22 additions & 10 deletions xmake.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
add_rules("mode.debug", "mode.release")
add_rules("mode.release")

target("cm")
local rust_backend = "back"
target("xm")
before_build(function(target)
os.cd("back")
os.exec("cargo build --release --verbose")
os.cd("..")
os.mkdir("after", "after/include")
os.cp("back/target/cxxbridge/back/src/*.h", "after/include/")
os.cp("back/target/cxxbridge/back/src/*.cc", "after/")
os.cp("back/target/cxxbridge/rust/*.h", "after/include/")
end)
set_toolchains("clang-13")
set_languages("cxx17")
set_kind("binary")

add_files("src/*.cpp")
add_includedirs("back/target/cxxbridge/back/src/")
add_includedirs("include/")
add_files("back/target/cxxbridge/back/src/lib.rs.cc")
add_links("back")
add_includedirs("src/include")

add_files("after/lib.rs.cc")
add_includedirs("after/include")

add_links("stdc++")
add_linkdirs(rust_backend .. "/target/release/")
add_links(rust_backend)

add_cxflags("-flto=thin")
-- add_links("pthread")
-- add_links("dl")
add_linkdirs("back/target/release/")
add_ldflags("-fuse-ld=mold")
add_ldflags("-flto=thin")
add_ldflags("-fuse-ld=mold")

0 comments on commit bbc0a86

Please sign in to comment.