diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4116830834..bd55654183 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -57,7 +57,7 @@ jobs: run: cargo test -p rustc_codegen_spirv --release --no-default-features --features "use-installed-tools" - name: workspace test (excluding examples & difftest) - run: cargo test --release --workspace --exclude "example-runner-*" --exclude "difftest*" --no-default-features --features "use-installed-tools" + run: cargo test --release --workspace --exclude "example-runner-*" --exclude "difftest*" --no-default-features --features "use-installed-tools,clap" # Examples - name: cargo check examples diff --git a/Cargo.lock b/Cargo.lock index 7e8a8aeae8..6d0220a41e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -556,7 +556,7 @@ dependencies = [ "compiletest_rs", "itertools 0.14.0", "rustc_codegen_spirv", - "rustc_codegen_spirv-target-specs", + "rustc_codegen_spirv-types", ] [[package]] @@ -2716,7 +2716,6 @@ dependencies = [ "regex", "rspirv", "rustc-demangle", - "rustc_codegen_spirv-target-specs", "rustc_codegen_spirv-types", "rustix 1.0.8", "sanitize-filename", @@ -2730,18 +2729,16 @@ dependencies = [ "tracing-tree", ] -[[package]] -name = "rustc_codegen_spirv-target-specs" -version = "0.9.0" - [[package]] name = "rustc_codegen_spirv-types" version = "0.9.0" dependencies = [ "rspirv", + "semver", "serde", "serde_json", "spirv", + "thiserror 2.0.16", ] [[package]] @@ -3097,7 +3094,6 @@ dependencies = [ "notify", "raw-string", "rustc_codegen_spirv", - "rustc_codegen_spirv-target-specs", "rustc_codegen_spirv-types", "semver", "serde", diff --git a/Cargo.toml b/Cargo.toml index 7e00acb1ed..1eb4422bb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,6 @@ members = [ "crates/rustc_codegen_spirv", "crates/rustc_codegen_spirv-types", - "crates/rustc_codegen_spirv-target-specs", "crates/spirv-builder", "crates/spirv-std", "crates/spirv-std/shared", @@ -50,7 +49,6 @@ spirv-std-macros = { path = "./crates/spirv-std/macros", version = "=0.9.0" } spirv-tools = { version = "0.13.0", default-features = false } rustc_codegen_spirv = { path = "./crates/rustc_codegen_spirv", version = "=0.9.0", default-features = false } rustc_codegen_spirv-types = { path = "./crates/rustc_codegen_spirv-types", version = "=0.9.0" } -rustc_codegen_spirv-target-specs = { path = "crates/rustc_codegen_spirv-target-specs", version = "=0.9.0" } # difftest libraries mirrored from difftest workspace difftest = { path = "tests/difftests/lib" } diff --git a/crates/rustc_codegen_spirv-target-specs/Cargo.toml b/crates/rustc_codegen_spirv-target-specs/Cargo.toml deleted file mode 100644 index 76e6e2c106..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "rustc_codegen_spirv-target-specs" -description = "target spec json files of rust-gpu for the rustc compiler" -version.workspace = true -authors.workspace = true -edition.workspace = true -license.workspace = true -repository.workspace = true - -[features] -include_str = [] -dir_path = [] diff --git a/crates/rustc_codegen_spirv-target-specs/README.md b/crates/rustc_codegen_spirv-target-specs/README.md deleted file mode 100644 index 9b0bc4d74a..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# `rustc_codegen_spirv-target-specs` - -The target spec json files of rust-gpu to hand to the rustc compiler, declaring various metadata about our codegen backend. - -## Features -* `include_str`: include target specs as string constants, for bundling with `cargo-gpu` -* `dir_path`: export a path to the target specs dir, for `spirv-builder` and `compiletest` in this repo diff --git a/crates/rustc_codegen_spirv-target-specs/src/include_str.rs b/crates/rustc_codegen_spirv-target-specs/src/include_str.rs deleted file mode 100644 index 53fba7f788..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/src/include_str.rs +++ /dev/null @@ -1,75 +0,0 @@ -/// Metadata for the compile targets supported by `rust-gpu` -pub const TARGET_SPECS: &[(&str, &str)] = &[ - ( - "spirv-unknown-opengl4.0.json", - include_str!("../target-specs/spirv-unknown-opengl4.0.json"), - ), - ( - "spirv-unknown-opengl4.1.json", - include_str!("../target-specs/spirv-unknown-opengl4.1.json"), - ), - ( - "spirv-unknown-opengl4.2.json", - include_str!("../target-specs/spirv-unknown-opengl4.2.json"), - ), - ( - "spirv-unknown-opengl4.3.json", - include_str!("../target-specs/spirv-unknown-opengl4.3.json"), - ), - ( - "spirv-unknown-opengl4.5.json", - include_str!("../target-specs/spirv-unknown-opengl4.5.json"), - ), - ( - "spirv-unknown-spv1.0.json", - include_str!("../target-specs/spirv-unknown-spv1.0.json"), - ), - ( - "spirv-unknown-spv1.1.json", - include_str!("../target-specs/spirv-unknown-spv1.1.json"), - ), - ( - "spirv-unknown-spv1.2.json", - include_str!("../target-specs/spirv-unknown-spv1.2.json"), - ), - ( - "spirv-unknown-spv1.3.json", - include_str!("../target-specs/spirv-unknown-spv1.3.json"), - ), - ( - "spirv-unknown-spv1.4.json", - include_str!("../target-specs/spirv-unknown-spv1.4.json"), - ), - ( - "spirv-unknown-spv1.5.json", - include_str!("../target-specs/spirv-unknown-spv1.5.json"), - ), - ( - "spirv-unknown-spv1.6.json", - include_str!("../target-specs/spirv-unknown-spv1.6.json"), - ), - ( - "spirv-unknown-vulkan1.0.json", - include_str!("../target-specs/spirv-unknown-vulkan1.0.json"), - ), - ( - "spirv-unknown-vulkan1.1.json", - include_str!("../target-specs/spirv-unknown-vulkan1.1.json"), - ), - ( - "spirv-unknown-vulkan1.1spv1.4.json", - include_str!("../target-specs/spirv-unknown-vulkan1.1spv1.4.json"), - ), - ( - "spirv-unknown-vulkan1.2.json", - include_str!("../target-specs/spirv-unknown-vulkan1.2.json"), - ), - ( - "spirv-unknown-vulkan1.3.json", - include_str!("../target-specs/spirv-unknown-vulkan1.3.json"), - ), - ( - "spirv-unknown-vulkan1.4.json", - include_str!("../target-specs/spirv-unknown-vulkan1.4.json"), - ), -]; diff --git a/crates/rustc_codegen_spirv-target-specs/src/lib.rs b/crates/rustc_codegen_spirv-target-specs/src/lib.rs deleted file mode 100644 index b3033d9fee..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/src/lib.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![doc = include_str!("../README.md")] - -/// directory with all the `target-specs` jsons for our codegen backend -#[cfg(feature = "dir_path")] -pub const TARGET_SPEC_DIR_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/target-specs"); - -#[cfg(feature = "include_str")] -mod include_str; -#[cfg(feature = "include_str")] -pub use include_str::TARGET_SPECS; diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-opengl4.0.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-opengl4.0.json deleted file mode 100644 index d76e303e2a..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-opengl4.0.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "opengl4.0", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-opengl4.0", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-opengl4.1.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-opengl4.1.json deleted file mode 100644 index 10eaa2f6ed..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-opengl4.1.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "opengl4.1", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-opengl4.1", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-opengl4.2.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-opengl4.2.json deleted file mode 100644 index 9a8e14bced..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-opengl4.2.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "opengl4.2", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-opengl4.2", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-opengl4.3.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-opengl4.3.json deleted file mode 100644 index a164073671..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-opengl4.3.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "opengl4.3", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-opengl4.3", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-opengl4.5.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-opengl4.5.json deleted file mode 100644 index 00d23b035d..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-opengl4.5.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "opengl4.5", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-opengl4.5", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.0.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.0.json deleted file mode 100644 index b1f7f910c3..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.0.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "spv1.0", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-spv1.0", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.1.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.1.json deleted file mode 100644 index 4319c16514..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.1.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "spv1.1", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-spv1.1", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.2.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.2.json deleted file mode 100644 index 43a4ec9bd8..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.2.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "spv1.2", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-spv1.2", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.3.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.3.json deleted file mode 100644 index 3903cdba51..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.3.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "spv1.3", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-spv1.3", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.4.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.4.json deleted file mode 100644 index a645839c76..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.4.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "spv1.4", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-spv1.4", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.5.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.5.json deleted file mode 100644 index 67a2fb375f..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.5.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "spv1.5", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-spv1.5", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.6.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.6.json deleted file mode 100644 index 0208756e96..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-spv1.6.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "spv1.6", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-spv1.6", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.0.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.0.json deleted file mode 100644 index 468d7e6049..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.0.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "vulkan1.0", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-vulkan1.0", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.1.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.1.json deleted file mode 100644 index b75eaa7dd9..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.1.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "vulkan1.1", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-vulkan1.1", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.1spv1.4.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.1spv1.4.json deleted file mode 100644 index 66eaba431b..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.1spv1.4.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "vulkan1.1spv1.4", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-vulkan1.1spv1.4", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.2.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.2.json deleted file mode 100644 index 34032c502a..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.2.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "vulkan1.2", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-vulkan1.2", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.3.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.3.json deleted file mode 100644 index ef4d7c2726..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.3.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "vulkan1.3", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-vulkan1.3", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.4.json b/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.4.json deleted file mode 100644 index f2b4d8ad37..0000000000 --- a/crates/rustc_codegen_spirv-target-specs/target-specs/spirv-unknown-vulkan1.4.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "allows-weak-linkage": false, - "arch": "spirv", - "crt-objects-fallback": "false", - "crt-static-allows-dylibs": true, - "crt-static-respected": true, - "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", - "dll-prefix": "", - "dll-suffix": ".spv.json", - "dynamic-linking": true, - "emit-debug-gdb-scripts": false, - "env": "vulkan1.4", - "linker-flavor": "unix", - "linker-is-gnu": false, - "llvm-target": "spirv-unknown-vulkan1.4", - "main-needs-argc-argv": false, - "metadata": { - "description": null, - "host_tools": null, - "std": null, - "tier": null - }, - "panic-strategy": "abort", - "simd-types-indirect": false, - "target-pointer-width": "32" -} diff --git a/crates/rustc_codegen_spirv-types/Cargo.toml b/crates/rustc_codegen_spirv-types/Cargo.toml index 36bd737f7e..83664a9997 100644 --- a/crates/rustc_codegen_spirv-types/Cargo.toml +++ b/crates/rustc_codegen_spirv-types/Cargo.toml @@ -12,3 +12,5 @@ spirv = { version = "0.3.0", features = ["serialize", "deserialize"] } rspirv = "0.12" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +semver = { version = "1.0.24", features = ["serde"] } +thiserror = "2.0.12" diff --git a/crates/rustc_codegen_spirv-types/src/lib.rs b/crates/rustc_codegen_spirv-types/src/lib.rs index c1ebdee660..336ecefbb0 100644 --- a/crates/rustc_codegen_spirv-types/src/lib.rs +++ b/crates/rustc_codegen_spirv-types/src/lib.rs @@ -3,7 +3,13 @@ pub use rspirv::spirv::Capability; mod compile_result; +mod rustc_version; +mod target; +mod target_spec; pub use compile_result::*; +pub use rustc_version::*; +pub use target::*; +pub use target_spec::*; // HACK(eddyb) allows downstream crates to access the correct version directly. pub use serde; diff --git a/crates/rustc_codegen_spirv-types/src/rustc_version.rs b/crates/rustc_codegen_spirv-types/src/rustc_version.rs new file mode 100644 index 0000000000..fdd708c8f9 --- /dev/null +++ b/crates/rustc_codegen_spirv-types/src/rustc_version.rs @@ -0,0 +1,20 @@ +use semver::Version; +use std::process::Command; + +pub fn query_rustc_version(toolchain: Option<&str>) -> std::io::Result { + let mut cmd = Command::new("rustc"); + if let Some(toolchain) = toolchain { + cmd.arg(format!("+{toolchain}")); + } + cmd.arg("--version"); + let output = cmd.output()?; + + let stdout = String::from_utf8(output.stdout).expect("stdout must be utf-8"); + let parse = |output: &str| { + let output = output.strip_prefix("rustc ")?; + let version = &output[..output.find(|c| !"0123456789.".contains(c))?]; + Version::parse(version).ok() + }; + Ok(parse(&stdout) + .unwrap_or_else(|| panic!("failed parsing `rustc --version` output `{stdout}`"))) +} diff --git a/crates/rustc_codegen_spirv-types/src/target.rs b/crates/rustc_codegen_spirv-types/src/target.rs new file mode 100644 index 0000000000..86c0bb1a0f --- /dev/null +++ b/crates/rustc_codegen_spirv-types/src/target.rs @@ -0,0 +1,70 @@ +use std::fmt::{Debug, Formatter}; +use thiserror::Error; + +pub const SPIRV_TARGET_PREFIX: &str = "spirv-unknown-"; + +/// A well-formed rust-gpu target. +/// +/// The constructors only check whether the target is well-formed, not whether it is valid. Since `spirv-builder` is +/// backwards compatible with older rust-gpu compilers, only the compiler itself knows what targets it can and cannot +/// support. This also allows adding new targets to the compiler without having to update `spirv-builder` and +/// `cargo-gpu`. +/// +/// Differentiates between a full target (e.g. `spirv-unknown-vulkan1.3`) and a target env (e.g. `vulkan1.3`). Use +/// [`Self::parse_target`] and [`Self::target`] to parse or format a full target, or use [`Self::parse_env`] and +/// [`Self::env`] when dealing with just target envs. The convenience function [`Self::parse`] accepts both targets and +/// target envs. Does not implement `Display`, since it is unclear whether the user wants a target or target env, though +/// a `Debug` implementation is provided. +#[derive(Clone)] +pub struct SpirvTarget { + target: String, +} + +impl SpirvTarget { + /// Try to parse either a full target or a target env + pub fn parse(target_or_env: &str) -> Result { + Self::parse_target(target_or_env).or_else(|_| Self::parse_env(target_or_env)) + } + + /// Parse a full target, e.g. `spirv-unknown-vulkan1.3` + pub fn parse_target(target: &str) -> Result { + let _target_env = target.strip_prefix(SPIRV_TARGET_PREFIX).ok_or_else(|| { + TargetError::NonSpirvTarget { + target: target.to_string(), + } + })?; + Ok(Self { + target: target.to_string(), + }) + } + + /// Parse a target env, e.g. `vulkan1.3` + pub fn parse_env(target_env: &str) -> Result { + Ok(Self { + target: format!("{SPIRV_TARGET_PREFIX}{target_env}"), + }) + } + + /// returns the full target, e.g. `spirv-unknown-vulkan1.3` + pub fn target(&self) -> &str { + &self.target + } + + /// returns the target env, e.g. `vulkan1.3` + pub fn env(&self) -> &str { + &self.target[SPIRV_TARGET_PREFIX.len()..] + } +} + +impl Debug for SpirvTarget { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + f.debug_tuple("Target").field(&self.target).finish() + } +} + +#[derive(Debug, Error)] +#[non_exhaustive] +pub enum TargetError { + #[error("SPIR-V target must start with `{SPIRV_TARGET_PREFIX}...`, was `{target}`")] + NonSpirvTarget { target: String }, +} diff --git a/crates/rustc_codegen_spirv-types/src/target_spec.rs b/crates/rustc_codegen_spirv-types/src/target_spec.rs new file mode 100644 index 0000000000..67d339423b --- /dev/null +++ b/crates/rustc_codegen_spirv-types/src/target_spec.rs @@ -0,0 +1,87 @@ +use crate::SpirvTarget; +use semver::Version; +use std::ffi::OsString; +use std::path::Path; + +/// Enum for different versions of target specs, to allow changing the target spec for different rust versions. +/// The version listed in the enum is always the minimum version to require said target spec, with the newest version +/// always at the top. +#[allow(non_camel_case_types)] +#[derive(Copy, Clone, Debug)] +pub enum TargetSpecVersion { + /// Introduced in `489c3ee6fd63da3ca7cf2b15e1ee709d8e078aab` in the old v2 target spec way, later ported to here. + /// remove `os: unknown`, add `crt-static-respected: true` + Rustc_1_85_0, + /// rustc 1.76 has been tested to correctly parse modern target spec jsons. + /// Some later version requires them. + /// Some earlier version fails with them (notably our 0.9.0 release). + Rustc_1_76_0, +} + +impl TargetSpecVersion { + /// Format the `--target` arg. On newer rustc versions, will create a compatible target spec json file and return + /// the absolute path to it, on older rustc versions may return the target name. + pub fn target_arg( + rustc_version: Version, + target: &SpirvTarget, + target_spec_folder: &Path, + ) -> std::io::Result { + if let Some(target_spec) = Self::from_rustc_version(rustc_version) { + std::fs::create_dir_all(target_spec_folder)?; + let spec_file = target_spec_folder.join(format!("{}.json", target.target())); + std::fs::write(&spec_file, target_spec.format_spec(target))?; + Ok(std::fs::canonicalize(spec_file)?.into_os_string()) + } else { + Ok(OsString::from(target.target())) + } + } + + /// Returns the version of the target spec required for a certain rustc version. May return `None` if the version + /// is old enough to not need target specs. + pub fn from_rustc_version(rustc_version: Version) -> Option { + if rustc_version >= Version::new(1, 85, 0) { + Some(Self::Rustc_1_85_0) + } else if rustc_version >= Version::new(1, 76, 0) { + Some(Self::Rustc_1_76_0) + } else { + None + } + } + + /// format the target spec json + pub fn format_spec(&self, target: &SpirvTarget) -> String { + let target_env = target.env(); + let extra = match self { + TargetSpecVersion::Rustc_1_85_0 => r#""crt-static-respected": true,"#, + TargetSpecVersion::Rustc_1_76_0 => r#""os": "unknown","#, + }; + format!( + r#"{{ + "allows-weak-linkage": false, + "arch": "spirv", + "crt-objects-fallback": "false", + "crt-static-allows-dylibs": true, + "data-layout": "e-m:e-p:32:32:32-i64:64-n8:16:32:64", + "dll-prefix": "", + "dll-suffix": ".spv.json", + "dynamic-linking": true, + "emit-debug-gdb-scripts": false, + "env": "{target_env}", + "linker-flavor": "unix", + "linker-is-gnu": false, + "llvm-target": "spirv-unknown-{target_env}", + "main-needs-argc-argv": false, + "metadata": {{ + "description": null, + "host_tools": null, + "std": null, + "tier": null + }}, + {extra} + "panic-strategy": "abort", + "simd-types-indirect": false, + "target-pointer-width": "32" +}}"# + ) + } +} diff --git a/crates/rustc_codegen_spirv/Cargo.toml b/crates/rustc_codegen_spirv/Cargo.toml index 8f7b880855..2357ae1f7f 100644 --- a/crates/rustc_codegen_spirv/Cargo.toml +++ b/crates/rustc_codegen_spirv/Cargo.toml @@ -62,9 +62,6 @@ tracing.workspace = true tracing-subscriber.workspace = true tracing-tree = "0.4.0" -# required for cargo gpu to resolve the needed target specs -rustc_codegen_spirv-target-specs.workspace = true - [dev-dependencies] pretty_assertions = "1.0" diff --git a/crates/spirv-builder/Cargo.toml b/crates/spirv-builder/Cargo.toml index a99bc4d884..5141408379 100644 --- a/crates/spirv-builder/Cargo.toml +++ b/crates/spirv-builder/Cargo.toml @@ -22,14 +22,11 @@ default = ["use-compiled-tools"] # Compile `rustc_codegen_spirv`, allows constructing SpirvBuilder without # explicitly passing in a path to a compiled `rustc_codegen_spirv.so` (or dll) rustc_codegen_spirv = ["dep:rustc_codegen_spirv"] -# Inclide target spec json files, allows constructing SpirvBuilder without -# explicitly passing a path to the target spec json -include-target-specs = ["dep:rustc_codegen_spirv-target-specs"] # See `rustc_codegen_spirv/Cargo.toml` for details on these features. # We add new "default" features to `use-installed-tools` and `use-compiled-tools` to keep # backwards compat with `default-features = false, features = "use-installed-tools"` setups -use-installed-tools = ["rustc_codegen_spirv", "include-target-specs", "rustc_codegen_spirv?/use-installed-tools"] -use-compiled-tools = ["rustc_codegen_spirv", "include-target-specs", "rustc_codegen_spirv?/use-compiled-tools"] +use-installed-tools = ["rustc_codegen_spirv", "rustc_codegen_spirv?/use-installed-tools"] +use-compiled-tools = ["rustc_codegen_spirv", "rustc_codegen_spirv?/use-compiled-tools"] skip-toolchain-check = ["rustc_codegen_spirv?/skip-toolchain-check"] watch = ["dep:notify"] @@ -38,7 +35,6 @@ clap = ["dep:clap"] [dependencies] rustc_codegen_spirv = { workspace = true, optional = true } rustc_codegen_spirv-types = { workspace = true } -rustc_codegen_spirv-target-specs = { workspace = true, features = ["dir_path"], optional = true } memchr = "2.4" raw-string = "0.3.5" diff --git a/crates/spirv-builder/src/lib.rs b/crates/spirv-builder/src/lib.rs index 3bd3c18dec..e1228d63d5 100644 --- a/crates/spirv-builder/src/lib.rs +++ b/crates/spirv-builder/src/lib.rs @@ -73,6 +73,8 @@ pub mod cargo_cmd; mod depfile; +#[cfg(test)] +mod tests; #[cfg(feature = "watch")] mod watch; @@ -85,27 +87,20 @@ use std::env; use std::fs::File; use std::io::BufReader; use std::path::{Path, PathBuf}; -use std::process::{Command, Stdio}; +use std::process::Stdio; use thiserror::Error; -pub use rustc_codegen_spirv_types::Capability; -pub use rustc_codegen_spirv_types::{CompileResult, ModuleResult}; - #[cfg(feature = "watch")] pub use self::watch::{SpirvWatcher, SpirvWatcherError}; - -#[cfg(feature = "include-target-specs")] -pub use rustc_codegen_spirv_target_specs::TARGET_SPEC_DIR_PATH; +pub use rustc_codegen_spirv_types::*; #[derive(Debug, Error)] #[non_exhaustive] pub enum SpirvBuilderError { #[error("`target` must be set, for example `spirv-unknown-vulkan1.2`")] MissingTarget, - #[error("expected `{SPIRV_TARGET_PREFIX}...` target, found `{target}`")] - NonSpirvTarget { target: String }, - #[error("SPIR-V target `{SPIRV_TARGET_PREFIX}-{target_env}` is not supported")] - UnsupportedSpirvTargetEnv { target_env: String }, + #[error("TargetError: {0}")] + TargetError(#[from] TargetError), #[error("`path_to_crate` must be set")] MissingCratePath, #[error("crate path '{0}' does not exist")] @@ -116,11 +111,6 @@ pub enum SpirvBuilderError { MissingRustcCodegenSpirvDylib, #[error("`rustc_codegen_spirv_location` path '{0}' is not a file")] RustcCodegenSpirvDylibDoesNotExist(PathBuf), - #[error( - "Without feature `include-target-specs`, instead of setting a `target`, \ - you need to set the path of the target spec file of your particular target with `path_to_target_spec`" - )] - MissingTargetSpec, #[error("build failed")] BuildFailed, #[error("multi-module build cannot be used with print_metadata = MetadataPrintout::Full")] @@ -136,8 +126,6 @@ pub enum SpirvBuilderError { WatchFailed(#[from] SpirvWatcherError), } -const SPIRV_TARGET_PREFIX: &str = "spirv-unknown-"; - #[derive(Debug, PartialEq, Eq, Clone, Copy, Default, serde::Deserialize, serde::Serialize)] #[cfg_attr(feature = "clap", derive(clap::ValueEnum))] #[non_exhaustive] @@ -461,12 +449,6 @@ pub struct SpirvBuilder { #[cfg_attr(feature = "clap", clap(skip))] pub toolchain_rustc_version: Option, - /// The path of the "target specification" file. - /// - /// For more info on "target specification" see - /// [this RFC](https://rust-lang.github.io/rfcs/0131-target-specification.html). - #[cfg_attr(feature = "clap", clap(skip))] - pub path_to_target_spec: Option, /// Set the target dir path to use for building shaders. Relative paths will be resolved /// relative to the `target` dir of the shader crate, absolute paths are used as is. /// Defaults to `spirv-builder`, resulting in the path `./target/spirv-builder`. @@ -517,7 +499,6 @@ impl Default for SpirvBuilder { extensions: Vec::new(), extra_args: Vec::new(), rustc_codegen_spirv_location: None, - path_to_target_spec: None, target_dir_path: None, toolchain_overwrite: None, toolchain_rustc_version: None, @@ -538,16 +519,6 @@ impl SpirvBuilder { } } - /// Sets the path of the "target specification" file. - /// - /// For more info on "target specification" see - /// [this RFC](https://rust-lang.github.io/rfcs/0131-target-specification.html). - #[must_use] - pub fn target_spec(mut self, p: impl AsRef) -> Self { - self.path_to_target_spec = Some(p.as_ref().to_path_buf()); - self - } - /// Whether to print build.rs cargo metadata (e.g. cargo:rustc-env=var=val). Defaults to [`MetadataPrintout::Full`]. #[must_use] pub fn print_metadata(mut self, v: MetadataPrintout) -> Self { @@ -805,39 +776,17 @@ fn join_checking_for_separators(strings: Vec>, sep: &str) -> St // Returns path to the metadata json. fn invoke_rustc(builder: &SpirvBuilder) -> Result { - let target = builder - .target - .as_ref() - .ok_or(SpirvBuilderError::MissingTarget)?; let path_to_crate = builder .path_to_crate .as_ref() .ok_or(SpirvBuilderError::MissingCratePath)?; + let target; { - let target_env = target.strip_prefix(SPIRV_TARGET_PREFIX).ok_or_else(|| { - SpirvBuilderError::NonSpirvTarget { - target: target.clone(), - } - })?; - // HACK(eddyb) used only to split the full list into groups. - #[allow(clippy::match_same_arms)] - match target_env { - // HACK(eddyb) hardcoded list to avoid checking if the JSON file - // for a particular target exists (and sanitizing strings for paths). - // - // FIXME(eddyb) consider moving this list, or even `target-specs`, - // into `rustc_codegen_spirv_types`'s code/source. - "spv1.0" | "spv1.1" | "spv1.2" | "spv1.3" | "spv1.4" | "spv1.5" | "spv1.6" => {} - "opengl4.0" | "opengl4.1" | "opengl4.2" | "opengl4.3" | "opengl4.5" => {} - "vulkan1.0" | "vulkan1.1" | "vulkan1.1spv1.4" | "vulkan1.2" | "vulkan1.3" - | "vulkan1.4" => {} - - _ => { - return Err(SpirvBuilderError::UnsupportedSpirvTargetEnv { - target_env: target_env.into(), - }); - } - } + let target_str = builder + .target + .as_ref() + .ok_or(SpirvBuilderError::MissingTarget)?; + target = SpirvTarget::parse(target_str)?; if (builder.print_metadata == MetadataPrintout::Full) && builder.multimodule { return Err(SpirvBuilderError::MultiModuleWithPrintMetadata); @@ -1035,28 +984,9 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result { cargo.args(extra_cargoflags.split_whitespace()); } - // FIXME(eddyb) consider moving `target-specs` into `rustc_codegen_spirv_types`. - // FIXME(eddyb) consider the `RUST_TARGET_PATH` env var alternative. - - // NOTE(firestar99) rustc 1.76 has been tested to correctly parse modern - // target_spec jsons, some later version requires them, some earlier - // version fails with them (notably our 0.9.0 release) - if toolchain_rustc_version >= Version::new(1, 76, 0) { - let path_opt = builder.path_to_target_spec.clone(); - let path; - #[cfg(feature = "include-target-specs")] - { - path = path_opt - .unwrap_or_else(|| PathBuf::from(format!("{TARGET_SPEC_DIR_PATH}/{target}.json"))); - } - #[cfg(not(feature = "include-target-specs"))] - { - path = path_opt.ok_or(SpirvBuilderError::MissingTargetSpec)?; - } - cargo.arg("--target").arg(path); - } else { - cargo.arg("--target").arg(target); - } + let target_spec_dir = target_dir.join("target-specs"); + let target = TargetSpecVersion::target_arg(toolchain_rustc_version, &target, &target_spec_dir)?; + cargo.arg("--target").arg(target); if !builder.shader_crate_features.default_features { cargo.arg("--no-default-features"); @@ -1169,21 +1099,3 @@ fn leaf_deps(artifact: &Path, mut handle: impl FnMut(&RawStr)) -> std::io::Resul recurse(&deps_map, artifact.to_str().unwrap().into(), &mut handle); Ok(()) } - -pub fn query_rustc_version(toolchain: Option<&str>) -> std::io::Result { - let mut cmd = Command::new("rustc"); - if let Some(toolchain) = toolchain { - cmd.arg(format!("+{toolchain}")); - } - cmd.arg("--version"); - let output = cmd.output()?; - - let stdout = String::from_utf8(output.stdout).expect("stdout must be utf-8"); - let parse = |output: &str| { - let output = output.strip_prefix("rustc ")?; - let version = &output[..output.find(|c| !"0123456789.".contains(c))?]; - Version::parse(version).ok() - }; - Ok(parse(&stdout) - .unwrap_or_else(|| panic!("failed parsing `rustc --version` output `{stdout}`"))) -} diff --git a/crates/spirv-builder/src/tests.rs b/crates/spirv-builder/src/tests.rs new file mode 100644 index 0000000000..1550a357ba --- /dev/null +++ b/crates/spirv-builder/src/tests.rs @@ -0,0 +1,20 @@ +#[cfg(feature = "clap")] +mod clap { + pub use crate::*; + use clap::Parser; + + /// look at the output of this test to see what `--help` prints + #[test] + fn test_clap_help() { + // any malformed clap declarations should panic within clap's parse + match SpirvBuilder::try_parse_from(["", "--help"]) { + Ok(_) => panic!("`--help` should make clap return an error"), + Err(e) => { + let e = e.to_string(); + println!("{}", e); + // sanity check help + assert!(e.contains("--target")); + } + }; + } +} diff --git a/tests/compiletests/Cargo.toml b/tests/compiletests/Cargo.toml index 9ea4a4ce46..8b88c9211b 100644 --- a/tests/compiletests/Cargo.toml +++ b/tests/compiletests/Cargo.toml @@ -16,7 +16,7 @@ use-compiled-tools = ["rustc_codegen_spirv/use-compiled-tools"] [dependencies] compiletest = { version = "0.11.2", package = "compiletest_rs" } rustc_codegen_spirv = { workspace = true } -rustc_codegen_spirv-target-specs = { workspace = true, features = ["dir_path"] } +rustc_codegen_spirv-types = { workspace = true } clap = { version = "4", features = ["derive"] } itertools = "0.14.0" diff --git a/tests/compiletests/src/main.rs b/tests/compiletests/src/main.rs index 843f9d9ea7..abe325d8b6 100644 --- a/tests/compiletests/src/main.rs +++ b/tests/compiletests/src/main.rs @@ -1,6 +1,7 @@ use clap::Parser; use itertools::Itertools as _; -use rustc_codegen_spirv_target_specs::TARGET_SPEC_DIR_PATH; +use rustc_codegen_spirv_types::{SpirvTarget, TargetSpecVersion, query_rustc_version}; +use std::ffi::OsString; use std::{ env, io, path::{Path, PathBuf}, @@ -28,12 +29,6 @@ impl Opt { } } -const SPIRV_TARGET_PREFIX: &str = "spirv-unknown-"; - -fn target_spec_json(target: &str) -> String { - format!("{TARGET_SPEC_DIR_PATH}/{target}.json") -} - #[derive(Copy, Clone)] enum DepKind { SpirvLib, @@ -48,9 +43,9 @@ impl DepKind { } } - fn target_dir_suffix(self, target: &str) -> String { + fn target_dir_suffix(self, target: &SpirvTarget) -> String { match self { - Self::SpirvLib => format!("{target}/debug/deps"), + Self::SpirvLib => format!("{}/debug/deps", target.target()), Self::ProcMacro => "debug/deps".into(), } } @@ -59,6 +54,10 @@ impl DepKind { fn main() { let opt = Opt::parse(); + // Pull in rustc_codegen_spirv as a dynamic library in the same way + // spirv-builder does. + let codegen_backend_path = find_rustc_codegen_spirv(); + let tests_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); let workspace_root = tests_dir.parent().unwrap().parent().unwrap(); let original_target_dir = workspace_root.join("target"); @@ -72,10 +71,6 @@ fn main() { std::env::set_current_dir(tests_dir).unwrap(); let tests_dir = PathBuf::from(""); - // Pull in rustc_codegen_spirv as a dynamic library in the same way - // spirv-builder does. - let codegen_backend_path = find_rustc_codegen_spirv(); - let runner = Runner { opt, tests_dir, @@ -161,8 +156,8 @@ impl Runner { println!("Testing env: {stage_id}\n"); - let target = format!("{SPIRV_TARGET_PREFIX}{env}"); - let libs = build_deps(&self.deps_target_dir, &self.codegen_backend_path, &target); + let target = SpirvTarget::parse(env).unwrap(); + let libs = self.build_deps(&target); let mut flags = test_rustc_flags( &self.codegen_backend_path, &libs, @@ -181,7 +176,7 @@ impl Runner { stage_id, target_rustcflags: Some(flags), mode: mode.parse().expect("Invalid mode"), - target: target_spec_json(&target), + target: self.target_spec_json(&target).into_string().unwrap(), src_base: self.tests_dir.join(mode), build_base: self.compiletest_build_dir.clone(), bless: self.opt.bless, @@ -194,90 +189,86 @@ impl Runner { compiletest::run_tests(&config); } } -} - -/// Runs the processes needed to build `spirv-std` & other deps. -fn build_deps(deps_target_dir: &Path, codegen_backend_path: &Path, target: &str) -> TestDeps { - // Build compiletests-deps-helper - std::process::Command::new("cargo") - .args([ - "build", - "-p", - "compiletests-deps-helper", - "-Zbuild-std=core", - "-Zbuild-std-features=compiler-builtins-mem", - &*format!("--target={}", target_spec_json(target)), - ]) - .arg("--target-dir") - .arg(deps_target_dir) - .env("RUSTFLAGS", rust_flags(codegen_backend_path)) - .stderr(std::process::Stdio::inherit()) - .stdout(std::process::Stdio::inherit()) - .status() - .and_then(map_status_to_result) - .unwrap(); - - let compiler_builtins = find_lib( - deps_target_dir, - "compiler_builtins", - DepKind::SpirvLib, - target, - ); - let core = find_lib(deps_target_dir, "core", DepKind::SpirvLib, target); - let spirv_std = find_lib(deps_target_dir, "spirv_std", DepKind::SpirvLib, target); - let glam = find_lib(deps_target_dir, "glam", DepKind::SpirvLib, target); - let spirv_std_macros = find_lib( - deps_target_dir, - "spirv_std_macros", - DepKind::ProcMacro, - target, - ); - let all_libs = [ - &compiler_builtins, - &core, - &spirv_std, - &glam, - &spirv_std_macros, - ]; - if all_libs.iter().any(|r| r.is_err()) { - // FIXME(eddyb) `missing_count` should always be `0` anyway. - // FIXME(eddyb) use `--message-format=json-render-diagnostics` to - // avoid caring about duplicates (or search within files at all). - let missing_count = all_libs - .iter() - .filter(|r| matches!(r, Err(FindLibError::Missing))) - .count(); - let duplicate_count = all_libs - .iter() - .filter(|r| matches!(r, Err(FindLibError::Duplicate))) - .count(); - eprintln!( - "warning: cleaning deps ({missing_count} missing libs, {duplicate_count} duplicated libs)" - ); - clean_deps(deps_target_dir); - build_deps(deps_target_dir, codegen_backend_path, target) - } else { - TestDeps { - core: core.ok().unwrap(), - glam: glam.ok().unwrap(), - compiler_builtins: compiler_builtins.ok().unwrap(), - spirv_std: spirv_std.ok().unwrap(), - spirv_std_macros: spirv_std_macros.ok().unwrap(), + /// Runs the processes needed to build `spirv-std` & other deps. + fn build_deps(&self, target: &SpirvTarget) -> TestDeps { + // Build compiletests-deps-helper + std::process::Command::new("cargo") + .args([ + "build", + "-p", + "compiletests-deps-helper", + "-Zbuild-std=core", + "-Zbuild-std-features=compiler-builtins-mem", + "--target", + ]) + .arg(self.target_spec_json(target)) + .arg("--target-dir") + .arg(&self.deps_target_dir) + .env("RUSTFLAGS", rust_flags(&self.codegen_backend_path)) + .stderr(std::process::Stdio::inherit()) + .stdout(std::process::Stdio::inherit()) + .status() + .and_then(map_status_to_result) + .unwrap(); + + let compiler_builtins = self.find_lib("compiler_builtins", DepKind::SpirvLib, target); + let core = self.find_lib("core", DepKind::SpirvLib, target); + let spirv_std = self.find_lib("spirv_std", DepKind::SpirvLib, target); + let glam = self.find_lib("glam", DepKind::SpirvLib, target); + let spirv_std_macros = self.find_lib("spirv_std_macros", DepKind::ProcMacro, target); + + let all_libs = [ + &compiler_builtins, + &core, + &spirv_std, + &glam, + &spirv_std_macros, + ]; + if all_libs.iter().any(|r| r.is_err()) { + // FIXME(eddyb) `missing_count` should always be `0` anyway. + // FIXME(eddyb) use `--message-format=json-render-diagnostics` to + // avoid caring about duplicates (or search within files at all). + let missing_count = all_libs + .iter() + .filter(|r| matches!(r, Err(FindLibError::Missing))) + .count(); + let duplicate_count = all_libs + .iter() + .filter(|r| matches!(r, Err(FindLibError::Duplicate))) + .count(); + eprintln!( + "warning: cleaning deps ({missing_count} missing libs, {duplicate_count} duplicated libs)" + ); + self.clean_deps(); + self.build_deps(target) + } else { + TestDeps { + core: core.ok().unwrap(), + glam: glam.ok().unwrap(), + compiler_builtins: compiler_builtins.ok().unwrap(), + spirv_std: spirv_std.ok().unwrap(), + spirv_std_macros: spirv_std_macros.ok().unwrap(), + } } } -} -fn clean_deps(deps_target_dir: &Path) { - std::process::Command::new("cargo") - .arg("clean") - .arg("--target-dir") - .arg(deps_target_dir) - .stderr(std::process::Stdio::inherit()) - .stdout(std::process::Stdio::inherit()) - .status() - .and_then(map_status_to_result) - .unwrap(); + fn clean_deps(&self) { + std::process::Command::new("cargo") + .arg("clean") + .arg("--target-dir") + .arg(&self.deps_target_dir) + .stderr(std::process::Stdio::inherit()) + .stdout(std::process::Stdio::inherit()) + .status() + .and_then(map_status_to_result) + .unwrap(); + } + + fn target_spec_json(&self, target: &SpirvTarget) -> OsString { + let rustc_version = query_rustc_version(None).unwrap(); + TargetSpecVersion::target_arg(rustc_version, target, &self.deps_target_dir).unwrap() + } } enum FindLibError { @@ -285,49 +276,53 @@ enum FindLibError { Duplicate, } -/// Attempt find the rlib that matches `base`, if multiple rlibs are found then -/// a clean build is required and `Err(FindLibError::Duplicate)` is returned. -fn find_lib( - deps_target_dir: &Path, - base: impl AsRef, - dep_kind: DepKind, - target: &str, -) -> Result { - let base = base.as_ref(); - let (expected_prefix, expected_extension) = dep_kind.prefix_and_extension(); - let expected_name = format!("{}{}", expected_prefix, base.display()); - - let dir = deps_target_dir.join(dep_kind.target_dir_suffix(target)); - - std::fs::read_dir(dir) - .unwrap() - .map(|entry| entry.unwrap().path()) - .filter(move |path| { - let name = { - let name = path.file_stem(); - if name.is_none() { - return false; - } - name.unwrap() - }; - - let name_matches = name.to_str().unwrap().starts_with(&expected_name) +impl Runner { + /// Attempt find the rlib that matches `base`, if multiple rlibs are found then + /// a clean build is required and `Err(FindLibError::Duplicate)` is returned. + fn find_lib( + &self, + base: impl AsRef, + dep_kind: DepKind, + target: &SpirvTarget, + ) -> Result { + let base = base.as_ref(); + let (expected_prefix, expected_extension) = dep_kind.prefix_and_extension(); + let expected_name = format!("{}{}", expected_prefix, base.display()); + + let dir = self + .deps_target_dir + .join(dep_kind.target_dir_suffix(target)); + + std::fs::read_dir(dir) + .unwrap() + .map(|entry| entry.unwrap().path()) + .filter(move |path| { + let name = { + let name = path.file_stem(); + if name.is_none() { + return false; + } + name.unwrap() + }; + + let name_matches = name.to_str().unwrap().starts_with(&expected_name) && name.len() == expected_name.len() + 17 // we expect our name, '-', and then 16 hexadecimal digits && ends_with_dash_hash(name.to_str().unwrap()); - let extension_matches = path - .extension() - .is_some_and(|ext| ext == expected_extension); - - name_matches && extension_matches - }) - .exactly_one() - .map_err(|mut iter| { - if iter.next().is_none() { - FindLibError::Missing - } else { - FindLibError::Duplicate - } - }) + let extension_matches = path + .extension() + .is_some_and(|ext| ext == expected_extension); + + name_matches && extension_matches + }) + .exactly_one() + .map_err(|mut iter| { + if iter.next().is_none() { + FindLibError::Missing + } else { + FindLibError::Duplicate + } + }) + } } /// Returns whether this string ends with a dash ('-'), followed by 16 lowercase hexadecimal characters @@ -414,10 +409,14 @@ fn dylib_path_envvar() -> &'static str { } fn dylib_path() -> Vec { - match env::var_os(dylib_path_envvar()) { + let mut dylibs = match env::var_os(dylib_path_envvar()) { Some(var) => env::split_paths(&var).collect(), None => Vec::new(), + }; + if let Ok(dir) = env::current_dir() { + dylibs.push(dir); } + dylibs } fn find_rustc_codegen_spirv() -> PathBuf { @@ -426,7 +425,8 @@ fn find_rustc_codegen_spirv() -> PathBuf { env::consts::DLL_PREFIX, env::consts::DLL_SUFFIX ); - for mut path in dylib_path() { + let dylib_paths = dylib_path(); + for mut path in dylib_paths { path.push(&filename); if path.is_file() { return path; diff --git a/tests/difftests/tests/Cargo.lock b/tests/difftests/tests/Cargo.lock index b77f1e1a79..03413d5971 100644 --- a/tests/difftests/tests/Cargo.lock +++ b/tests/difftests/tests/Cargo.lock @@ -1241,9 +1241,11 @@ name = "rustc_codegen_spirv-types" version = "0.9.0" dependencies = [ "rspirv", + "semver", "serde", "serde_json", "spirv", + "thiserror", ] [[package]]