Skip to content

Commit

Permalink
Merge pull request #981 from vrc-get/litedb
Browse files Browse the repository at this point in the history
litedb module updates
  • Loading branch information
anatawa12 committed May 17, 2024
2 parents 01579c2 + 291e1cb commit 3b464e5
Show file tree
Hide file tree
Showing 14 changed files with 615 additions and 1,136 deletions.
116 changes: 111 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion vrc-get-litedb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vrc-get-litedb"
version = "0.1.5-beta.0"
version = "0.2.0-beta.0"
edition.workspace = true
license.workspace = true
authors.workspace = true
Expand Down Expand Up @@ -28,10 +28,13 @@ include = [
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bson = "2.10.0"
hex = "0.4.3"
once_cell = "1.19.0"
rand = "0.8.5"
serde = "1.0.202"

[build-dependencies]
ar = "0.9.0"
cc = "1.0.97"
object = { version = "0.35.0", default-features = false, features = ["macho"] }
65 changes: 55 additions & 10 deletions vrc-get-litedb/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ fn main() {
println!("cargo:rerun-if-changed=dotnet/src");
println!("cargo:rerun-if-changed=dotnet/LiteDB/LiteDB");

// currently this code is only tested on macOS.
// Note for users of this library:
// The NativeAOT does not support start-stop-gc so you have to disable it.
if std::env::var("TARGET").unwrap().contains("linux") {
// start stop gc is not supported by dotnet.
println!("cargo:rustc-link-arg=-Wl,-z,nostart-stop-gc");
}

let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
let target_info = TargetInformation::from_triple(std::env::var("TARGET").unwrap().as_str());
Expand Down Expand Up @@ -44,6 +49,18 @@ fn main() {
path = dotnet_built.parent().unwrap().display()
);

// link bootstrapper
let bootstrapper = dotnet_sdk_folder.join(target_info.bootstrapper);
if target_info.family == TargetFamily::Linux || target_info.family == TargetFamily::MacOS {
// for unix-like platforms, generate a static library from bootstrapperdll and link it
create_libbootstrapperdll_a(&bootstrapper, &patched_lib_folder, &target_info);
println!("cargo:rustc-link-lib=static:+whole-archive=bootstrapperdll");
} else {
// for windows, generate a .lib file from bootstrapperdll.obj and link it
create_libbootstrapperdll_lib(&bootstrapper, &patched_lib_folder, &target_info);
println!("cargo:rustc-link-lib=static:+whole-archive=bootstrapperdll");
}

// link prebuilt dotnet
if target_info.family == TargetFamily::MacOS {
// for apple platform, we need to fix object file a little
Expand All @@ -68,15 +85,6 @@ fn main() {
remove_libunwind(&before, &patched);
}

if target_info.family == TargetFamily::Linux {
// start stop gc is not supported by dotnet.
println!("cargo:rustc-link-arg=-Wl,-z,nostart-stop-gc");
} else if target_info.family == TargetFamily::Windows {
// "/merge:.modules=.rdata" "/merge:.unbox=.text"
println!("cargo:rustc-link-arg=/merge:.modules=.rdata");
println!("cargo:rustc-link-arg=/merge:.unbox=.text");
}

let common_libs: &[&str] = &[
//"static=Runtime.ServerGC",
"static=Runtime.WorkstationGC",
Expand Down Expand Up @@ -241,3 +249,40 @@ fn remove_libunwind(archive: &Path, patched: &Path) {
.flush()
.expect("writing patched library");
}

fn create_libbootstrapperdll_a(obj: &Path, folder: &Path, target_info: &TargetInformation) {
let lib_path = folder.join("libbootstrapperdll.a");
let file = std::fs::File::create(&lib_path).expect("failed to create libbootstrapperdll.a");
let mut builder = ar::Builder::new(std::io::BufWriter::new(file));
builder
.append_file(
b"bootstrapperdll.o",
&mut std::fs::File::open(obj).expect("opening bootstrapperdll.o"),
)
.unwrap();

builder
.into_inner()
.unwrap()
.flush()
.expect("writing patched libbootstrapperdll.a");

if target_info.family == TargetFamily::MacOS {
// for bsd, ranlib to index
Command::new("ranlib")
.arg(lib_path)
.status()
.expect("running ranlib");
}
}

fn create_libbootstrapperdll_lib(obj: &Path, folder: &Path, _target_info: &TargetInformation) {
let lib_path = folder.join("bootstrapperdll.lib");

cc::windows_registry::find(std::env::var("TARGET").unwrap().as_str(), "lib.exe")
.expect("finding lib.exe")
.arg(format!("/out:{}", lib_path.to_str().unwrap()))
.arg(obj)
.status()
.expect("running lib /out:bootstrapperdll.lib bootstrapperdll.obj");
}
2 changes: 1 addition & 1 deletion vrc-get-litedb/dotnet/LiteDB

0 comments on commit 3b464e5

Please sign in to comment.