Skip to content
This repository has been archived by the owner on Sep 13, 2023. It is now read-only.

Update lmdb to latest version and other goodies #56

Merged
merged 11 commits into from Sep 5, 2019
8 changes: 4 additions & 4 deletions .travis.yml
Expand Up @@ -9,10 +9,10 @@ os:
- osx

rust:
- 1.30.0
- stable
- beta
- nightly
- 1.37.0
- stable
- beta
- nightly

script:
- cargo build --verbose
Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Expand Up @@ -34,9 +34,9 @@ members = [
]

[dependencies]
bitflags = "1"
byteorder = "1.0"
libc = "0.2"
bitflags = "1.1.0"
byteorder = "1.3.2"
libc = "0.2.62"

# In order to ensure that we test lmdb-rkv in CI against the in-tree version
# of lmdb-rkv-sys, we specify the dependency as a path here.
Expand All @@ -49,5 +49,5 @@ libc = "0.2"
lmdb-rkv-sys = { path = "./lmdb-sys" }

[dev-dependencies]
rand = "0.4"
tempdir = "0.3"
rand = "0.4.6"
tempdir = "0.3.7"
114 changes: 57 additions & 57 deletions azure-pipelines-template.yml
@@ -1,58 +1,58 @@
jobs:
- job: ${{ parameters.name }}
pool:
vmImage: ${{ parameters.vmImage }}
strategy:
matrix:
stable:
rustup_toolchain: stable
beta:
rustup_toolchain: beta
nightly:
rustup_toolchain: nightly
steps:
# Linux and macOS.
- ${{ if ne(parameters.name, 'Windows') }}:
- script: |
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $RUSTUP_TOOLCHAIN
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin"
displayName: Install rust
# Windows.
- ${{ if eq(parameters.name, 'Windows') }}:
- script: |
curl -sSf -o rustup-init.exe https://win.rustup.rs
rustup-init.exe -y --default-toolchain %RUSTUP_TOOLCHAIN%
set PATH=%PATH%;%USERPROFILE%\.cargo\bin
echo "##vso[task.setvariable variable=PATH;]%PATH%;%USERPROFILE%\.cargo\bin"
displayName: Install rust (windows)
# All platforms.
- script: |
rustc -Vv
cargo -V
displayName: Query rust and cargo versions
- script: cargo build
displayName: Build
- script: |
cargo test --all --verbose
cargo test --release --all --verbose
displayName: Test
# Linux and macOS w/nightly toolchain.
# Ideally we'd only run the script for the nightly toolchain, but I can't
# figure out how to determine that within the Azure Pipelines conditional.
- ${{ if ne(parameters.name, 'Windows') }}:
- script: |
export RUST_BACKTRACE=1
if [ "$RUSTUP_TOOLCHAIN" = "nightly" ]
then cargo bench --all --verbose;
fi
displayName: Bench
# Windows w/nightly toolchain.
# Ideally we'd only run the script for the nightly toolchain, but I can't
# figure out how to determine that within the Azure Pipelines conditional.
- ${{ if eq(parameters.name, 'Windows') }}:
- script: |
SET RUST_BACKTRACE=1
if "%RUSTUP_TOOLCHAIN%" == "nightly" (
cargo bench --all --verbose
)
displayName: Bench
- job: ${{ parameters.name }}
pool:
vmImage: ${{ parameters.vmImage }}
strategy:
matrix:
stable:
rustup_toolchain: stable
beta:
rustup_toolchain: beta
nightly:
rustup_toolchain: nightly
steps:
# Linux and macOS.
- ${{ if ne(parameters.name, 'Windows') }}:
- script: |
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain $RUSTUP_TOOLCHAIN
echo "##vso[task.setvariable variable=PATH;]$PATH:$HOME/.cargo/bin"
displayName: Install rust
# Windows.
- ${{ if eq(parameters.name, 'Windows') }}:
- script: |
curl -sSf -o rustup-init.exe https://win.rustup.rs
rustup-init.exe -y --default-toolchain %RUSTUP_TOOLCHAIN%
set PATH=%PATH%;%USERPROFILE%\.cargo\bin
echo "##vso[task.setvariable variable=PATH;]%PATH%;%USERPROFILE%\.cargo\bin"
displayName: Install rust (windows)
# All platforms.
- script: |
rustc -Vv
cargo -V
displayName: Query rust and cargo versions
- script: cargo build
displayName: Build
- script: |
cargo test --all --verbose
cargo test --release --all --verbose
displayName: Test
# Linux and macOS w/nightly toolchain.
# Ideally we'd only run the script for the nightly toolchain, but I can't
# figure out how to determine that within the Azure Pipelines conditional.
- ${{ if ne(parameters.name, 'Windows') }}:
- script: |
export RUST_BACKTRACE=1
if [ "$RUSTUP_TOOLCHAIN" = "nightly" ]
then cargo bench --all --verbose;
fi
displayName: Bench
# Windows w/nightly toolchain.
# Ideally we'd only run the script for the nightly toolchain, but I can't
# figure out how to determine that within the Azure Pipelines conditional.
- ${{ if eq(parameters.name, 'Windows') }}:
- script: |
SET RUST_BACKTRACE=1
if "%RUSTUP_TOOLCHAIN%" == "nightly" (
cargo bench --all --verbose
)
displayName: Bench
24 changes: 12 additions & 12 deletions azure-pipelines.yml
@@ -1,15 +1,15 @@
jobs:
- template: azure-pipelines-template.yml
parameters:
name: macOS
vmImage: macOS-10.13
- template: azure-pipelines-template.yml
parameters:
name: macOS
vmImage: macOS-10.13

- template: azure-pipelines-template.yml
parameters:
name: Linux
vmImage: ubuntu-16.04
- template: azure-pipelines-template.yml
parameters:
name: Linux
vmImage: ubuntu-16.04

- template: azure-pipelines-template.yml
parameters:
name: Windows
vmImage: vs2017-win2016
- template: azure-pipelines-template.yml
parameters:
name: Windows
vmImage: vs2017-win2016
13 changes: 8 additions & 5 deletions lmdb-sys/Cargo.toml
Expand Up @@ -2,8 +2,8 @@

name = "lmdb-rkv-sys"
# NB: When modifying, also modify html_root_url in lib.rs
version = "0.8.6"
authors = ["Dan Burkert <dan@danburkert.com>"]
version = "0.9.0"
authors = ["Dan Burkert <dan@danburkert.com>", "Victor Porof <vporof@mozilla.com>"]
license = "Apache-2.0"

description = "Rust bindings for liblmdb."
Expand All @@ -13,14 +13,17 @@ documentation = "https://docs.rs/lmdb-rkv-sys"
keywords = ["LMDB", "database", "storage-engine", "bindings", "library"]
categories = ["database", "external-ffi-bindings"]

# NB: When generating bindings, change to "bindgen.rs" or use something
# like `cargo-script` instead.
build = "build.rs"

[dependencies]
libc = "0.2"
libc = "0.2.62"

[build-dependencies]
pkg-config = "0.3.2"
cc = "1"
pkg-config = "0.3.15"
cc = "1.0.41"
bindgen = "0.51.0"

[features]
default = []
Expand Down
68 changes: 68 additions & 0 deletions lmdb-sys/bindgen.rs
@@ -0,0 +1,68 @@
extern crate bindgen;

use bindgen::callbacks::IntKind;
use bindgen::callbacks::ParseCallbacks;
use std::env;
use std::path::PathBuf;

#[derive(Debug)]
struct Callbacks;

impl ParseCallbacks for Callbacks {
fn int_macro(&self, name: &str, _value: i64) -> Option<IntKind> {
match name {
"MDB_SUCCESS"
| "MDB_KEYEXIST"
| "MDB_NOTFOUND"
| "MDB_PAGE_NOTFOUND"
| "MDB_CORRUPTED"
| "MDB_PANIC"
| "MDB_VERSION_MISMATCH"
| "MDB_INVALID"
| "MDB_MAP_FULL"
| "MDB_DBS_FULL"
| "MDB_READERS_FULL"
| "MDB_TLS_FULL"
| "MDB_TXN_FULL"
| "MDB_CURSOR_FULL"
| "MDB_PAGE_FULL"
| "MDB_MAP_RESIZED"
| "MDB_INCOMPATIBLE"
| "MDB_BAD_RSLOT"
| "MDB_BAD_TXN"
| "MDB_BAD_VALSIZE"
| "MDB_BAD_DBI"
| "MDB_LAST_ERRCODE" => Some(IntKind::Int),
_ => Some(IntKind::UInt),
}
}
}

fn main() {
let mut lmdb = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap());
lmdb.push("lmdb");
lmdb.push("libraries");
lmdb.push("liblmdb");

let mut out_path = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap());
out_path.push("src");

let bindings = bindgen::Builder::default()
.header(lmdb.join("lmdb.h").to_string_lossy())
.whitelist_var("^(MDB|mdb)_.*")
.whitelist_type("^(MDB|mdb)_.*")
.whitelist_function("^(MDB|mdb)_.*")
.ctypes_prefix("::libc")
.blacklist_item("mode_t")
.blacklist_item("^__.*")
.parse_callbacks(Box::new(Callbacks {}))
.layout_tests(false)
.prepend_enum_name(false)
.rustfmt_bindings(true)
.generate()
.expect("Unable to generate bindings");

bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
15 changes: 7 additions & 8 deletions lmdb-sys/build.rs
@@ -1,5 +1,5 @@
extern crate pkg_config;
extern crate cc;
extern crate pkg_config;

use std::env;
use std::path::PathBuf;
Expand Down Expand Up @@ -33,18 +33,17 @@ const MDB_IDL_LOGN: u8 = 15;
const MDB_IDL_LOGN: u8 = 16;

fn main() {
let mut lmdb: PathBuf = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap());
let mut lmdb = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap());
lmdb.push("lmdb");
lmdb.push("libraries");
lmdb.push("liblmdb");

if !pkg_config::find_library("liblmdb").is_ok() {
cc::Build::new()
.define("MDB_IDL_LOGN", Some(MDB_IDL_LOGN.to_string().as_str()))
.file(lmdb.join("mdb.c"))
.file(lmdb.join("midl.c"))
// https://github.com/LMDB/lmdb/blob/LMDB_0.9.21/libraries/liblmdb/Makefile#L25
.opt_level(2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

.compile("liblmdb.a")
.define("MDB_IDL_LOGN", Some(MDB_IDL_LOGN.to_string().as_str()))
.file(lmdb.join("mdb.c"))
.file(lmdb.join("midl.c"))
.flag_if_supported("-Wno-unused-parameter")
.compile("liblmdb.a")
}
}