Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple glutin from winit #1435

Merged
merged 8 commits into from
Sep 3, 2022
Merged
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
3 changes: 0 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
- [ ] Tested on all platforms changed
- [ ] Compilation warnings were addressed
- [ ] `cargo fmt` has been run on this branch
- [ ] `cargo doc` builds successfully
- [ ] Added an entry to `CHANGELOG.md` if knowledge of this change could be valuable to users
- [ ] Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
- [ ] Created or updated an example program if it would help users understand this functionality
86 changes: 29 additions & 57 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
- uses: actions/checkout@v1
- uses: hecrj/setup-rust-action@v1
with:
rust-version: stable
rust-version: nightly
components: rustfmt
- name: Check Formatting
run: cargo +stable fmt --all -- --check
run: cargo +nightly fmt --all -- --check
kchibisov marked this conversation as resolved.
Show resolved Hide resolved

tests:
name: Tests
Expand All @@ -35,30 +35,27 @@ jobs:
platform:
- { target: x86_64-pc-windows-msvc, os: windows-latest, }
- { target: i686-pc-windows-msvc, os: windows-latest, }
- { target: i686-pc-windows-msvc, os: windows-latest, options: --no-default-features, features: wgl }
- { target: i686-pc-windows-msvc, os: windows-latest, options: --no-default-features, features: egl }
- { target: x86_64-pc-windows-gnu, os: windows-latest, host: -x86_64-pc-windows-gnu }
- { target: i686-pc-windows-gnu, os: windows-latest, host: -i686-pc-windows-gnu }
- { target: i686-unknown-linux-gnu, os: ubuntu-latest, }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest, }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest, options: --no-default-features, features: x11 }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest, options: --no-default-features, features: wayland }
- { target: aarch64-linux-android, os: ubuntu-latest, }
- { target: arm-linux-androideabi, os: ubuntu-latest, }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest, options: --no-default-features, features: "egl,wayland,x11" }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest, options: --no-default-features, features: glx }
- { target: aarch64-linux-android, os: ubuntu-latest, cmd: 'apk --' }
- { target: x86_64-apple-darwin, os: macos-latest, }
- { target: x86_64-apple-ios, os: macos-latest, }
- { target: aarch64-apple-ios, os: macos-latest, }
# We're using Windows rather than Ubuntu to run the wasm tests because caching cargo-web
# doesn't currently work on Linux.
#- { target: wasm32-unknown-unknown, os: windows-latest, features: stdweb, web: web }
#- { target: wasm32-unknown-unknown, os: windows-latest, features: web-sys, web: web }
# We don't support ios for now.
# - { target: x86_64-apple-ios, os: macos-latest, }
# - { target: aarch64-apple-ios, os: macos-latest, }

env:
RUST_BACKTRACE: 1
CARGO_INCREMENTAL: 0
PKG_CONFIG_ALLOW_CROSS: 1
RUSTFLAGS: "-C debuginfo=0"
OPTIONS: ${{ matrix.platform.options }}
CMD: ${{ matrix.platform.cmd }}
FEATURES: ${{ format(',{0}', matrix.platform.features ) }}
WEB: ${{ matrix.platform.web }}
RUSTDOCFLAGS: -Dwarnings

runs-on: ${{ matrix.platform.os }}
Expand All @@ -82,58 +79,33 @@ jobs:
# "Temporary" workaround until https://github.com/actions/virtual-environments/issues/5879#issuecomment-1195156618
# gets looked into.
run: echo "ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME" >> $GITHUB_ENV
- name: Install Linux dependencies
if: (matrix.platform.os == 'ubuntu-latest')
run: sudo apt-get update && sudo apt-get install pkg-config cmake libfreetype6-dev libfontconfig1-dev libxkbcommon-dev
# We need those for examples.

- name: Install GCC Multilib
if: (matrix.platform.os == 'ubuntu-latest') && contains(matrix.platform.target, 'i686')
run: sudo dpkg --add-architecture i386 && sudo apt-get update && sudo apt-get install g++-multilib gcc-multilib libfreetype6-dev:i386 libfontconfig1-dev:i386 libxkbcommon-dev:i386
- name: Install cargo-web
continue-on-error: true
if: contains(matrix.platform.target, 'wasm32')
run: cargo install cargo-web

- name: Check documentation
shell: bash
if: matrix.platform.target != 'wasm32-unknown-unknown'
run: cd glutin && cargo doc --no-deps --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES --document-private-items

- name: Lint with clippy
shell: bash
if: matrix.rust_version == '1.57.0'
run: cargo clippy --workspace --all-targets --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES -- -Dwarnings
run: sudo apt-get update && sudo apt-get install gcc-multilib

- name: Build glutin
shell: bash
run: cd glutin && cargo $WEB build --verbose --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES
- name: Build all
shell: bash
if: (!contains(matrix.platform.target, 'wasm32'))
run: cargo $WEB build --verbose --target ${{ matrix.platform.target }}
- name: Install cargo-apk
if: contains(matrix.platform.target, 'android')
run: cargo install cargo-apk

- name: Build tests
shell: bash
if: (!contains(matrix.platform.target, 'android'))
run: cd glutin && cargo $WEB test --no-run --verbose --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES
- name: Build tests all
shell: bash
if: (!contains(matrix.platform.target, 'android') && !contains(matrix.platform.target, 'wasm32'))
run: cargo $WEB test --no-run --verbose --target ${{ matrix.platform.target }}
run: cargo $CMD test -p glutin --no-run --verbose --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES
- name: Run tests
shell: bash
if: (!contains(matrix.platform.target, 'ios') && !contains(matrix.platform.target, 'android') && !contains(matrix.platform.target, 'wasm32'))
run: cd glutin && cargo $WEB test --verbose --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES
if: (
!contains(matrix.platform.target, 'android') &&
!contains(matrix.platform.target, 'ios') &&
!contains(matrix.platform.target, 'wasm32'))
run: cargo $CMD test --verbose --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES

- name: Build with serde enabled
- name: Check documentation
shell: bash
if: (!contains(matrix.platform.target, 'android'))
run: cd glutin && cargo $WEB build --verbose --target ${{ matrix.platform.target }} $OPTIONS --features serde,$FEATURES
run: cd glutin && cargo $CMD doc --no-deps --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES --document-private-items

- name: Build tests with serde enabled
shell: bash
if: (!contains(matrix.platform.target, 'android'))
run: cd glutin && cargo $WEB test --no-run --verbose --target ${{ matrix.platform.target }} $OPTIONS --features serde,$FEATURES
- name: Run tests with serde enabled
- name: Lint with clippy
shell: bash
if: (!contains(matrix.platform.target, 'ios') && !contains(matrix.platform.target, 'android') && !contains(matrix.platform.target, 'wasm32'))
run: cd glutin && cargo $WEB test --verbose --target ${{ matrix.platform.target }} $OPTIONS --features serde,$FEATURES
if: (matrix.rust_version == '1.57.0') && !contains(matrix.platform.options, '--no-default-features')
run: cargo clippy --workspace --all-targets --target ${{ matrix.platform.target }} $OPTIONS --features $FEATURES -- -Dwarnings

7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Unreleased

- Replace `winit` dependency with `raw-window-handle`.
- The Api is now built around `Display`, `Surface`, `Config`, and `Surface` for more info see crate documentation and examples.
- The ios support was removed for the lack of maintainance for now. In case there's a need for it, contributions are welcome.
- The context creation is no longer limited to winit's supported platforms.
- The underlying Api providers are publically exposed now, so glutin could be used with just e.g. `EGL`.
- Fixed soundness issues with `Surface` MT safety, since before `EGLSurface` could be sent to a different thread, which is not safe.

# Version 0.29.1 (2022-08-10)

- Fix build failures when building from crates.io
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
members = [
"glutin",
"glutin_examples",
"glutin_examples/ios-example/rust",
"glutin_egl_sys",
"glutin_glx_sys",
"glutin_wgl_sys",
Expand Down
43 changes: 0 additions & 43 deletions ISSUES.md

This file was deleted.

29 changes: 11 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# glutin - OpenGL, UTilities and INput
A low-level library for OpenGL context creation, written in pure Rust.

A low-level library for OpenGL context creation.

[![](https://img.shields.io/crates/v/glutin.svg)](https://crates.io/crates/glutin)
[![Docs.rs](https://docs.rs/glutin/badge.svg)](https://docs.rs/glutin)
Expand All @@ -20,10 +21,11 @@ Join us in any of these:

## Usage Examples

Warning: these are examples for master. For the latest released version you can
**Warning:** these are examples for master. For the latest released version you can
find them [here](https://github.com/rust-windowing/glutin/releases/tag/v0.29.1).

The examples use [gl_generator](https://crates.io/crates/gl_generator) to generate OpenGL bindings.
The examples use [gl_generator](https://crates.io/crates/gl_generator) to
generate OpenGL bindings.

### Try it!

Expand All @@ -33,19 +35,18 @@ cd glutin
cargo run --example window
```

## Common issues

Please refer to [ISSUES.md.](ISSUES.md)

### Usage

Glutin is an OpenGL context creation library and doesn't directly provide OpenGL bindings for you.
Glutin is an OpenGL context creation library and doesn't directly provide
OpenGL bindings for you.

For examples, please look [here.](https://github.com/rust-windowing/glutin/tree/master/glutin_examples)

Note that glutin aims at being a low-level brick in your rendering infrastructure. You are encouraged to write another layer of abstraction between glutin and your application.
Note that glutin aims at being a low-level brick in your rendering
infrastructure. You are encouraged to write another layer of abstraction
between glutin and your application.

Glutin is only officially supported on the latest stable version of the Rust compiler.
The minimum rust version target by glutin is `1.57.0`.

## Platform-specific notes

Expand All @@ -54,11 +55,3 @@ Glutin is only officially supported on the latest stable version of the Rust com
To compile the examples for android, you have to use the `cargo apk` utility.

See [`cargo-apk` in the `android-ndk-rs` repository](https://github.com/rust-windowing/android-ndk-rs/tree/master/cargo-apk) for instructions.

### X11

The plan is that glutin tries to dynamically link-to and use Wayland w/EGL if possible. If it doesn't work, it will try Xlib w/GLX follow by Xlib w/EGL instead. This is work-in-progress.

### Wayland

Due to an issue with how Mesa and Wayland play together, all shared contexts must use the same events pool as each other.
79 changes: 35 additions & 44 deletions glutin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,57 @@ name = "glutin"
version = "0.29.1"
authors = ["The glutin contributors", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "Cross-platform OpenGL context provider."
keywords = ["windowing", "opengl"]
keywords = ["windowing", "opengl", "egl", "glx", "wgl", "cgl"]
license = "Apache-2.0"
readme = "../README.md"
repository = "https://github.com/rust-windowing/glutin"
documentation = "https://docs.rs/glutin"
rust-version = "1.57.0"
edition = "2021"
rust-version = "1.57"

[package.metadata.docs.rs]
features = ["serde"]

[features]
default = ["x11", "wayland", "wayland-dlopen", "wayland-csd-adwaita"]
serde = ["winit/serde"]
x11 = ["winit/x11", "glutin_glx_sys"]
wayland = ["winit/wayland", "wayland-client", "wayland-egl"]
wayland-dlopen = ["winit/wayland-dlopen"]
wayland-csd-adwaita = ["winit/wayland-csd-adwaita"]
wayland-csd-adwaita-notitle = ["winit/wayland-csd-adwaita-notitle"]
default = ["egl", "glx", "x11", "wayland", "wgl"]
egl = ["glutin_egl_sys", "libloading"]
glx = ["x11", "x11-dl", "glutin_glx_sys", "libloading"]
wgl = ["glutin_wgl_sys", "windows-sys"]
x11 = ["x11-dl"]
wayland = ["wayland-sys"]

[dependencies]
bitflags = "1.3.2"
libloading = { version = "0.7.3", optional = true }
once_cell = "1.13"
winit = { version = "0.27.1", default-features = false }

[target.'cfg(target_os = "android")'.dependencies]
glutin_egl_sys = { version = "0.1.6", path = "../glutin_egl_sys" }
libloading = "0.7"
parking_lot = "0.12"
raw-window-handle = "0.5"

[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
objc = "0.2.6"
glutin_gles2_sys = { version = "0.1.5", path = "../glutin_gles2_sys" }
raw-window-handle = "0.5.0"

[target.'cfg(target_os = "macos")'.dependencies]
cgl = "0.3"
cocoa = "0.24"
core-foundation = "0.9"
[target.'cfg(target_os = "windows")'.dependencies]
glutin_egl_sys = { version = "0.1.6", path = "../glutin_egl_sys", optional = true }
glutin_wgl_sys = { version = "0.1.5", path = "../glutin_wgl_sys", optional = true }

[target.'cfg(target_os = "windows")'.dependencies.winapi]
version = "0.3"
[target.'cfg(target_os = "windows")'.dependencies.windows-sys]
version = "0.36"
features = [
"winnt",
"winuser",
"wingdi",
"libloaderapi",
"Win32_Foundation",
"Win32_Graphics_Gdi",
"Win32_Graphics_OpenGL",
"Win32_System_LibraryLoader",
"Win32_UI_WindowsAndMessaging",
]
optional = true

[target.'cfg(target_os = "windows")'.dependencies]
libloading = "0.7"
glutin_wgl_sys = { version = "0.1.5", path = "../glutin_wgl_sys" }
[target.'cfg(target_os = "android")'.dependencies]
glutin_egl_sys = { version = "0.1.6", path = "../glutin_egl_sys" }
parking_lot = "0.12"

[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "netbsd", target_os = "openbsd"))'.dependencies]
osmesa-sys = "0.1"
wayland-client = { version = "0.29.4", features = ["dlopen"], optional = true }
wayland-egl = { version = "0.29.4", optional = true }
libloading = "0.7"
glutin_egl_sys = { version = "0.1.6", path = "../glutin_egl_sys" }
glutin_egl_sys = { version = "0.1.6", path = "../glutin_egl_sys", optional = true }
glutin_glx_sys = { version = "0.1.8", path = "../glutin_glx_sys", optional = true }
parking_lot = "0.12"
log = "0.4"
wayland-sys = { version = "0.30.0-beta.8", default-features = false, features = ["egl", "client", "dlopen"], optional = true }
x11-dl = { version = "2.20.0", optional = true }

[target.'cfg(any(target_os = "macos"))'.dependencies]
cgl = "0.3.2"
cocoa = "0.24.0"
core-foundation = "0.9.3"
objc = "0.2.7"

[build-dependencies]
cfg_aliases = "0.1.1"
24 changes: 24 additions & 0 deletions glutin/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use cfg_aliases::cfg_aliases;

fn main() {
// Setup alias to reduce `cfg` boilerplate.
cfg_aliases! {
// Systems.
android: { target_os = "android" },
wasm: { target_arch = "wasm32" },
macos: { target_os = "macos" },
ios: { target_os = "ios" },
apple: { any(target_os = "ios", target_os = "macos") },
free_unix: { all(unix, not(apple), not(android)) },

// Native displays.
x11_platform: { all(feature = "x11", free_unix, not(wasm)) },
wayland_platform: { all(feature = "wayland", free_unix, not(wasm)) },

// Backends.
egl_backend: { all(feature = "egl", any(windows, unix), not(apple), not(wasm)) },
glx_backend: { all(feature = "glx", x11_platform, not(wasm)) },
wgl_backend: { all(feature = "wgl", windows, not(wasm)) },
cgl_backend: { all(macos, not(wasm)) },
}
}
Loading