Skip to content

Commit 3b464e5

Browse files
authored
Merge pull request #981 from vrc-get/litedb
litedb module updates
2 parents 01579c2 + 291e1cb commit 3b464e5

File tree

14 files changed

+615
-1136
lines changed

14 files changed

+615
-1136
lines changed

Cargo.lock

Lines changed: 111 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vrc-get-litedb/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "vrc-get-litedb"
3-
version = "0.1.5-beta.0"
3+
version = "0.2.0-beta.0"
44
edition.workspace = true
55
license.workspace = true
66
authors.workspace = true
@@ -28,10 +28,13 @@ include = [
2828
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
2929

3030
[dependencies]
31+
bson = "2.10.0"
3132
hex = "0.4.3"
3233
once_cell = "1.19.0"
3334
rand = "0.8.5"
35+
serde = "1.0.202"
3436

3537
[build-dependencies]
3638
ar = "0.9.0"
39+
cc = "1.0.97"
3740
object = { version = "0.35.0", default-features = false, features = ["macho"] }

vrc-get-litedb/build.rs

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ fn main() {
1212
println!("cargo:rerun-if-changed=dotnet/src");
1313
println!("cargo:rerun-if-changed=dotnet/LiteDB/LiteDB");
1414

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

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

52+
// link bootstrapper
53+
let bootstrapper = dotnet_sdk_folder.join(target_info.bootstrapper);
54+
if target_info.family == TargetFamily::Linux || target_info.family == TargetFamily::MacOS {
55+
// for unix-like platforms, generate a static library from bootstrapperdll and link it
56+
create_libbootstrapperdll_a(&bootstrapper, &patched_lib_folder, &target_info);
57+
println!("cargo:rustc-link-lib=static:+whole-archive=bootstrapperdll");
58+
} else {
59+
// for windows, generate a .lib file from bootstrapperdll.obj and link it
60+
create_libbootstrapperdll_lib(&bootstrapper, &patched_lib_folder, &target_info);
61+
println!("cargo:rustc-link-lib=static:+whole-archive=bootstrapperdll");
62+
}
63+
4764
// link prebuilt dotnet
4865
if target_info.family == TargetFamily::MacOS {
4966
// for apple platform, we need to fix object file a little
@@ -68,15 +85,6 @@ fn main() {
6885
remove_libunwind(&before, &patched);
6986
}
7087

71-
if target_info.family == TargetFamily::Linux {
72-
// start stop gc is not supported by dotnet.
73-
println!("cargo:rustc-link-arg=-Wl,-z,nostart-stop-gc");
74-
} else if target_info.family == TargetFamily::Windows {
75-
// "/merge:.modules=.rdata" "/merge:.unbox=.text"
76-
println!("cargo:rustc-link-arg=/merge:.modules=.rdata");
77-
println!("cargo:rustc-link-arg=/merge:.unbox=.text");
78-
}
79-
8088
let common_libs: &[&str] = &[
8189
//"static=Runtime.ServerGC",
8290
"static=Runtime.WorkstationGC",
@@ -241,3 +249,40 @@ fn remove_libunwind(archive: &Path, patched: &Path) {
241249
.flush()
242250
.expect("writing patched library");
243251
}
252+
253+
fn create_libbootstrapperdll_a(obj: &Path, folder: &Path, target_info: &TargetInformation) {
254+
let lib_path = folder.join("libbootstrapperdll.a");
255+
let file = std::fs::File::create(&lib_path).expect("failed to create libbootstrapperdll.a");
256+
let mut builder = ar::Builder::new(std::io::BufWriter::new(file));
257+
builder
258+
.append_file(
259+
b"bootstrapperdll.o",
260+
&mut std::fs::File::open(obj).expect("opening bootstrapperdll.o"),
261+
)
262+
.unwrap();
263+
264+
builder
265+
.into_inner()
266+
.unwrap()
267+
.flush()
268+
.expect("writing patched libbootstrapperdll.a");
269+
270+
if target_info.family == TargetFamily::MacOS {
271+
// for bsd, ranlib to index
272+
Command::new("ranlib")
273+
.arg(lib_path)
274+
.status()
275+
.expect("running ranlib");
276+
}
277+
}
278+
279+
fn create_libbootstrapperdll_lib(obj: &Path, folder: &Path, _target_info: &TargetInformation) {
280+
let lib_path = folder.join("bootstrapperdll.lib");
281+
282+
cc::windows_registry::find(std::env::var("TARGET").unwrap().as_str(), "lib.exe")
283+
.expect("finding lib.exe")
284+
.arg(format!("/out:{}", lib_path.to_str().unwrap()))
285+
.arg(obj)
286+
.status()
287+
.expect("running lib /out:bootstrapperdll.lib bootstrapperdll.obj");
288+
}

vrc-get-litedb/dotnet/LiteDB

0 commit comments

Comments
 (0)