From 1b2cb327f68763d84acb03e83af796b2ebe0d5bd Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Wed, 18 Nov 2020 10:35:23 +0100 Subject: [PATCH 1/4] Give a compile error if neither of the use* features are enabled --- spirv-tools-sys/build.rs | 11 ++++++++--- spirv-tools-sys/src/lib.rs | 3 +++ src/lib.rs | 3 +++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/spirv-tools-sys/build.rs b/spirv-tools-sys/build.rs index 96d7128..05eed06 100644 --- a/spirv-tools-sys/build.rs +++ b/spirv-tools-sys/build.rs @@ -219,9 +219,14 @@ fn val(build: &mut Build) { } fn main() { - if std::env::var("CARGO_FEATURE_USE_INSTALLED_TOOLS").is_ok() - && std::env::var("CARGO_FEATURE_USE_COMPILED_TOOLS").is_err() - { + let use_installed = std::env::var("CARGO_FEATURE_USE_INSTALLED_TOOLS").is_ok(); + let use_compiled = std::env::var("CARGO_FEATURE_USE_COMPILED_TOOLS").is_ok(); + + if !use_compiled && !use_installed { + panic!("Enable at least one of `use-compiled-tools` or `use-installed-tools` features"); + } + + if use_installed && !use_compiled { println!("cargo:warning=use-installed-tools feature on, skipping compilation of C++ code"); return; } diff --git a/spirv-tools-sys/src/lib.rs b/spirv-tools-sys/src/lib.rs index e40dccc..32df4e3 100644 --- a/spirv-tools-sys/src/lib.rs +++ b/spirv-tools-sys/src/lib.rs @@ -1,3 +1,6 @@ +#[cfg(not(any(feature = "use-installed-tools", feature = "use-compiled-tools")))] +compile_error!("Enable at least one of `use-compiled-tools` or `use-installed-tools` features"); + pub mod assembler; pub mod diagnostics; pub mod opt; diff --git a/src/lib.rs b/src/lib.rs index 6b53fa9..3f5b446 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,6 @@ +#[cfg(not(any(feature = "use-installed-tools", feature = "use-compiled-tools")))] +compile_error!("Enable at least one of `use-compiled-tools` or `use-installed-tools` features"); + pub mod assembler; pub mod binary; pub mod opt; From 4a2e4112819a7e083bef6c59f883e148a451100c Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Wed, 18 Nov 2020 10:42:49 +0100 Subject: [PATCH 2/4] Enable feature for publish check --- .github/workflows/rust-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml index 0a840fd..2788232 100644 --- a/.github/workflows/rust-ci.yml +++ b/.github/workflows/rust-ci.yml @@ -98,7 +98,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: publish - args: --dry-run --manifest-path spirv-tools-sys/Cargo.toml + args: --dry-run --manifest-path spirv-tools-sys/Cargo.toml --features use-compiled-tools - name: cargo publish check uses: actions-rs/cargo@v1 with: From 524985f1ae9f38364c9d0005de39ec9e98db2c20 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Wed, 18 Nov 2020 10:50:48 +0100 Subject: [PATCH 3/4] Change to just use default instead --- .github/workflows/rust-ci.yml | 2 +- spirv-tools-sys/Cargo.toml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml index 2788232..0a840fd 100644 --- a/.github/workflows/rust-ci.yml +++ b/.github/workflows/rust-ci.yml @@ -98,7 +98,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: publish - args: --dry-run --manifest-path spirv-tools-sys/Cargo.toml --features use-compiled-tools + args: --dry-run --manifest-path spirv-tools-sys/Cargo.toml - name: cargo publish check uses: actions-rs/cargo@v1 with: diff --git a/spirv-tools-sys/Cargo.toml b/spirv-tools-sys/Cargo.toml index 06e42d6..eaeeaf3 100644 --- a/spirv-tools-sys/Cargo.toml +++ b/spirv-tools-sys/Cargo.toml @@ -22,6 +22,7 @@ include = [ ] [features] +default = ["use-compiled-tools"] # Using this feature disables the compilation in the build script, but # preserves the types so that spirv-tools can still work without needing # to keep copies of some of the basic enums etc From 3301cd97661ab1ea5776f0afc5237abaa3adc4ac Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Wed, 18 Nov 2020 11:02:39 +0100 Subject: [PATCH 4/4] Update CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2554fbf..6bfa3ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate +### Added +- [PR#4](https://github.com/EmbarkStudios/spirv-tools-rs/pull/4) added more clear compile errors if neither of the `use-*-tools` features are enabled for either `spirv-tools` or `spirv-tools-sys`. + +### Changed +- [PR#4](https://github.com/EmbarkStudios/spirv-tools-rs/pull/4) made `use-compiled-tools` the default feature for `spirv-tools-sys`. This would only affect direct consumers of `spirv-tools-sys`. + ## [0.1.0] - 2020-11-13 ### Added - Added initial implementation, which includes the assembler, validator, and most of the optimizer, which meets the current needs of rust-gpu.