build(docs.rs): try a default-feature based approach

This commit is contained in:
chyyran 2023-02-16 01:09:43 -05:00
parent ceb5a6d6ea
commit 0eb9859cc4
11 changed files with 23 additions and 86 deletions

View file

@ -18,7 +18,7 @@ platform-dirs = "0.3.0"
blake3 = { version = "1.3.3" }
thiserror = "1.0.38"
bincode = { version = "2.0.0-rc.2", features = ["serde"] }
rusqlite = { version = "0.28.0", default-features = false, optional = true }
rusqlite = { version = "0.28.0", features = ["bundled"] }
bytemuck = "1.13.0"
@ -32,11 +32,10 @@ features = [
optional = true
[features]
# should be enabled at librashader crate level.
cache = ["rusqlite/bundled"]
d3d = ["windows"]
docsrs = ["blake3/pure"]
# hack to get building on docsrs
docsrs = ["blake3/pure", "rusqlite/in_gecko"]
[package.metadata.docs.rs]
features = ["docsrs"]
no-default-features = true

View file

@ -1,7 +1,6 @@
use crate::cacheable::Cacheable;
use crate::key::CacheKey;
#[cfg(feature = "cache")]
pub(crate) mod internal {
use platform_dirs::AppDirs;
use rusqlite::{Connection, DatabaseName};
@ -66,8 +65,6 @@ pub(crate) mod internal {
}
}
#[cfg(feature = "cache")]
/// Cache a shader object (usually bytecode) created by the keyed objects.
///
/// - `factory` is the function that compiles the values passed as keys to a shader object.
@ -122,7 +119,6 @@ where
Ok(load(blob)?)
}
#[cfg(feature = "cache")]
/// Cache a pipeline state object.
///
/// Keys are not used to create the object and are only used to uniquely identify the pipeline state.
@ -182,9 +178,3 @@ where
Ok(pipeline)
}
#[cfg(not(feature = "cache"))]
pub use crate::docsrs::cache_pipeline;
#[cfg(not(feature = "cache"))]
pub use crate::docsrs::cache_shader_object;

View file

@ -9,7 +9,6 @@ pub struct CachedCompilation<T> {
compilation: T,
}
#[cfg(feature = "cache")]
impl<T: ShaderCompilation + for<'de> serde::Deserialize<'de> + serde::Serialize + Clone>
ShaderCompilation for CachedCompilation<T>
{
@ -57,17 +56,6 @@ impl<T: ShaderCompilation + for<'de> serde::Deserialize<'de> + serde::Serialize
}
}
#[cfg(not(feature = "cache"))]
impl<T: ShaderCompilation + for<'de> serde::Deserialize<'de> + serde::Serialize + Clone>
ShaderCompilation for CachedCompilation<T>
{
fn compile(source: &ShaderSource) -> Result<Self, ShaderCompileError> {
Ok(CachedCompilation {
compilation: T::compile(source)?
})
}
}
impl FromCompilation<CachedCompilation<GlslangCompilation>> for DXIL {
type Target = <DXIL as FromCompilation<GlslangCompilation>>::Target;
type Options = <DXIL as FromCompilation<GlslangCompilation>>::Options;

View file

@ -1,42 +0,0 @@
use crate::{CacheKey, Cacheable};
/// Cache a pipeline state object.
///
/// Keys are not used to create the object and are only used to uniquely identify the pipeline state.
///
/// - `restore_pipeline` tries to restore the pipeline with either a cached binary pipeline state
/// cache, or create a new pipeline if no cached value is available.
/// - `fetch_pipeline_state` fetches the new pipeline state cache after the pipeline was created.
#[allow(unused_variables)]
pub fn cache_pipeline<E, T, R, const KEY_SIZE: usize>(
index: &str,
keys: &[&dyn CacheKey; KEY_SIZE],
restore_pipeline: impl Fn(Option<Vec<u8>>) -> Result<R, E>,
fetch_pipeline_state: impl FnOnce(&R) -> Result<T, E>,
bypass_cache: bool,
) -> Result<R, E>
where
T: Cacheable,
{
eprintln!("[librashader:warn] Cache support was not built, you must rebuild librashader with the cache feature.");
return Ok(restore_pipeline(None)?);
}
/// Cache a shader object (usually bytecode) created by the keyed objects.
///
/// - `factory` is the function that compiles the values passed as keys to a shader object.
/// - `load` tries to load a compiled shader object to a driver-specialized result.
#[allow(unused_variables)]
pub fn cache_shader_object<E, T, R, H, const KEY_SIZE: usize>(
index: &str,
keys: &[H; KEY_SIZE],
factory: impl FnOnce(&[H; KEY_SIZE]) -> Result<T, E>,
load: impl Fn(T) -> Result<R, E>,
bypass_cache: bool,
) -> Result<R, E>
where
H: CacheKey,
T: Cacheable,
{
eprintln!("[librashader:warn] Cache support was not built, you must rebuild librashader with the cache feature.");
return Ok(load(factory(keys)?)?);
}

View file

@ -22,7 +22,3 @@ pub use cache::cache_shader_object;
#[cfg(all(target_os = "windows", feature = "d3d"))]
mod d3d;
#[cfg(not(feature = "cache"))]
mod docsrs;

View file

@ -15,7 +15,7 @@ description = "RetroArch shaders for all."
crate-type = [ "cdylib", "staticlib" ]
[features]
default = ["runtime-all", "librashader/cache" ]
default = ["runtime-all" ]
runtime-all = ["runtime-opengl", "runtime-d3d11", "runtime-d3d12", "runtime-vulkan"]
runtime-opengl = ["gl", "librashader/runtime-gl"]
runtime-d3d11 = ["windows", "librashader/runtime-d3d11", "windows/Win32_Graphics_Direct3D11"]
@ -35,9 +35,6 @@ spirv_cross = { package = "librashader-spirv-cross", version = "0.23" }
version = "0.44.0"
optional = true
[package.metadata.cargo-post.dependencies]
[package.metadata.docs.rs]
targets = ["x86_64-pc-windows-msvc", "x86_64-unknown-linux-gnu"]
no-default-features = true
features = ["runtime-all", "librashader/docsrs"]
features = ["librashader/docsrs"]

View file

@ -57,7 +57,9 @@ features = [
[[test]]
name = "triangle"
required-features = ["librashader-cache/cache"]
[dev-dependencies]
gfx-maths = "0.2.8"
[package.metadata.docs.rs]
features = ["librashader-cache/docsrs"]

View file

@ -65,7 +65,9 @@ features = [
[[test]]
name = "triangle"
required-features = ["librashader-cache/cache"]
[dev-dependencies]
gfx-maths = "0.2.8"
[package.metadata.docs.rs]
features = ["librashader-cache/docsrs"]

View file

@ -31,4 +31,6 @@ glfw = "0.47.0"
[[test]]
name = "triangle"
required-features = ["librashader-cache/cache"]
[package.metadata.docs.rs]
features = ["librashader-cache/docsrs"]

View file

@ -40,4 +40,6 @@ ash-window = "0.12.0"
[[test]]
name = "triangle"
required-features = ["librashader-cache/cache"]
[package.metadata.docs.rs]
features = ["librashader-cache/docsrs"]

View file

@ -23,7 +23,7 @@ librashader-runtime-d3d12 = { path = "../librashader-runtime-d3d12", version =
librashader-runtime-gl = { path = "../librashader-runtime-gl", version = "0.1.0-rc.5", optional = true }
librashader-runtime-vk = { path = "../librashader-runtime-vk", version = "0.1.0-rc.5", optional = true }
librashader-cache = { path = "../librashader-cache", version = "0.1.0-rc.5", default-features = false }
librashader-cache = { path = "../librashader-cache", version = "0.1.0-rc.5" }
ash = { version = "0.37.1+1.3.235", optional = true }
@ -52,13 +52,14 @@ runtime-all = ["runtime-gl", "runtime-d3d11", "runtime-d3d12", "runtime-vk"]
reflect-all = ["reflect-cross", "reflect-dxil"]
# enable all features by default
default = [ "runtime-all", "reflect-all", "preprocess", "presets" ]
default = [ "full" ]
internal = []
cache = ["librashader-cache/cache"]
full = ["runtime-all", "reflect-all", "preprocess", "presets"]
# cache hack
docsrs = ["librashader-cache/docsrs"]
[package.metadata.docs.rs]
targets = ["x86_64-pc-windows-msvc", "x86_64-unknown-linux-gnu"]
no-default-features = true
features = [ "librashader-cache/docsrs" ]