Skip to content

Commit 79d36e7

Browse files
mockersfcart
andcommitted
Prepare crevice for vendored release (#3394)
# Objective - Our crevice is still called "crevice", which we can't use for a release - Users would need to use our "crevice" directly to be able to use the derive macro ## Solution - Rename crevice to bevy_crevice, and crevice-derive to bevy-crevice-derive - Re-export it from bevy_render, and use it from bevy_render everywhere - Fix derive macro to work either from bevy_render, from bevy_crevice, or from bevy ## Remaining - It is currently re-exported as `bevy::render::bevy_crevice`, is it the path we want? - After a brief suggestion to Cart, I changed the version to follow Bevy version instead of crevice, do we want that? - Crevice README.md need to be updated - in the `Cargo.toml`, there are a few things to change. How do we want to change them? How do we keep attributions to original Crevice? ``` authors = ["Lucien Greathouse <me@lpghatguy.com>"] documentation = "https://docs.rs/crevice" homepage = "https://github.com/LPGhatguy/crevice" repository = "https://github.com/LPGhatguy/crevice" ``` Co-authored-by: François <8672791+mockersf@users.noreply.github.com> Co-authored-by: Carter Anderson <mcanders1@gmail.com>
1 parent aeba9fa commit 79d36e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+161
-117
lines changed

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ ron = "0.7.0"
102102
serde = { version = "1", features = ["derive"] }
103103
# Needed to poll Task examples
104104
futures-lite = "1.11.3"
105-
crevice = { path = "crates/crevice", version = "0.8.0", features = ["glam"] }
106105

107106
[[example]]
108107
name = "hello_world"

crates/crevice/Cargo.toml renamed to crates/bevy_crevice/Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
2-
name = "crevice"
3-
description = "Create GLSL-compatible versions of structs with explicitly-initialized padding"
4-
version = "0.8.0"
2+
name = "bevy_crevice"
3+
description = "Create GLSL-compatible versions of structs with explicitly-initialized padding (Bevy version)"
4+
version = "0.5.0"
55
edition = "2021"
66
authors = ["Lucien Greathouse <me@lpghatguy.com>"]
77
documentation = "https://docs.rs/crevice"
88
homepage = "https://github.com/LPGhatguy/crevice"
9-
repository = "https://github.com/LPGhatguy/crevice"
9+
repository = "https://github.com/bevyengine/bevy"
1010
readme = "README.md"
1111
keywords = ["glsl", "std140", "std430"]
1212
license = "MIT OR Apache-2.0"
@@ -23,7 +23,7 @@ std = []
2323
# default-members = ["crevice-derive", "crevice-tests"]
2424

2525
[dependencies]
26-
crevice-derive = { version = "0.8.0", path = "crevice-derive" }
26+
bevy-crevice-derive = { version = "0.5.0", path = "bevy-crevice-derive" }
2727

2828
bytemuck = "1.4.1"
2929
mint = "0.5.8"
File renamed without changes.
File renamed without changes.

crates/crevice/README.md renamed to crates/bevy_crevice/README.md

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
# Crevice
1+
# Bevy Crevice
22

3-
[![GitHub CI Status](https://github.com/LPGhatguy/crevice/workflows/CI/badge.svg)](https://github.com/LPGhatguy/crevice/actions)
4-
[![crevice on crates.io](https://img.shields.io/crates/v/crevice.svg)](https://crates.io/crates/crevice)
5-
[![crevice docs](https://img.shields.io/badge/docs-docs.rs-orange.svg)](https://docs.rs/crevice)
3+
This is a fork of [Crevice](https://crates.io/crates/crevice) for
4+
[Bevy](https://bevyengine.org).
5+
6+
For use outside of Bevy, you should consider
7+
using [Crevice](https://crates.io/crates/crevice) directly.
8+
9+
It was forked to allow better integration in Bevy:
10+
11+
* Easier derive macro usage, without needing to depend on `Crevice` directly.
12+
* Use of unmerged features (as of the fork), like
13+
[Array Support](https://github.com/LPGhatguy/crevice/pull/27/).
14+
* Renaming of traits and macros to better match Bevy API.
15+
16+
## Crevice
617

718
Crevice creates GLSL-compatible versions of types through the power of derive
819
macros. Generated structures provide an [`as_bytes`][std140::Std140::as_bytes]
@@ -21,7 +32,7 @@ other math libraries by use of the mint crate. Crevice currently supports:
2132
* mint 0.5, enabled by default
2233
* cgmath 0.18, using the `cgmath` feature
2334
* nalgebra 0.29, using the `nalgebra` feature
24-
* glam 0.19, using the `glam` feature
35+
* glam 0.20, using the `glam` feature
2536

2637
PRs are welcome to add or update math libraries to Crevice.
2738

@@ -50,7 +61,7 @@ uniform MAIN {
5061
```
5162

5263
```rust
53-
use crevice::std140::{AsStd140, Std140};
64+
use bevy_crevice::std140::{AsStd140, Std140};
5465

5566
#[derive(AsStd140)]
5667
struct MainUniform {
@@ -93,7 +104,7 @@ buffer POINT_LIGHTS {
93104
```
94105

95106
```rust
96-
use crevice::std140::{self, AsStd140};
107+
use bevy_crevice::std140::{self, AsStd140};
97108

98109
#[derive(AsStd140)]
99110
struct PointLight {
File renamed without changes.

crates/crevice/crevice-derive/Cargo.toml renamed to crates/bevy_crevice/bevy-crevice-derive/Cargo.toml

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
2-
name = "crevice-derive"
3-
description = "Derive crate for the 'crevice' crate"
4-
version = "0.8.0"
2+
name = "bevy-crevice-derive"
3+
description = "Derive crate for the 'crevice' crate (Bevy version)"
4+
version = "0.5.0"
55
edition = "2018"
66
authors = ["Lucien Greathouse <me@lpghatguy.com>"]
77
documentation = "https://docs.rs/crevice-derive"
88
homepage = "https://github.com/LPGhatguy/crevice"
9-
repository = "https://github.com/LPGhatguy/crevice"
9+
repository = "https://github.com/bevyengine/bevy"
1010
license = "MIT OR Apache-2.0"
1111

1212
[features]
@@ -24,3 +24,4 @@ proc-macro = true
2424
syn = "1.0.40"
2525
quote = "1.0.7"
2626
proc-macro2 = "1.0.21"
27+
bevy_macro_utils = { path = "../../bevy_macro_utils", version = "0.5.0" }

crates/crevice/crevice-derive/src/glsl.rs renamed to crates/bevy_crevice/bevy-crevice-derive/src/glsl.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use quote::quote;
33
use syn::{parse_quote, Data, DeriveInput, Fields, Path};
44

55
pub fn emit(input: DeriveInput) -> TokenStream {
6+
let bevy_crevice_path = crate::bevy_crevice_path();
7+
68
let fields = match &input.data {
79
Data::Struct(data) => match &data.fields {
810
Fields::Named(fields) => fields,
@@ -12,8 +14,8 @@ pub fn emit(input: DeriveInput) -> TokenStream {
1214
Data::Enum(_) | Data::Union(_) => panic!("Only structs are supported"),
1315
};
1416

15-
let base_trait_path: Path = parse_quote!(::crevice::glsl::Glsl);
16-
let struct_trait_path: Path = parse_quote!(::crevice::glsl::GlslStruct);
17+
let base_trait_path: Path = parse_quote!(#bevy_crevice_path::glsl::Glsl);
18+
let struct_trait_path: Path = parse_quote!(#bevy_crevice_path::glsl::GlslStruct);
1719

1820
let name = input.ident;
1921
let name_str = Literal::string(&name.to_string());
@@ -23,14 +25,14 @@ pub fn emit(input: DeriveInput) -> TokenStream {
2325
let glsl_fields = fields.named.iter().map(|field| {
2426
let field_ty = &field.ty;
2527
let field_name_str = Literal::string(&field.ident.as_ref().unwrap().to_string());
26-
let field_as = quote! {<#field_ty as ::crevice::glsl::GlslArray>};
28+
let field_as = quote! {<#field_ty as #bevy_crevice_path::glsl::GlslArray>};
2729

2830
quote! {
2931
s.push_str("\t");
3032
s.push_str(#field_as::NAME);
3133
s.push_str(" ");
3234
s.push_str(#field_name_str);
33-
<#field_as::ArraySize as ::crevice::glsl::DimensionList>::push_to_string(s);
35+
<#field_as::ArraySize as #bevy_crevice_path::glsl::DimensionList>::push_to_string(s);
3436
s.push_str(";\n");
3537
}
3638
});

crates/crevice/crevice-derive/src/layout.rs renamed to crates/bevy_crevice/bevy-crevice-derive/src/layout.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ pub fn emit(
88
mod_name: &'static str,
99
min_struct_alignment: usize,
1010
) -> TokenStream {
11+
let bevy_crevice_path = crate::bevy_crevice_path();
12+
1113
let mod_name = Ident::new(mod_name, Span::call_site());
1214
let trait_name = Ident::new(trait_name, Span::call_site());
1315

14-
let mod_path: Path = parse_quote!(::crevice::#mod_name);
16+
let mod_path: Path = parse_quote!(#bevy_crevice_path::#mod_name);
1517
let trait_path: Path = parse_quote!(#mod_path::#trait_name);
1618

1719
let as_trait_name = format_ident!("As{}", trait_name);
@@ -63,7 +65,7 @@ pub fn emit(
6365

6466
let field_alignments = fields.iter().map(|field| layout_alignment_of_ty(&field.ty));
6567
let struct_alignment = quote! {
66-
::crevice::internal::max_arr([
68+
#bevy_crevice_path::internal::max_arr([
6769
#min_struct_alignment,
6870
#(#field_alignments,)*
6971
])
@@ -139,13 +141,13 @@ pub fn emit(
139141
// We set our target alignment to the larger of the
140142
// alignment due to the previous field and the alignment
141143
// requirement of the next field.
142-
let alignment = ::crevice::internal::max(
144+
let alignment = #bevy_crevice_path::internal::max(
143145
#next_field_or_self_alignment,
144146
min_alignment,
145147
);
146148

147149
// Using everything we've got, compute our padding amount.
148-
::crevice::internal::align_offset(starting_offset, alignment)
150+
#bevy_crevice_path::internal::align_offset(starting_offset, alignment)
149151
}
150152
}
151153
})
@@ -222,7 +224,7 @@ pub fn emit(
222224
let size = ::core::mem::size_of::<Self>();
223225
let align = <Self as #trait_path>::ALIGNMENT;
224226

225-
let zeroed: Self = ::crevice::internal::bytemuck::Zeroable::zeroed();
227+
let zeroed: Self = #bevy_crevice_path::internal::bytemuck::Zeroable::zeroed();
226228

227229
#[derive(Debug)]
228230
struct Field {
@@ -253,13 +255,13 @@ pub fn emit(
253255
#pad_fn_impls
254256
#struct_definition
255257

256-
unsafe impl #impl_generics ::crevice::internal::bytemuck::Zeroable for #generated_name #ty_generics #where_clause {}
257-
unsafe impl #impl_generics ::crevice::internal::bytemuck::Pod for #generated_name #ty_generics #where_clause {}
258+
unsafe impl #impl_generics #bevy_crevice_path::internal::bytemuck::Zeroable for #generated_name #ty_generics #where_clause {}
259+
unsafe impl #impl_generics #bevy_crevice_path::internal::bytemuck::Pod for #generated_name #ty_generics #where_clause {}
258260

259261
unsafe impl #impl_generics #mod_path::#trait_name for #generated_name #ty_generics #where_clause {
260262
const ALIGNMENT: usize = #struct_alignment;
261263
const PAD_AT_END: bool = true;
262-
type Padded = #padded_path<Self, {::crevice::internal::align_offset(
264+
type Padded = #padded_path<Self, {#bevy_crevice_path::internal::align_offset(
263265
::core::mem::size_of::<#generated_name>(),
264266
#struct_alignment
265267
)}>;
@@ -272,7 +274,7 @@ pub fn emit(
272274
Self::Output {
273275
#generated_struct_field_init
274276

275-
..::crevice::internal::bytemuck::Zeroable::zeroed()
277+
..#bevy_crevice_path::internal::bytemuck::Zeroable::zeroed()
276278
}
277279
}
278280

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
mod glsl;
2+
mod layout;
3+
4+
use bevy_macro_utils::BevyManifest;
5+
use proc_macro::TokenStream as CompilerTokenStream;
6+
7+
use syn::{parse_macro_input, DeriveInput, Path};
8+
9+
#[proc_macro_derive(AsStd140)]
10+
pub fn derive_as_std140(input: CompilerTokenStream) -> CompilerTokenStream {
11+
let input = parse_macro_input!(input as DeriveInput);
12+
let expanded = layout::emit(input, "Std140", "std140", 16);
13+
14+
CompilerTokenStream::from(expanded)
15+
}
16+
17+
#[proc_macro_derive(AsStd430)]
18+
pub fn derive_as_std430(input: CompilerTokenStream) -> CompilerTokenStream {
19+
let input = parse_macro_input!(input as DeriveInput);
20+
let expanded = layout::emit(input, "Std430", "std430", 0);
21+
22+
CompilerTokenStream::from(expanded)
23+
}
24+
25+
#[proc_macro_derive(GlslStruct)]
26+
pub fn derive_glsl_struct(input: CompilerTokenStream) -> CompilerTokenStream {
27+
let input = parse_macro_input!(input as DeriveInput);
28+
let expanded = glsl::emit(input);
29+
30+
CompilerTokenStream::from(expanded)
31+
}
32+
33+
const BEVY: &str = "bevy";
34+
const BEVY_CREVICE: &str = "bevy_crevice";
35+
const BEVY_RENDER: &str = "bevy_render";
36+
37+
fn bevy_crevice_path() -> Path {
38+
let bevy_manifest = BevyManifest::default();
39+
bevy_manifest
40+
.maybe_get_path(crate::BEVY)
41+
.map(|bevy_path| {
42+
let mut segments = bevy_path.segments;
43+
segments.push(BevyManifest::parse_str("render"));
44+
segments.push(BevyManifest::parse_str("render_resource"));
45+
Path {
46+
leading_colon: None,
47+
segments,
48+
}
49+
})
50+
.or_else(|| bevy_manifest.maybe_get_path(crate::BEVY_RENDER))
51+
.map(|bevy_render_path| {
52+
let mut segments = bevy_render_path.segments;
53+
segments.push(BevyManifest::parse_str("render_resource"));
54+
Path {
55+
leading_colon: None,
56+
segments,
57+
}
58+
})
59+
.unwrap_or_else(|| bevy_manifest.get_path(crate::BEVY_CREVICE))
60+
}

crates/crevice/crevice-tests/Cargo.toml renamed to crates/bevy_crevice/crevice-tests/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ edition = "2018"
77
wgpu-validation = ["wgpu", "naga", "futures"]
88

99
[dependencies]
10-
crevice = { path = ".." }
11-
crevice-derive = { path = "../crevice-derive", features = ["debug-methods"] }
10+
bevy_crevice = { path = ".." }
11+
bevy-crevice-derive = { path = "../bevy-crevice-derive", features = ["debug-methods"] }
1212

1313
anyhow = "1.0.44"
1414
bytemuck = "1.7.2"

crates/crevice/crevice-tests/src/gpu.rs renamed to crates/bevy_crevice/crevice-tests/src/gpu.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use std::borrow::Cow;
22
use std::fmt::Debug;
33
use std::marker::PhantomData;
44

5-
use crevice::glsl::{Glsl, GlslStruct};
6-
use crevice::std140::{AsStd140, Std140};
7-
use crevice::std430::{AsStd430, Std430};
5+
use bevy_crevice::glsl::{Glsl, GlslStruct};
6+
use bevy_crevice::std140::{AsStd140, Std140};
7+
use bevy_crevice::std430::{AsStd430, Std430};
88
use futures::executor::block_on;
99
use wgpu::util::DeviceExt;
1010

crates/crevice/crevice-tests/src/lib.rs renamed to crates/bevy_crevice/crevice-tests/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ fn test_round_trip_primitive<T>(_value: T) {}
1515
#[macro_use]
1616
mod util;
1717

18-
use crevice::glsl::GlslStruct;
19-
use crevice::std140::AsStd140;
20-
use crevice::std430::AsStd430;
18+
use bevy_crevice::glsl::GlslStruct;
19+
use bevy_crevice::std140::AsStd140;
20+
use bevy_crevice::std430::AsStd430;
2121
use mint::{ColumnMatrix2, ColumnMatrix3, ColumnMatrix4, Vector2, Vector3, Vector4};
2222

2323
#[test]

crates/crevice/src/glsl.rs renamed to crates/bevy_crevice/src/glsl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Defines traits and types for generating GLSL code from Rust definitions.
22
3-
pub use crevice_derive::GlslStruct;
3+
pub use bevy_crevice_derive::GlslStruct;
44
use std::marker::PhantomData;
55

66
/// Type-level linked list of array dimensions
File renamed without changes.
File renamed without changes.

crates/crevice/src/lib.rs renamed to crates/bevy_crevice/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ uniform MAIN {
5656
```
5757
5858
```rust
59-
use crevice::std140::{AsStd140, Std140};
59+
use bevy_crevice::std140::{AsStd140, Std140};
6060
6161
#[derive(AsStd140)]
6262
struct MainUniform {
@@ -100,7 +100,7 @@ buffer POINT_LIGHTS {
100100
```
101101
102102
```rust
103-
use crevice::std140::{self, AsStd140};
103+
use bevy_crevice::std140::{self, AsStd140};
104104
105105
#[derive(AsStd140)]
106106
struct PointLight {

crates/crevice/src/std140.rs renamed to crates/bevy_crevice/src/std140.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ pub use self::traits::*;
1515
#[cfg(feature = "std")]
1616
pub use self::writer::*;
1717

18-
pub use crevice_derive::AsStd140;
18+
pub use bevy_crevice_derive::AsStd140;

crates/crevice/src/std140/sizer.rs renamed to crates/bevy_crevice/src/std140/sizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ buffer FROBS {
2525
```
2626
2727
```
28-
use crevice::std140::{self, AsStd140};
28+
use bevy_crevice::std140::{self, AsStd140};
2929
3030
#[derive(AsStd140)]
3131
struct Frob {

crates/crevice/src/std140/traits.rs renamed to crates/bevy_crevice/src/std140/traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ uniform CAMERA {
8989
```
9090
9191
```no_run
92-
use crevice::std140::{AsStd140, Std140};
92+
use bevy_crevice::std140::{AsStd140, Std140};
9393
9494
#[derive(AsStd140)]
9595
struct CameraUniform {

crates/crevice/src/std140/writer.rs renamed to crates/bevy_crevice/src/std140/writer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ buffer POINT_LIGHTS {
3232
```
3333
3434
```
35-
use crevice::std140::{self, AsStd140};
35+
use bevy_crevice::std140::{self, AsStd140};
3636
3737
#[derive(AsStd140)]
3838
struct PointLight {

crates/crevice/src/std430.rs renamed to crates/bevy_crevice/src/std430.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ pub use self::traits::*;
1313
#[cfg(feature = "std")]
1414
pub use self::writer::*;
1515

16-
pub use crevice_derive::AsStd430;
16+
pub use bevy_crevice_derive::AsStd430;

crates/crevice/src/std430/sizer.rs renamed to crates/bevy_crevice/src/std430/sizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ buffer FROBS {
2525
```
2626
2727
```
28-
use crevice::std430::{self, AsStd430};
28+
use bevy_crevice::std430::{self, AsStd430};
2929
3030
#[derive(AsStd430)]
3131
struct Frob {

crates/crevice/src/std430/traits.rs renamed to crates/bevy_crevice/src/std430/traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ uniform CAMERA {
8989
```
9090
9191
```no_run
92-
use crevice::std430::{AsStd430, Std430};
92+
use bevy_crevice::std430::{AsStd430, Std430};
9393
9494
#[derive(AsStd430)]
9595
struct CameraUniform {

0 commit comments

Comments
 (0)