{"id":20410893,"url":"https://github.com/mintlu8/wgsl_ln","last_synced_at":"2025-04-12T16:05:06.361Z","repository":{"id":247728796,"uuid":"826646262","full_name":"mintlu8/wgsl_ln","owner":"mintlu8","description":"Compile time wgsl import, linking and checking.","archived":false,"fork":false,"pushed_at":"2024-07-13T11:20:19.000Z","size":21,"stargazers_count":19,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-31T11:56:36.501Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mintlu8.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-10T05:34:50.000Z","updated_at":"2024-10-16T10:14:09.000Z","dependencies_parsed_at":"2024-07-10T09:33:14.176Z","dependency_job_id":null,"html_url":"https://github.com/mintlu8/wgsl_ln","commit_stats":null,"previous_names":["mintlu8/wgsl_ln"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mintlu8%2Fwgsl_ln","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mintlu8%2Fwgsl_ln/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mintlu8%2Fwgsl_ln/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mintlu8%2Fwgsl_ln/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mintlu8","download_url":"https://codeload.github.com/mintlu8/wgsl_ln/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224737131,"owners_count":17361345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T05:48:59.502Z","updated_at":"2024-11-15T05:49:00.281Z","avatar_url":"https://github.com/mintlu8.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wgsl_ln\n\n[![Crates.io](https://img.shields.io/crates/v/wgsl_ln.svg)](https://crates.io/crates/wgsl_ln)\n[![Docs](https://docs.rs/wgsl_ln/badge.svg)](https://docs.rs/wgsl_ln/latest/wgsl_ln/)\n\nExperimental crate for writing wgsl in rust!\n\n## The `wgsl!` macro\n\nThe `wgsl!` macro converts normal rust tokens into a wgsl `\u0026'static str`, similar to `stringify!`.\nThis also validates the wgsl string using `naga`. Errors will be reported with\nthe correct span.\n\n```rust\npub static MANHATTAN_DISTANCE: \u0026str = wgsl!(\n    fn manhattan_distance(a: vec2\u003cf32\u003e, b: vec2\u003cf32\u003e) -\u003e f32 {\n        return abs(a.x - b.x) + abs(a.y - b.y);\n    }\n);\n```\n\nMost errors can be caught at compile time.\n\n```rust\npub static MANHATTAN_DISTANCE: \u0026str = wgsl!(\n    fn manhattan_distance(a: vec2\u003cf32\u003e, b: vec2\u003cf32\u003e) -\u003e f32 {\n        // not allowed in wgsl\n        abs(a.x - b.x) + abs(a.y - b.y)\n    }\n);\n```\n\n## The `#[wgsl_export(name)]` macro\n\nExport a wgsl item (function, struct, etc)\nvia `wgsl_export`. Must have the same `name` as the exported item.\n\n```rust\n#[wgsl_export(manhattan_distance)]\npub static MANHATTAN_DISTANCE: \u0026str = wgsl!(\n    fn manhattan_distance(a: vec2\u003cf32\u003e, b: vec2\u003cf32\u003e) -\u003e f32 {\n        return abs(a.x - b.x) + abs(a.y - b.y);\n    }\n);\n```\n\n## Using an exported item\n\n```rust\npub static MANHATTAN_DISTANCE_TIMES_FIVE: \u0026str = wgsl!(\n    fn manhattan_distance_times_five(a: vec2\u003cf32\u003e, b: vec2\u003cf32\u003e) -\u003e f32 {\n        return #manhattan_distance(a, b) * 5.0;\n    }\n);\n```\n\n`#manhattan_distance` copies the `manhattan_distance` function into the module,\nmaking it usable. You can specify multiple instances of `#manhattan_distance`\nor omit the `#` in later usages.\n\n## Ok what's actually going on?\n\n`wgsl_export` creates a `macro_rules!` macro that pastes itself into the `wgsl!` macro.\nThe macro is `#[doc(hidden)]` and available in the crate root,\ni.e. `crate::__wgsl_paste_manhattan_distance!`.\n\nYou don't need to import anything to use items defined in your crate, for other crates,\nyou might want to blanket import the crate root.\n\n```rust\nmod my_shaders {\n    pub use external_shader_defs::*;\n\n    pub static MAGIC: \u0026str = wgsl!(\n        fn magic() -\u003e f32 {\n            return #magic_number();\n        }\n    )\n}\npub use my_shaders::MAGIC;\n```\n\n## `naga_oil` support\n\nEnable the `naga_oil` feature to enable limited `naga_oil` support:\n\n* Treat `#preprocessor_macro_name` as tokens instead of imports.\n  * `#define_import_path`\n  * `#import`\n  * `#if`\n  * `#ifdef`\n  * `#ifndef`\n  * `#else`\n  * `#endif`\n\nThese values can no longer be imported.\n\n* Checks will be disabled when naga_oil preprocessor macros are detected.\n\n## License\n\nLicense under either of\n\nApache License, Version 2.0 (LICENSE-APACHE or \u003chttp://www.apache.org/licenses/LICENSE-2.0\u003e)\nMIT license (LICENSE-MIT or \u003chttp://opensource.org/licenses/MIT\u003e)\nat your option.\n\n## Contribution\n\nContributions are welcome!\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmintlu8%2Fwgsl_ln","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmintlu8%2Fwgsl_ln","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmintlu8%2Fwgsl_ln/lists"}