Skip to content

Build script complaining about cargo edition feature #99

@NoSanityHere

Description

@NoSanityHere

Im getting an error about cargo edition features when cargo gpu compiles my shader crate:

  error: failed to parse manifest at` /workspace_root/shaders/Cargo.toml`

  Caused by:
    feature `edition2024` is required

    The package requires the Cargo feature called `edition2024`, but that feature is not stabilized in this version of Cargo (1.84.0-nightly (66221abde 2024-11-19)).
    Consider adding `cargo-features = ["edition2024"]` to the top of Cargo.toml (above the [package] table) to tell Cargo you are opting in to use this unstable feature.
    See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#edition-2024 for more information about the status of this feature.
  Error: BuildFailed

adding the line at the top of Cargo.toml (in both the workspace and shader crate) does work, but it also causes a warning about the feature no longer being neccesary (im guessing the warning comes from compiling the main crate, but the error would come from the shader crate being compiled)

just wondering if im doing something wrong, or if its just the version of rust nightly that something is currently using, and itll be fixed when the compiler version is changed?

here is the build script:

use cargo_gpu::spirv_builder::{MetadataPrintout, SpirvMetadata};
use std::path::PathBuf;
use std::{env, fs};

// mostly stolen from https://github.com/Rust-GPU/rust-gpu/issues/291#issuecomment-3004833358

fn main() -> Result<(), Box<dyn std::error::Error>> {
	let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("Always set by Cargo; qed");
	
	if target_arch != "spirv" {
		let out_dir = env::var("OUT_DIR").expect("Always set by Cargo; qed");
		
		// Skip compilation under Clippy, it doesn't work for some reason and isn't really needed
		// anyway
		if env::var("CLIPPY_ARGS").is_ok() {
			let empty_file = PathBuf::from(out_dir).join("empty.bin");
			fs::write(&empty_file, [])?;
			println!("cargo::rustc-env=SHADER_PATH={}", empty_file.display());
			
			return Ok(());
		}
		
		let profile = env::var("PROFILE").expect("Always set by Cargo; qed");
		
		let shader_crate = PathBuf::from("./shaders");
		
		// TODO: Workaround for https://github.com/Rust-GPU/cargo-gpu/issues/90
		let cargo_target_dir = env::var("CARGO_TARGET_DIR").ok();
		// SAFETY: Single-threaded
		unsafe {
			env::remove_var("CARGO_TARGET_DIR");
		}
		
		let backend = cargo_gpu::Install::from_shader_crate(shader_crate.clone()).run()?;

		// TODO: Workaround for https://github.com/Rust-GPU/cargo-gpu/issues/90
		if let Some(cargo_target_dir) = cargo_target_dir {
			// SAFETY: Single-threaded
			unsafe {
				env::set_var("CARGO_TARGET_DIR", cargo_target_dir);
			}
		}
		
		let mut builder = backend.to_spirv_builder(shader_crate, "spirv-unknown-vulkan1.2");
		builder.print_metadata = MetadataPrintout::DependencyOnly;
		builder.spirv_metadata = if profile == "debug" {
			SpirvMetadata::NameVariables
		} else {
			SpirvMetadata::None
		};
		// Avoid Cargo deadlock
		builder.target_dir_path.replace(out_dir.into());

		let spv_result = builder.build()?;
		
		let path_to_shaders = spv_result.module.unwrap_single();
		let shader_fmt = "SPV";
		
		println!("cargo::rustc-env=SHADER_PATH={}", path_to_shaders.display());
		println!("cargo::rustc-env=SHADER_FMT={}", shader_fmt);
	}
	
	Ok(())
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions