From 78019d2ea464921b94cd342a4b41e32fb7a96ada Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Sat, 20 Jul 2024 10:15:56 +0200 Subject: [PATCH 1/7] Build outside of source dir (using cmake crate) --- Cargo.lock | 18 +++++++++++++++++- ibverbs-sys/Cargo.toml | 3 ++- ibverbs-sys/build.rs | 23 +++++++++++++++-------- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bcbe9e0..e0fee8b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -49,6 +49,12 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" +[[package]] +name = "cc" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aba8f4e9906c7ce3c73463f62a7f0c65183ada1a2d47e397cc8810827f9694f" + [[package]] name = "cexpr" version = "0.6.0" @@ -75,6 +81,15 @@ dependencies = [ "libloading", ] +[[package]] +name = "cmake" +version = "0.1.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" +dependencies = [ + "cc", +] + [[package]] name = "either" version = "1.13.0" @@ -117,9 +132,10 @@ dependencies = [ [[package]] name = "ibverbs-sys" -version = "0.2.0+52.0" +version = "0.2.1+52.0" dependencies = [ "bindgen", + "cmake", "regex", ] diff --git a/ibverbs-sys/Cargo.toml b/ibverbs-sys/Cargo.toml index 1ce4463..45dd00d 100644 --- a/ibverbs-sys/Cargo.toml +++ b/ibverbs-sys/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ibverbs-sys" -version = "0.2.0+52.0" +version = "0.2.1+52.0" edition = "2021" description = "Raw, FFI bindings for RDMA ibverbs through rdma-core" @@ -24,6 +24,7 @@ exclude = ["vendor/rdma-core/build/"] [build-dependencies] bindgen = "0.69.2" +cmake = "0.1.50" # to make -Zminimal-versions work [target.'cfg(any())'.dependencies] diff --git a/ibverbs-sys/build.rs b/ibverbs-sys/build.rs index 9eed2ff..cfd50f5 100644 --- a/ibverbs-sys/build.rs +++ b/ibverbs-sys/build.rs @@ -8,8 +8,10 @@ fn main() { println!("cargo:rustc-link-search=native={manifest_dir}/vendor/rdma-core/build/lib"); println!("cargo:rustc-link-lib=ibverbs"); - // initialize and update submodules - if Path::new(".git").is_dir() { + if Path::new("vendor/rdma-core/CMakeLists.txt").exists() { + // don't touch source dir if not necessary + } else if Path::new(".git").is_dir() { + // initialize and update submodules Command::new("git") .args(["submodule", "update", "--init"]) .status() @@ -22,16 +24,21 @@ fn main() { } // build vendor/rdma-core - Command::new("bash") - .current_dir("vendor/rdma-core/") - .args(["build.sh"]) - .status() - .expect("Failed to build vendor/rdma-core using build.sh"); + eprintln!("run cmake"); + let built_in = cmake::Config::new("vendor/rdma-core") + .define("IN_PLACE", "1") + .define("NO_MAN_PAGES", "1") + .no_build_target(true) + .build(); + let built_in = built_in + .to_str() + .expect("build directory path is not valid UTF-8"); // generate the bindings + eprintln!("run bindgen"); let bindings = bindgen::Builder::default() .header("vendor/rdma-core/libibverbs/verbs.h") - .clang_arg("-Ivendor/rdma-core/build/include/") + .clang_arg(format!("-I{built_in}/include/")) .allowlist_function("ibv_.*") .allowlist_type("ibv_.*") .bitfield_enum("ibv_access_flags") From b7474076a01c1531fda131dfba7fcc56324c3edb Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Sat, 20 Jul 2024 11:28:34 +0200 Subject: [PATCH 2/7] Also install clang for rdma-core to build --- .github/workflows/check.yml | 12 ++++++++++++ .github/workflows/test.yml | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a568066..7c92722 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -53,6 +53,9 @@ jobs: run: | sudo apt-get update sudo apt-get install libibverbs1 libibverbs-dev + - name: Install clang for rdma-core to be happy + run: | + sudo apt-get install clang - name: Install ${{ matrix.toolchain }} uses: dtolnay/rust-toolchain@master with: @@ -77,6 +80,9 @@ jobs: run: | sudo apt-get update sudo apt-get install libibverbs1 libibverbs-dev + - name: Install clang for rdma-core to be happy + run: | + sudo apt-get install clang - name: Install nightly uses: dtolnay/rust-toolchain@nightly - name: cargo doc @@ -96,6 +102,9 @@ jobs: run: | sudo apt-get update sudo apt-get install libibverbs1 libibverbs-dev + - name: Install clang for rdma-core to be happy + run: | + sudo apt-get install clang - name: Install stable uses: dtolnay/rust-toolchain@stable - name: cargo install cargo-hack @@ -121,6 +130,9 @@ jobs: run: | sudo apt-get update sudo apt-get install libibverbs1 libibverbs-dev + - name: Install clang for rdma-core to be happy + run: | + sudo apt-get install clang - name: Install ${{ matrix.msrv }} uses: dtolnay/rust-toolchain@master with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 82db700..77cc920 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,6 +33,9 @@ jobs: run: | sudo apt-get update sudo apt-get install libibverbs1 libibverbs-dev + - name: Install clang for rdma-core to be happy + run: | + sudo apt-get install clang - name: Install ${{ matrix.toolchain }} uses: dtolnay/rust-toolchain@master with: @@ -80,6 +83,9 @@ jobs: run: | sudo apt-get update sudo apt-get install libibverbs1 libibverbs-dev + - name: Install clang for rdma-core to be happy + run: | + sudo apt-get install clang - name: Install stable uses: dtolnay/rust-toolchain@stable - name: Install nightly for -Zminimal-versions @@ -122,6 +128,9 @@ jobs: run: | sudo apt-get update sudo apt-get install libibverbs1 libibverbs-dev + - name: Install clang for rdma-core to be happy + run: | + sudo apt-get install clang - name: Install stable uses: dtolnay/rust-toolchain@stable with: From 3997ddb50a843bab0c66fb8c5703bb71a2500cca Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Sat, 20 Jul 2024 11:37:50 +0200 Subject: [PATCH 3/7] Also choose clang --- .github/workflows/check.yml | 11 +++++++++++ .github/workflows/test.yml | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 7c92722..455c1d4 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -66,6 +66,9 @@ jobs: with: reporter: 'github-pr-check' github_token: ${{ secrets.GITHUB_TOKEN }} + env: + CC: clang + CXX: clang doc: # run docs generation on nightly rather than stable. This enables features like # https://doc.rust-lang.org/beta/unstable-book/language-features/doc-cfg.html which allows an @@ -89,6 +92,8 @@ jobs: run: cargo doc --no-deps --all-features env: RUSTDOCFLAGS: --cfg docsrs + CC: clang + CXX: clang hack: # cargo-hack checks combinations of feature flags to ensure that features are all additive # which is required for feature unification @@ -113,6 +118,9 @@ jobs: # --feature-powerset runs for every combination of features - name: cargo hack run: cargo hack --feature-powerset check + env: + CC: clang + CXX: clang msrv: # check that we can build using the minimal rust version that is specified by this crate runs-on: ubuntu-latest @@ -139,3 +147,6 @@ jobs: toolchain: ${{ matrix.msrv }} - name: cargo +${{ matrix.msrv }} check run: cargo check + env: + CC: clang + CXX: clang diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 77cc920..9cb8c28 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -47,9 +47,15 @@ jobs: # https://twitter.com/jonhoo/status/1571290371124260865 - name: cargo test --locked run: cargo test --locked --all-features --all-targets + env: + CC: clang + CXX: clang # https://github.com/rust-lang/cargo/issues/6669 - name: cargo test --doc run: cargo test --locked --all-features --doc + env: + CC: clang + CXX: clang minimal: # This action chooses the oldest version of the dependencies permitted by Cargo.toml to ensure # that this crate is compatible with the minimal version that this crate and its dependencies @@ -96,6 +102,9 @@ jobs: run: cargo +nightly update -Zminimal-versions - name: cargo test run: cargo test --locked --all-features --all-targets + env: + CC: clang + CXX: clang coverage: # use llvm-cov to build and collect coverage and outputs in a format that # is compatible with codecov.io @@ -142,6 +151,9 @@ jobs: run: cargo generate-lockfile - name: cargo llvm-cov run: cargo llvm-cov --locked --all-features --lcov --output-path lcov.info + env: + CC: clang + CXX: clang - name: Record Rust version run: echo "RUST=$(rustc --version)" >> "$GITHUB_ENV" - name: Upload to codecov.io From d5665950f3e9a59dce00d602da4d8637077a1ec7 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Sat, 20 Jul 2024 11:52:21 +0200 Subject: [PATCH 4/7] Also configure target directory --- .github/workflows/check.yml | 47 +++++++------------------------------ .github/workflows/test.yml | 39 +++++------------------------- configure-ci.sh | 24 +++++++++++++++++++ 3 files changed, 38 insertions(+), 72 deletions(-) create mode 100755 configure-ci.sh diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 455c1d4..3d810e0 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -49,13 +49,8 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - name: Install libibverbs dependencies - run: | - sudo apt-get update - sudo apt-get install libibverbs1 libibverbs-dev - - name: Install clang for rdma-core to be happy - run: | - sudo apt-get install clang + - name: Configure CI host + run: configure-ci.sh - name: Install ${{ matrix.toolchain }} uses: dtolnay/rust-toolchain@master with: @@ -66,9 +61,6 @@ jobs: with: reporter: 'github-pr-check' github_token: ${{ secrets.GITHUB_TOKEN }} - env: - CC: clang - CXX: clang doc: # run docs generation on nightly rather than stable. This enables features like # https://doc.rust-lang.org/beta/unstable-book/language-features/doc-cfg.html which allows an @@ -79,21 +71,14 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - name: Install libibverbs dependencies - run: | - sudo apt-get update - sudo apt-get install libibverbs1 libibverbs-dev - - name: Install clang for rdma-core to be happy - run: | - sudo apt-get install clang + - name: Configure CI host + run: configure-ci.sh - name: Install nightly uses: dtolnay/rust-toolchain@nightly - name: cargo doc run: cargo doc --no-deps --all-features env: RUSTDOCFLAGS: --cfg docsrs - CC: clang - CXX: clang hack: # cargo-hack checks combinations of feature flags to ensure that features are all additive # which is required for feature unification @@ -103,13 +88,8 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - name: Install libibverbs dependencies - run: | - sudo apt-get update - sudo apt-get install libibverbs1 libibverbs-dev - - name: Install clang for rdma-core to be happy - run: | - sudo apt-get install clang + - name: Configure CI host + run: configure-ci.sh - name: Install stable uses: dtolnay/rust-toolchain@stable - name: cargo install cargo-hack @@ -118,9 +98,6 @@ jobs: # --feature-powerset runs for every combination of features - name: cargo hack run: cargo hack --feature-powerset check - env: - CC: clang - CXX: clang msrv: # check that we can build using the minimal rust version that is specified by this crate runs-on: ubuntu-latest @@ -134,19 +111,11 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - name: Install libibverbs dependencies - run: | - sudo apt-get update - sudo apt-get install libibverbs1 libibverbs-dev - - name: Install clang for rdma-core to be happy - run: | - sudo apt-get install clang + - name: Configure CI host + run: configure-ci.sh - name: Install ${{ matrix.msrv }} uses: dtolnay/rust-toolchain@master with: toolchain: ${{ matrix.msrv }} - name: cargo +${{ matrix.msrv }} check run: cargo check - env: - CC: clang - CXX: clang diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9cb8c28..46827e9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,13 +29,8 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - name: Install libibverbs dependencies - run: | - sudo apt-get update - sudo apt-get install libibverbs1 libibverbs-dev - - name: Install clang for rdma-core to be happy - run: | - sudo apt-get install clang + - name: Configure CI host + run: configure-ci.sh - name: Install ${{ matrix.toolchain }} uses: dtolnay/rust-toolchain@master with: @@ -47,15 +42,9 @@ jobs: # https://twitter.com/jonhoo/status/1571290371124260865 - name: cargo test --locked run: cargo test --locked --all-features --all-targets - env: - CC: clang - CXX: clang # https://github.com/rust-lang/cargo/issues/6669 - name: cargo test --doc run: cargo test --locked --all-features --doc - env: - CC: clang - CXX: clang minimal: # This action chooses the oldest version of the dependencies permitted by Cargo.toml to ensure # that this crate is compatible with the minimal version that this crate and its dependencies @@ -85,13 +74,8 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - name: Install libibverbs dependencies - run: | - sudo apt-get update - sudo apt-get install libibverbs1 libibverbs-dev - - name: Install clang for rdma-core to be happy - run: | - sudo apt-get install clang + - name: Configure CI host + run: configure-ci.sh - name: Install stable uses: dtolnay/rust-toolchain@stable - name: Install nightly for -Zminimal-versions @@ -102,9 +86,6 @@ jobs: run: cargo +nightly update -Zminimal-versions - name: cargo test run: cargo test --locked --all-features --all-targets - env: - CC: clang - CXX: clang coverage: # use llvm-cov to build and collect coverage and outputs in a format that # is compatible with codecov.io @@ -133,13 +114,8 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - name: Install libibverbs dependencies - run: | - sudo apt-get update - sudo apt-get install libibverbs1 libibverbs-dev - - name: Install clang for rdma-core to be happy - run: | - sudo apt-get install clang + - name: Configure CI host + run: configure-ci.sh - name: Install stable uses: dtolnay/rust-toolchain@stable with: @@ -151,9 +127,6 @@ jobs: run: cargo generate-lockfile - name: cargo llvm-cov run: cargo llvm-cov --locked --all-features --lcov --output-path lcov.info - env: - CC: clang - CXX: clang - name: Record Rust version run: echo "RUST=$(rustc --version)" >> "$GITHUB_ENV" - name: Upload to codecov.io diff --git a/configure-ci.sh b/configure-ci.sh new file mode 100755 index 0000000..d952b63 --- /dev/null +++ b/configure-ci.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +set -euo pipefail + +echo "Install libibverbs dependencies" +sudo apt-get update +sudo apt-get install libibverbs1 libibverbs-dev + +echo "Install clang for rdma-core to be happy" +sudo apt-get install clang + +echo "Move Cargo target dir to avoid super long paths" +mkdir /tmp/cargo + +echo "Tell Cargo to use clang and target dir" +cat >.cargo < Date: Sat, 20 Jul 2024 11:53:20 +0200 Subject: [PATCH 5/7] heavy sigh --- .github/workflows/check.yml | 8 ++++---- .github/workflows/test.yml | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 3d810e0..f824dfc 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -50,7 +50,7 @@ jobs: with: submodules: true - name: Configure CI host - run: configure-ci.sh + run: ./configure-ci.sh - name: Install ${{ matrix.toolchain }} uses: dtolnay/rust-toolchain@master with: @@ -72,7 +72,7 @@ jobs: with: submodules: true - name: Configure CI host - run: configure-ci.sh + run: ./configure-ci.sh - name: Install nightly uses: dtolnay/rust-toolchain@nightly - name: cargo doc @@ -89,7 +89,7 @@ jobs: with: submodules: true - name: Configure CI host - run: configure-ci.sh + run: ./configure-ci.sh - name: Install stable uses: dtolnay/rust-toolchain@stable - name: cargo install cargo-hack @@ -112,7 +112,7 @@ jobs: with: submodules: true - name: Configure CI host - run: configure-ci.sh + run: ./configure-ci.sh - name: Install ${{ matrix.msrv }} uses: dtolnay/rust-toolchain@master with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 46827e9..c9c127a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -30,7 +30,7 @@ jobs: with: submodules: true - name: Configure CI host - run: configure-ci.sh + run: ./configure-ci.sh - name: Install ${{ matrix.toolchain }} uses: dtolnay/rust-toolchain@master with: @@ -75,7 +75,7 @@ jobs: with: submodules: true - name: Configure CI host - run: configure-ci.sh + run: ./configure-ci.sh - name: Install stable uses: dtolnay/rust-toolchain@stable - name: Install nightly for -Zminimal-versions @@ -115,7 +115,7 @@ jobs: with: submodules: true - name: Configure CI host - run: configure-ci.sh + run: ./configure-ci.sh - name: Install stable uses: dtolnay/rust-toolchain@stable with: From f2731c32911d9f01ace4cfc3855a17a3b1ff555e Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Sat, 20 Jul 2024 11:55:12 +0200 Subject: [PATCH 6/7] heavier sigh --- configure-ci.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/configure-ci.sh b/configure-ci.sh index d952b63..a4ea8da 100755 --- a/configure-ci.sh +++ b/configure-ci.sh @@ -13,7 +13,8 @@ echo "Move Cargo target dir to avoid super long paths" mkdir /tmp/cargo echo "Tell Cargo to use clang and target dir" -cat >.cargo <.cargo/config.toml < Date: Sat, 20 Jul 2024 11:57:40 +0200 Subject: [PATCH 7/7] missed two jobs --- .github/workflows/scheduled.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/scheduled.yml b/.github/workflows/scheduled.yml index 8e276e4..a9146b3 100644 --- a/.github/workflows/scheduled.yml +++ b/.github/workflows/scheduled.yml @@ -22,10 +22,8 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - name: Install libibverbs dependencies - run: | - sudo apt-get update - sudo apt-get install libibverbs1 libibverbs-dev + - name: Configure CI host + run: ./configure-ci.sh - name: Install nightly uses: dtolnay/rust-toolchain@nightly - name: cargo generate-lockfile @@ -49,10 +47,8 @@ jobs: - uses: actions/checkout@v4 with: submodules: true - - name: Install libibverbs dependencies - run: | - sudo apt-get update - sudo apt-get install libibverbs1 libibverbs-dev + - name: Configure CI host + run: ./configure-ci.sh - name: Install beta if: hashFiles('Cargo.lock') != '' uses: dtolnay/rust-toolchain@beta