diff --git a/.github/actions/setup-ninja/action.yml b/.github/actions/setup-ninja/action.yml index d6ddb1b4d..1b4f87a0c 100644 --- a/.github/actions/setup-ninja/action.yml +++ b/.github/actions/setup-ninja/action.yml @@ -3,15 +3,21 @@ runs: steps: - name: install ninja if: runner.os == 'macOS' - run: brew install ninja + run: | + brew install ninja + echo "CMAKE_GENERATOR=Ninja" >> "$GITHUB_ENV" shell: bash - name: install ninja if: runner.os == 'Windows' - run: choco install ninja + run: | + choco install ninja + echo "CMAKE_GENERATOR=Ninja" >> "$GITHUB_ENV" shell: bash - name: install ninja if: runner.os == 'Linux' - run: sudo apt-get install ninja-build + run: | + sudo apt-get install ninja-build + echo "CMAKE_GENERATOR=Ninja" >> "$GITHUB_ENV" shell: bash diff --git a/protobuf/Cargo.toml b/protobuf/Cargo.toml index aec0c56c2..fdf297aba 100644 --- a/protobuf/Cargo.toml +++ b/protobuf/Cargo.toml @@ -13,6 +13,7 @@ prost-types = { path = "../prost-types" } anyhow = "1.0.1" prost-build = { path = "../prost-build" } tempfile = "3" +cmake = "0.1.51" [package.metadata.cargo-machete] ignored = ["prost", "prost-types"] diff --git a/protobuf/build.rs b/protobuf/build.rs index 28da48118..4ca64ede9 100644 --- a/protobuf/build.rs +++ b/protobuf/build.rs @@ -118,35 +118,19 @@ fn install_conformance_test_runner( prefix_dir: &Path, ) -> Result<()> { // Build and install protoc, the protobuf libraries, and the conformance test runner. - let rc = Command::new("cmake") - .arg("-GNinja") - .arg(src_dir.join("cmake")) - .arg("-DCMAKE_BUILD_TYPE=DEBUG") - .arg(format!("-DCMAKE_INSTALL_PREFIX={}", prefix_dir.display())) - .arg("-Dprotobuf_BUILD_CONFORMANCE=ON") - .arg("-Dprotobuf_BUILD_TESTS=OFF") - .current_dir(build_dir) - .status() - .context("failed to execute CMake")?; - assert!(rc.success(), "protobuf CMake failed"); - - let num_jobs = env::var("NUM_JOBS").context("NUM_JOBS environment variable not set")?; - - let rc = Command::new("ninja") - .arg("-j") - .arg(&num_jobs) - .arg("install") - .current_dir(build_dir) - .status() - .context("failed to execute ninja protobuf")?; - ensure!(rc.success(), "failed to make protobuf"); + cmake::Config::new(src_dir.join("cmake")) + .define("CMAKE_INSTALL_PREFIX", prefix_dir) + .define("protobuf_BUILD_CONFORMANCE", "ON") + .define("protobuf_BUILD_TESTS", "OFF") + .out_dir(build_dir) + .build(); // Install the conformance-test-runner binary, since it isn't done automatically. fs::copy( - build_dir.join("conformance_test_runner"), + build_dir.join("build").join("conformance_test_runner"), prefix_dir.join("bin").join("conformance-test-runner"), ) - .context("failed to move conformance-test-runner")?; + .context("failed to copy conformance-test-runner")?; Ok(()) }