Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mdbx_sys] README.md and build.rs to fix Windows build #91

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 >=5.0 <= 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`, `Windows SDK` and `C++ CMake tool for Windows` 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)

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

2. Restart `VSCode` 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 <=15.0` [bindgen requirements](https://rust-lang.github.io/rust-bindgen/requirements.html).
2. Build the library, and it should be successfully build 😀!
47 changes: 34 additions & 13 deletions packages/mdbx_sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,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");
.expect(mdbx.as_path().to_str().unwrap());

let core_path = mdbx.join("mdbx.c");
let mut core = fs::read_to_string(core_path.as_path()).unwrap();
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