Skip to content

Commit

Permalink
[mdbx_sys] README.md and build.rs fix to window builds
Browse files Browse the repository at this point in the history
  • Loading branch information
psengrith committed Jun 29, 2024
1 parent d5cee4a commit 7b36267
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 12 deletions.
12 changes: 11 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
"bug"
]
},
{
"login": "psengrith",
"name": "Sengrith",
"avatar_url": "https://avatars.githubusercontent.com/u/172288069?v=4",
"profile": "https://www.linkedin.com/in/psengrith/",
"contributions": [
"bug",
"doc"
]
},
{
"login": "leisim",
"name": "Simon Leier",
Expand Down Expand Up @@ -211,4 +221,4 @@
"repoHost": "https://github.com",
"skipCi": true,
"commitConvention": "angular"
}
}
1 change: 1 addition & 0 deletions packages/isar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ Big thanks go to these wonderful people:
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/inkomomutane"><img src="https://avatars.githubusercontent.com/u/57417802?v=4" width="100px;" alt=""/><br /><sub><b>Nelson Mutane</b></sub></a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Viper-Bit"><img src="https://avatars.githubusercontent.com/u/24822764?v=4" width="100px;" alt=""/><br /><sub><b>Peyman</b></sub></a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/psengrith"><img src="https://avatars.githubusercontent.com/u/172288069?v=4" width="100px;" alt=""/><br /><sub><b>Sengrith</b></sub></a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/leisim"><img src="https://avatars.githubusercontent.com/u/13610195?v=4" width="100px;" alt=""/><br /><sub><b>Simon Leier</b></sub></a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ika020202"><img src="https://avatars.githubusercontent.com/u/42883378?v=4" width="100px;" alt=""/><br /><sub><b>Ura</b></sub></a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/blendthink"><img src="https://avatars.githubusercontent.com/u/32213113?v=4" width="100px;" alt=""/><br /><sub><b>blendthink</b></sub></a></td>
Expand Down
53 changes: 53 additions & 0 deletions packages/mdbx_sys/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# mdbx_sys

Rust binding of mdbx.

## Build Setup (for Windows)

For triplet `x86_64-pc-windows-msvc`

1. Install rust to use triplet `x86_64-pc-windows-msvc`.

2. Install [MSYS2](https://www.msys2.org/).

- Make sure to add `msys\usr\bin` to environment variable `PATH`.

3. Use MSYS2 package manager to install neccessary build tools:

```{bash}
pacman -S --needed make
```

- Make sure to add `msys\mingw64\bin` to environment variable `PATH`.

3. Install `clang <= 15.0` (as a workaround for [#2500](https://github.com/rust-lang/rust-bindgen/issues/2500#issuecomment-1640545912)) from [llvm-project](https://github.com/llvm/llvm-project/releases/tag/llvmorg-15.0.7).

- Make sure to add `path\to\bin\libclang.dll` to environment variable `LIBCLANG_PATH`.
- Make sure option `MSVC` is selected when installing `Desktop Development with C++` build tool by using [Visual Studio Build Tools 2019](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools&rel=16)

5. Install [CMake](https://cmake.org/download/), and configure enivronment variable.

6. Restart VCCode instance to reload the environment variables. Then, build the library, and it should be successfully build 😀!

<!-- [Broken] For triplet `x86_64-pc-windows-gnu`
1. Install rust to use triplet `x86_64-pc-windows-gnu`.
2. Install [MSYS2](https://www.msys2.org/).
- Make sure to add `msys\usr\bin` to environment variable `PATH`.
3. Use MSYS2 package manager to install neccessary build tools:
```{bash}
pacman -S --needed make mingw-w64-x86_64-cmake mingw-w64-x86_64-rust mingw-w64-x86-64-clang
```
- Make sure to add `msys\mingw64\bin` to environment variable `PATH`.
- Make sure to add `path\to\bin\libclang.dll` to environment variable `LIBCLANG_PATH`.
4. Restart VCCode instance to reload the environment variables. Then, build the library, and it should be successfully build 😀! -->

## Other Unix/Linux-Based OS

1. Install `build-essential` and `clang >= 5.0` [bindgen requirements](https://rust-lang.github.io/rust-bindgen/requirements.html).
2. Build the library, and it should be successfully build 😀!
43 changes: 32 additions & 11 deletions packages/mdbx_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,31 @@ fn main() {
let is_android = env::var("CARGO_CFG_TARGET_OS").unwrap() == "android";

let _ = fs::remove_dir_all("libmdbx");
let mut mdbx = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap());
mdbx.push("libmdbx");

Command::new("git")
.arg("clone")
.arg(LIBMDBX_REPO)
.arg("--branch")
.arg(LIBMDBX_TAG)
.output()
.unwrap();
if !mdbx.exists() {
Command::new("git")
.arg("clone")
.arg(LIBMDBX_REPO)
.arg("--branch")
.arg(LIBMDBX_TAG)
.output()
.unwrap();
}

mdbx.push("dist-check");
let _ = fs::remove_dir_all(mdbx.as_path());
mdbx.pop();
mdbx.push("dist");
let _ = fs::remove_dir_all(mdbx.as_path());

Command::new("make")
.arg("release-assets")
.current_dir("libmdbx")
.output()
.unwrap();

let mut mdbx = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap());
mdbx.push("libmdbx");
mdbx.push("dist");

let core_path = mdbx.join("mdbx.c");
let mut core = fs::read_to_string(core_path.as_path()).unwrap();
core = core.replace("!CharToOemBuffA(buf, buf, size)", "false");
Expand All @@ -95,6 +101,14 @@ fn main() {
}
fs::write(core_path.as_path(), core).unwrap();

if env::var("TARGET").unwrap().contains("windows") {
let h_path = mdbx.join("mdbx.h");
let mut headers = fs::read_to_string(h_path.as_path()).expect("dist/mdbx.h was not found!");
// A temporary workaround since -DMDBX_LOCK_SUFFIX has no effect.
headers = headers.replace("\"-lck\"", "\".lock\"");
fs::write(h_path.as_path(), headers).unwrap();
}

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());

let bindings = bindgen::Builder::default()
Expand All @@ -111,6 +125,9 @@ fn main() {
.generate_comments(true)
.disable_header_comment()
.rustfmt_bindings(true)
.clang_arg("-Wno-ignored-attributes")
.clang_arg("-DNDEBUG 1")
.clang_arg("-DMDBX_WITHOUT_MSVC_CRT 1")
.generate()
.expect("Unable to generate bindings");

Expand All @@ -122,6 +139,10 @@ fn main() {
let flags = format!("{:?}", cc_builder.get_compiler().cflags_env());
cc_builder.flag_if_supported("-Wno-everything");

if env::var("TARGET").unwrap().ends_with("-musl") {
cc_builder.define("MDBX_HAVE_BUILTIN_CPU_SUPPORTS", "0");
}

if cfg!(windows) {
let dst = cmake::Config::new(&mdbx)
.define("MDBX_INSTALL_STATIC", "1")
Expand Down

0 comments on commit 7b36267

Please sign in to comment.