Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ jobs:
- run: cargo build --verbose
- run: cargo build --verbose --target wasm32-unknown-unknown
env:
RUSTFLAGS: --cfg=web_sys_unstable_apis
RUSTFLAGS: --cfg=web_sys_unstable_apis
- run: cargo build --verbose --no-default-features
- run: cargo build --verbose --target wasm32-unknown-unknown --no-default-features
env:
RUSTFLAGS: --cfg=web_sys_unstable_apis
- run: cargo test --verbose
- run: (cd examples/hello && cargo build --features glutin_winit)
- run: (cd examples/hello && cargo build --target wasm32-unknown-unknown)
Expand Down
33 changes: 26 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,47 @@ targets = [
"x86_64-pc-windows-msvc",
"i686-unknown-linux-gnu",
"i686-pc-windows-msvc",
"wasm32-unknown-unknown"
"wasm32-unknown-unknown",
]

[lib]
name = "glow"
path = "src/lib.rs"

[dependencies]
log = { version = "0.4.16", optional = true }
log = { version = "0.4.16", optional = true, default-features = false }

[features]
default = ["std"]
std = [
"log/std",
"wasm_bindgen/std",
"web_sys/std",
"js_sys/std",
"slotmap/std",
]
debug_trace_calls = []
debug_automatic_glGetError = []

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = "~0.3"
wasm-bindgen = "~0.2"
slotmap = "1"
[target.'cfg(target_arch = "wasm32")'.dependencies.js_sys]
version = "~0.3"
package = "js-sys"
default-features = false

[target.'cfg(target_arch = "wasm32")'.dependencies.wasm_bindgen]
version = "~0.2"
package = "wasm-bindgen"
default-features = false

[target.'cfg(target_arch = "wasm32")'.dependencies.slotmap]
version = "1"
package = "slotmap"
default-features = false

[target.'cfg(target_arch = "wasm32")'.dependencies.web_sys]
version = "~0.3.60"
version = "~0.3.77"
package = "web-sys"
default-features = false
features = [
"Document",
"Element",
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@ cargo build
cargo build --target wasm32-unknown-unknown
```

## `no_std` support

`no_std` support can be enabled by compiling with `--no-default-features` to
disable `std` support. For example:

```toml
[dependencies]
glow = { version = "0.16", default-features = false }
```

To support both `std` and `no_std` builds in project, you can use the following
in your `Cargo.toml`:

```toml
[features]
default = ["std", "other features"]

std = ["glow/std"]
other_features = []

[dependencies]
glow = { version = "0.16", default-features = false }
```

## License

This project is licensed under any one of [Apache License, Version
Expand Down
5 changes: 4 additions & 1 deletion examples/hello/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[cfg(any(target_arch = "wasm32", feature = "glutin_winit", feature = "sdl2"))]
use glow::*;

fn main() {
#[cfg(any(target_arch = "wasm32", feature = "glutin_winit", feature = "sdl2"))]
unsafe {
// Create a context from a WebGL2 context on wasm32 targets
#[cfg(target_arch = "wasm32")]
Expand All @@ -27,6 +29,8 @@ fn main() {
// Create a context from a glutin window on non-wasm32 targets
#[cfg(feature = "glutin_winit")]
let (gl, gl_surface, gl_context, shader_version, _window, event_loop) = {
use core::num::NonZeroU32;

use glutin::{
config::{ConfigTemplateBuilder, GlConfig},
context::{ContextApi, ContextAttributesBuilder, NotCurrentGlContext},
Expand All @@ -35,7 +39,6 @@ fn main() {
};
use glutin_winit::{DisplayBuilder, GlWindow};
use raw_window_handle::HasRawWindowHandle;
use std::num::NonZeroU32;

let event_loop = winit::event_loop::EventLoopBuilder::new().build().unwrap();
let window_builder = winit::window::WindowBuilder::new()
Expand Down
Loading