Skip to content

*: add tirocks-sys and xtask #1

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

Merged
merged 14 commits into from
Jan 29, 2022
Merged

*: add tirocks-sys and xtask #1

merged 14 commits into from
Jan 29, 2022

Conversation

BusyJay
Copy link
Owner

@BusyJay BusyJay commented Jan 22, 2022

The version of titan and rocksdb submodules are the same as master branch of rust-rocksdb. xtask crate are copied from grpc-rs. Build script are refactored.

Compared to rust-rocksdb, the main differences are:

  1. Use cargo command and bindgen to maintain bindings just like grpc-rs:
    cargo xtask bindgen
    
  2. Titan and rocksdb are maintained in one crate instead of two. Because compiling titan requires rocksdb, so it's impossible to publish a crate that only includes the source of titan. And compiling crocksdb also requires the source of titan. So it's easier to maintain to just put rocksdb and titan into one crate.
  3. bindgen is completely removed from dependency tree unless we want to regenerate bindings. So compiling tirocks doesn't requires clang and llvm. It's safe for every platform to share the same bindings as all structs are opaque types and libc is used to cover the platform differences.
  4. Released version of snappy-sys is used by default so we can publish tirocks in the future.

Signed-off-by: Jay Lee <[email protected]>
Signed-off-by: Jay Lee <[email protected]>
Signed-off-by: Jay Lee <[email protected]>
Signed-off-by: Jay Lee <[email protected]>
@BusyJay BusyJay requested review from Connor1996 and tabokie January 22, 2022 13:31
links = "tirocks"

[dependencies]
# native library >=1.0.8
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this mean?

Copy link
Owner Author

Choose a reason for hiding this comment

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

It means the version of bzip2 package >= 1.0.8.

Cargo.toml Outdated

[patch.crates-io]
# Use cmake to build the binary, so it can be compiled on all supported platform.
snappy-sys = { git = "https://github.com/busyjay/rust-snappy.git", branch = "static-link" }
Copy link
Collaborator

Choose a reason for hiding this comment

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

newline

Signed-off-by: Jay Lee <[email protected]>
Signed-off-by: Jay Lee <[email protected]>
Copy link
Collaborator

@Connor1996 Connor1996 left a comment

Choose a reason for hiding this comment

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

In rust-rocksdb, DBStatisticsTickerType is generated by librocksdb_sys/src/generated.rs. We did some changes in it. It can't simply follow the original c.h.

#[cfg(feature = "update-bindings")]
fn bindgen_rocksdb(file_path: &Path) {
println!("cargo:rerun-if-env-changed=TEST_BIND");
let gen_tests = env::var("TEST_BIND").map_or(false, |s| s == "1");
Copy link
Collaborator

Choose a reason for hiding this comment

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

should it be removed?

Copy link
Owner Author

Choose a reason for hiding this comment

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

No, it will be used in tests.

@BusyJay
Copy link
Owner Author

BusyJay commented Jan 26, 2022

@tabokie @Connor1996

I add the missing ticker and histogram types by including them into whitelist. So they are generated by bindgen automatically instead of custom scripts.

I also define all the properties names in c.h, so they can also be maintained by bindgen.

@@ -0,0 +1,2718 @@
/* Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wish we can use C API defined in rocksdb and Titan instead of maintaining it here.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Agree. Maybe we need to have rocksdb headers, titan headers and custom headers maintained by ourselves. This can be done later.

}

fn clang_format() {
exec(cmd("clang-format").args(&[
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about calling it in make format

Copy link
Owner Author

Choose a reason for hiding this comment

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

There is no Makefile. The point of using xtask is to use cargo flow completely.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If I have some changes, then I need to call cargo fmt and cargo xtask clang-format separately. I don't think it's friendly.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Added a new command cargo xtask format.

## Build

```
$ cargo xtask submodule # if you just cloned the repository
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest provide a make build

Copy link
Owner Author

@BusyJay BusyJay Jan 28, 2022

Choose a reason for hiding this comment

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

It's a one time task. And update submodule every time may not be a good idea if I want to checkout submodule to a different version.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So we need to provide a Makfile. update_rocksdb and update_titan are needed by the auto-update bot.

Copy link
Owner Author

Choose a reason for hiding this comment

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

What is auto-update bot? All functionality can be implemented as a new command of xtask.

Copy link
Collaborator

Choose a reason for hiding this comment

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

update the rocksdb/titan submodule when any rocksdb/titan's PRs get merged, and then file a PR to update rust-rocksdb dependency in tikv repo

figure_link_lib(&dst, "rocksdb");

if cfg!(target_os = "windows") {
build.define("OS_WIN", None);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have a question: as the rocksdb has already been built above, do these defines make any sense?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yes, it will be used in the headers included in c.h.

let mut builder = bindgen::Builder::default();

if env::var("CARGO_CFG_TARGET_OS").map_or(false, |s| s == "windows") {
builder = builder.clang_arg("-D _WIN32_WINNT=0x600");
Copy link
Collaborator

Choose a reason for hiding this comment

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

what's it for. Please add a comment.

Copy link
Owner Author

Choose a reason for hiding this comment

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

It's copied from grpc-rs. Some file may require to define minimal supported windows version at compile time.

.whitelist_type(r"\brocksdb::Histograms")
.whitelist_type(r"\brocksdb::titandb::TickerType")
.whitelist_type(r"\brocksdb::titandb::HistogramType")
.blacklist_type(r"\b__.*")
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is it for

Copy link
Owner Author

Choose a reason for hiding this comment

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

To filter symbols like __uint32.

.whitelist_type(r"\brocksdb::titandb::HistogramType")
.blacklist_type(r"\b__.*")
.derive_copy(false)
.opaque_type(r"\bctitandb_.*")
Copy link
Collaborator

Choose a reason for hiding this comment

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

why titan's type are opaque type

Copy link
Owner Author

Choose a reason for hiding this comment

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

Actually all structs are opaque types as the current way they are defined. But this is a stale change, I will remove it.

#[doc = " 4. Add the enum conversions from Java and C++ to portal.h's toJavaTickerType"]
#[doc = " and toCppTickers"]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub enum rocksdb_Tickers {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we have a way to add a prefix c for these enums to make them consistent with other types

Copy link
Collaborator

Choose a reason for hiding this comment

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

or cancel the prefix c in the crocksdb.h

Copy link
Owner Author

Choose a reason for hiding this comment

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

No, we can't. rust-lang/rust-bindgen#1098. I think the c prefix is fine as it can tell what types are defined by ourselves and what types are defined by rocksdb itself.

@@ -0,0 +1,32 @@
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
Copy link
Collaborator

@Connor1996 Connor1996 Jan 28, 2022

Choose a reason for hiding this comment

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

Suggested change
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
// Copyright 2022 TiKV Project Authors. Licensed under Apache-2.0.

Copy link
Collaborator

@Connor1996 Connor1996 left a comment

Choose a reason for hiding this comment

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

rest LGTM

Copy link
Collaborator

@Connor1996 Connor1996 left a comment

Choose a reason for hiding this comment

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

LGTM

@BusyJay BusyJay merged commit a15458c into main Jan 29, 2022
@BusyJay BusyJay deleted the add-native-lib branch January 29, 2022 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants