foundationdb icon indicating copy to clipboard operation
foundationdb copied to clipboard

Rust cxx

Open sears opened this issue 2 years ago • 31 comments

This adds cmake support for Rust <-> C++ interoperability via the CXX crate. Sample usage:

# ~/build_output/bin/fdbserver -r unittests -f /flow/rust
...
Testing /flow/rust/hello_world
FDB git SHA: 24677fb7de19cef7a55221524466019d777c4100
Foo: 42;
...

In this test, C++ invokes Rust, which invokes a C++ function to get the git sha. Rust then prints a few things to stdout and returns.

Code-Reviewer Section

The general guidelines can be found here.

Please check each of the following things and check all boxes before accepting a PR.

  • [ ] The PR has a description, explaining both the problem and the solution.
  • [ ] The description mentions which forms of testing were done and the testing seems reasonable.
  • [ ] Every function/class/actor that was touched is reasonably well documented.

For Release-Branches

If this PR is made against a release-branch, please also check the following:

  • [ ] This change/bugfix is a cherry-pick from the next younger branch (younger release-branch or main if this is the youngest branch)
  • [ ] There is a good reason why this PR needs to go into a release branch and this reason is documented (either in the description above or in a linked GitHub issue)

sears avatar Jul 20 '22 17:07 sears

Result of foundationdb-pr on Linux CentOS 7

  • Commit ID: 5ba28986db7330b64e1127653430b2ba286ba44f
  • Duration 0:05:54
  • Result: :x: FAILED
  • Error: Error while executing command: ninja -v -C build_output -j ${NPROC} all packages strip_targets. Reason: exit status 1
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 20 '22 18:07 foundationdb-ci

Result of foundationdb-pr-cluster-tests on Linux CentOS 7

  • Commit ID: 5ba28986db7330b64e1127653430b2ba286ba44f
  • Duration 0:05:55
  • Result: :x: FAILED
  • Error: Error while executing command: ninja -v -C build_output -j ${NPROC} all packages strip_targets. Reason: exit status 1
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 20 '22 18:07 foundationdb-ci

Result of foundationdb-pr-cluster-tests on Linux CentOS 7

  • Commit ID: d6e680952b7aef9fa39158e4292a282dcbca21ad
  • Duration 0:05:18
  • Result: :x: FAILED
  • Error: Error while executing command: ninja -v -C build_output -j ${NPROC} all packages strip_targets. Reason: exit status 1
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 20 '22 18:07 foundationdb-ci

Doxense CI Report for Windows 10

  • Commit ID: d6e680952b7aef9fa39158e4292a282dcbca21ad
  • Result: :x: FAILED
  • Build Logs (available for 30 days)

fdb-windows-ci avatar Jul 20 '22 18:07 fdb-windows-ci

Result of foundationdb-pr on Linux CentOS 7

  • Commit ID: d6e680952b7aef9fa39158e4292a282dcbca21ad
  • Duration 0:06:35
  • Result: :x: FAILED
  • Error: Error while executing command: ninja -v -C build_output -j ${NPROC} all packages strip_targets. Reason: exit status 1
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 20 '22 18:07 foundationdb-ci

Result of foundationdb-pr-cluster-tests on Linux CentOS 7

  • Commit ID: a3b03047cc08031b2efc38610e4afc5634411fdc
  • Duration 0:04:28
  • Result: :x: FAILED
  • Error: Error while executing command: ninja -v -C build_output -j ${NPROC} all packages strip_targets. Reason: exit status 1
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 20 '22 18:07 foundationdb-ci

Result of foundationdb-pr on Linux CentOS 7

  • Commit ID: a3b03047cc08031b2efc38610e4afc5634411fdc
  • Duration 0:04:43
  • Result: :x: FAILED
  • Error: Error while executing command: ninja -v -C build_output -j ${NPROC} all packages strip_targets. Reason: exit status 1
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 20 '22 18:07 foundationdb-ci

Doxense CI Report for Windows 10

  • Commit ID: a3b03047cc08031b2efc38610e4afc5634411fdc
  • Result: :x: FAILED
  • Build Logs (available for 30 days)

fdb-windows-ci avatar Jul 20 '22 18:07 fdb-windows-ci

Result of foundationdb-pr-macos on macOS BigSur 11.5.2

  • Commit ID: 1a2d4f8244371daf9719786e0927fce5873533cc
  • Duration 0:07:00
  • Result: :x: FAILED
  • Error: Error while executing command: ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${HOME}/.ssh_key ec2-user@${MAC_EC2_HOST} /usr/local/bin/bash --login -c ./build_pr_macos.sh. Reason: exit status 1
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 20 '22 18:07 foundationdb-ci

Doxense CI Report for Windows 10

  • Commit ID: 1a2d4f8244371daf9719786e0927fce5873533cc
  • Result: :x: FAILED
  • Build Logs (available for 30 days)

fdb-windows-ci avatar Jul 20 '22 19:07 fdb-windows-ci

Result of foundationdb-pr on Linux CentOS 7

  • Commit ID: a3b03047cc08031b2efc38610e4afc5634411fdc
  • Duration 1:10:45
  • Result: :white_check_mark: SUCCEEDED
  • Error: N/A
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 20 '22 19:07 foundationdb-ci

Result of foundationdb-pr on Linux CentOS 7

  • Commit ID: 1a2d4f8244371daf9719786e0927fce5873533cc
  • Duration 1:07:22
  • Result: :white_check_mark: SUCCEEDED
  • Error: N/A
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 20 '22 19:07 foundationdb-ci

Result of foundationdb-pr-cluster-tests on Linux CentOS 7

  • Commit ID: 1a2d4f8244371daf9719786e0927fce5873533cc
  • Duration 2:09:15
  • Result: :x: FAILED
  • Error: Error while executing command: make -C tests -kj run. Reason: exit status 2
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 20 '22 20:07 foundationdb-ci

Doxense CI Report for Windows 10

  • Commit ID: c393b056a572e475401118607b137d7ac5c7d0e6
  • Result: :x: FAILED
  • Build Logs (available for 30 days)

fdb-windows-ci avatar Jul 20 '22 23:07 fdb-windows-ci

Result of foundationdb-pr on Linux CentOS 7

  • Commit ID: c393b056a572e475401118607b137d7ac5c7d0e6
  • Duration 1:00:48
  • Result: :white_check_mark: SUCCEEDED
  • Error: N/A
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 20 '22 23:07 foundationdb-ci

Result of foundationdb-pr-cluster-tests on Linux CentOS 7

  • Commit ID: c393b056a572e475401118607b137d7ac5c7d0e6
  • Duration 4:17:55
  • Result: :x: FAILED
  • Error: Build has timed out.
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 21 '22 03:07 foundationdb-ci

It is really awesome to see this PR! :-) I was wondering if you might be able to share your vision/roadmap around native Rust/CXX/Flow integration?

Something that we are missing as layer developers is the ability to do simulation testing. If there is someway we can combine the ability to write our application code in Rust, and at the same time gain all the benefits of flow, that would something I would really like to explore.

I maintain the Tokio/Rust bindings and @PierreZ maintains the non-Tokio Rust bindings. We have had some discussions around this in the past.

rajivr avatar Jul 21 '22 03:07 rajivr

It is really awesome to see this PR! :-) I was wondering if you might be able to share your vision/roadmap around native Rust/CXX/Flow integration?

:+1: :tada: :rocket:

Something that we are missing as layer developers is the ability to do simulation testing. If there is someway we can combine the ability to write our application code in Rust, and at the same time gain all the benefits of flow, that would something I would really like to explore.

On our side, @wonshtrum managed to create a Trait that looks like the Java Workload interface. It is a proof of concept for now, but we are capable of running some tests like:

impl RustWorkload for MyWorkload {
// ...
    fn setup(&'static mut self, db: SimDatabase, done: Promise) {
        println!("rust_setup({})", self.uuid);
        fdb_rt(async move {
            let trx = db.create_trx().expect("trx");
            trx.set_read_version(42);
            let version = trx.get_read_version().await.expect("read_version");
            println!("Version: {}", version);

            let trx = db.create_trx().expect("trx2");
            let version = trx.get_read_version().await.expect("read_version2");
            println!("Version2: {}", version);

            trx.set(b"hello", b"world");
            trx.commit().await.expect("commit1");
            let trx = db.create_trx().expect("trx2");
            let maybe_value = trx.get(b"hello", false).await.expect("get");
            let value = maybe_value.expect("value");
            let value = from_utf8(value.deref()).expect("utf8");
            println!("Value: {:?}", value);

            self.context.trace(
                FDBSeverity::WarnAlways,
                "RustWorkloadSetup".to_string(),
                vec![("Hello".to_string(), value.to_string())],
            );
            done.send(true);
        })
    }

Because of how workloads are behaving, we wrote a tiny async runtime that is using the simulation framework as the reactor. It is highly experimental for now, but the crate will be open-sourced.

We are using the External Workload for now, but maybe we could leverage Rust cxx to simplify that part.

PierreZ avatar Jul 21 '22 06:07 PierreZ

Result of foundationdb-pr-macos on macOS BigSur 11.5.2

  • Commit ID: a043715ba371b7bb9870c40118123a2a1c2ce661
  • Duration 0:07:05
  • Result: :x: FAILED
  • Error: Error while executing command: ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ${HOME}/.ssh_key ec2-user@${MAC_EC2_HOST} /usr/local/bin/bash --login -c ./build_pr_macos.sh. Reason: exit status 1
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 21 '22 22:07 foundationdb-ci

Doxense CI Report for Windows 10

  • Commit ID: a043715ba371b7bb9870c40118123a2a1c2ce661
  • Result: :x: FAILED
  • Build Logs (available for 30 days)

fdb-windows-ci avatar Jul 21 '22 22:07 fdb-windows-ci

Result of foundationdb-pr on Linux CentOS 7

  • Commit ID: a043715ba371b7bb9870c40118123a2a1c2ce661
  • Duration 1:16:09
  • Result: :white_check_mark: SUCCEEDED
  • Error: N/A
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 21 '22 23:07 foundationdb-ci

Result of foundationdb-pr-cluster-tests on Linux CentOS 7

  • Commit ID: a043715ba371b7bb9870c40118123a2a1c2ce661
  • Duration 4:16:03
  • Result: :x: FAILED
  • Error: Build has timed out.
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 22 '22 02:07 foundationdb-ci

Result of foundationdb-pr-cluster-tests on Linux CentOS 7

  • Commit ID: eb919161df208c86a97e1d80e29f27f75eb6160d
  • Duration 0:05:20
  • Result: :x: FAILED
  • Error: Error while executing command: cmake -S . -B build_output -D USE_CCACHE=ON -D USE_WERROR=ON -D RocksDB_ROOT=/opt/rocksdb-6.27.3 -D RUN_JUNIT_TESTS=OFF -D RUN_JAVA_INTEGRATION_TESTS=OFF -D BUILD_DOCUMENTATION=OFF -G Ninja. Reason: exit status 1
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 26 '22 22:07 foundationdb-ci

Result of foundationdb-pr on Linux CentOS 7

  • Commit ID: eb919161df208c86a97e1d80e29f27f75eb6160d
  • Duration 0:05:25
  • Result: :x: FAILED
  • Error: Error while executing command: cmake -S . -B build_output -D USE_CCACHE=ON -D USE_WERROR=ON -D RocksDB_ROOT=/opt/rocksdb-6.27.3 -D RUN_JUNIT_TESTS=ON -D RUN_JAVA_INTEGRATION_TESTS=ON -D BUILD_DOCUMENTATION=ON -G Ninja. Reason: exit status 1
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 26 '22 22:07 foundationdb-ci

Doxense CI Report for Windows 10

  • Commit ID: eb919161df208c86a97e1d80e29f27f75eb6160d
  • Result: :x: FAILED
  • Build Logs (available for 30 days)

fdb-windows-ci avatar Jul 26 '22 23:07 fdb-windows-ci

Result of foundationdb-pr on Linux CentOS 7

  • Commit ID: 936b9a3b3dd31d19b73ad6aa0597448bd5de5955
  • Duration 0:07:55
  • Result: :x: FAILED
  • Error: Error while executing command: ninja -v -C build_output -j ${NPROC} all packages strip_targets. Reason: exit status 1
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 27 '22 17:07 foundationdb-ci

Result of foundationdb-pr-cluster-tests on Linux CentOS 7

  • Commit ID: 936b9a3b3dd31d19b73ad6aa0597448bd5de5955
  • Duration 0:08:41
  • Result: :x: FAILED
  • Error: Error while executing command: ninja -v -C build_output -j ${NPROC} all packages strip_targets. Reason: exit status 1
  • Build Logs (available for 30 days)

foundationdb-ci avatar Jul 27 '22 17:07 foundationdb-ci

Doxense CI Report for Windows 10

  • Commit ID: 936b9a3b3dd31d19b73ad6aa0597448bd5de5955
  • Result: :x: FAILED
  • Build Logs (available for 30 days)

fdb-windows-ci avatar Jul 27 '22 17:07 fdb-windows-ci

@rajivr @PierreZ

Sorry for the slow response. I almost missed your comments, since they're sandwiched between test results.

We don't have a roadmap yet. We're exploring a few options to figure out what's possible, and how hard different approaches are. You might also be interested in this PR, where I attempted to implement an FDB role from-scratch in Rust:

https://github.com/apple/foundationdb/pull/7728

The Rust process comes up, and manages to bootstrap its way into the master role. The master role tries to hand out some read versions. At that point, the commit path hangs due to missing functionality in the master. I'm in the process of merging the updated flow transport documentation from that PR, but the rest is moth-balled.

The main things we learned from that are:

  • it's really hard to get .fbs files that match the FDB flatbuffers, since flatc's rust backend is missing some union {} features that FDB relies on.
  • there are a lot of custom data structures that we'll need to port to rust in order to get basic things done.

This CXX binding PR is the follow up to that work. It bypasses the first issue. Our hope is that it will let us make progress on the second issue by porting pieces of a role to Rust a time.

sears avatar Jul 28 '22 15:07 sears

@rajivr @PierreZ

Sorry for the slow response. I almost missed your comments, since they're sandwiched between test results.

We don't have a roadmap yet. We're exploring a few options to figure out what's possible, and how hard different approaches are. You might also be interested in this PR, where I attempted to implement an FDB role from-scratch in Rust:

https://github.com/apple/foundationdb/pull/7728

The Rust process comes up, and manages to bootstrap its way into the master role. The master role tries to hand out some read versions. At that point, the commit path hangs due to missing functionality in the master. I'm in the process of merging the updated flow transport documentation from that PR, but the rest is moth-balled.

The main things we learned from that are:

  • it's really hard to get .fbs files that match the FDB flatbuffers, since flatc's rust backend is missing some union {} features that FDB relies on.

  • there are a lot of custom data structures that we'll need to port to rust in order to get basic things done.

This CXX binding PR is the follow up to that work. It bypasses the first issue. Our hope is that it will let us make progress on the second issue by porting pieces of a role to Rust a time.

Thanks for the detailed answer. Looking forward to see how things are evolving 🦀

PierreZ avatar Jul 28 '22 15:07 PierreZ