Skip to content

Commit

Permalink
Merge pull request #190 from raylib-rs/master
Browse files Browse the repository at this point in the history
Sync with delta
  • Loading branch information
Dacode45 authored May 19, 2024
2 parents 60c20e6 + 2b9533c commit 2ce9836
Show file tree
Hide file tree
Showing 169 changed files with 22,157 additions and 91,920 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: CI

on:
pull_request:
push:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ubuntu-latest-cargo-build-stable-${{ hashFiles('**/Cargo.toml') }}
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Setup git submodules
run: git submodule init; git submodule update
- name: Install alsa, udev, glfw3, sdl, and wayland
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libglfw3-dev libwayland-dev libsdl2-dev
- name: Run doc tests with all features (this also compiles README examples)
run: cargo test --doc --all-features
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ubuntu-latest-cargo-build-stable-${{ hashFiles('**/Cargo.toml') }}
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
override: true
- name: Setup git submodules
run: git submodule init; git submodule update
- name: Install alsa, udev, glfw3, sdl, and wayland
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libglfw3-dev libwayland-dev libsdl2-dev
- name: Run clippy
run: cargo clippy --workspace --all-targets --all-features
- name: Check format
run: cargo fmt --all -- --check
14 changes: 8 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Build
run: cd raylib && cargo build --verbose --features nobuild
- uses: actions/checkout@v1
- name: Setup git submodules
run: git submodule init; git submodule update
- name: Install alsa, udev, glfw3, sdl, and wayland
run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev libglfw3-dev libwayland-dev libsdl2-dev
- name: Build
run: cd raylib && cargo build --verbose
# - name: Run tests [Requires window system]
# run: cargo test -p raylib-test --verbose
# run: cargo test -p raylib-test --verbose
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "raylib-sys/raylib"]
path = raylib-sys/raylib
url = https://github.com/raysan5/raylib
branch = "5.0"
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[workspace]
members = ["raylib", "raylib-sys", "raylib-test", "samples", "showcase"]
members = ["raylib", "raylib-sys"]
exclude = ["raylib-test"]
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
![logo](logo/raylib-rust_256x256.png)

![rust](https://img.shields.io/badge/rust-1.31+-orange.svg?style=flat-square&logo=rust)
<p align="center">
![rust](https://img.shields.io/badge/rust-1.77+-orange.svg?style=flat-square&logo=rust)
[![crates.io](https://img.shields.io/crates/v/raylib.svg?style=flat-square)](https://crates.io/crates/raylib)
[![docs](https://docs.rs/raylib/badge.svg)](https://docs.rs/raylib)
[discord](https://discord.gg/VkzNHUE)
[![discord](https://img.shields.io/discord/426912293134270465)](https://discord.gg/VkzNHUE)

</p>

# NOTE 4.x version in progress.
<table border="0">
<tr>
<td>

Raylib 4.2 is currently a work in progress. In the meantime you can use a fork: https://github.com/bitten2up/raylib-rs
![logo](logo/raylib-rust_256x256.png)

Add this to your Cargo.toml
```toml
[dependencies.raylib]
version = "5.0.0"
git = "https://github.com/bitten2up/raylib-rs"
branch = "5.0.0"
```
</td>
<td>

# raylib-rs

raylib-rs is a Rust binding for [raylib](http://www.raylib.com/) 3.5. It currently targets the _stable_ Rust toolchain, version 1.31 or higher.
raylib-rs is a Rust binding for [raylib](http://www.raylib.com/) 5.0. It currently targets the _stable_ Rust toolchain, version 1.77 or higher.

Please checkout the showcase directory to find usage examples!

Though this binding tries to stay close to the simple C API, it makes some changes to be more idiomatic for Rust.

</td>
</tr>
</table>


- Resources are automatically cleaned up when they go out of scope (or when `std::mem::drop` is called). This is essentially RAII. This means that "Unload" functions are not exposed (and not necessary unless you obtain a `Weak` resource using make_weak()).
- Most of the Raylib API is exposed through `RaylibHandle`, which is for enforcing that Raylib is only initialized once, and for making sure the window is closed properly. RaylibHandle has no size and goes away at compile time. Because of mutability rules, Raylib-rs is thread safe!
- A `RaylibHandle` and `RaylibThread` are obtained through `raylib::init_window(...)` or through the newer `init()` function which will allow you to `build` up some window options before initialization (replaces `set_config_flags`). RaylibThread should not be sent to any other threads, or used in a any syncronization primitives (Mutex, Arc) etc.
Expand All @@ -34,18 +37,16 @@ Though this binding tries to stay close to the simple C API, it makes some chang
- `Font::from_data`, `Font::set_chars`, and `Font::set_texture` methods were added to create a `Font` from loaded `CharInfo` data.
- `SubText` and `FormatText` are omitted, and are instead covered by Rust's string slicing and Rust's `format!` macro, respectively.

**Disclaimer: I created this binding as a way to learn Rust. There may be some things I can do better, or make more ergonomic for users. Feel free to make suggestions!**

# Installation

## Supported Platforms

| API | Windows | Linux | macOS | Web | Android | Raspberry Pi |
| ------ | ------------------ | ------------------ | ------------------ | -------------- | ------- | ------------ |
| core | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :construction: | | |
| rgui | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | | |
| physac | :construction: | :construction: | :construction: | | | |
| rlgl | :heavy_check_mark: | :x: | :x: | | | |
| API | Windows | Linux | macOS | Web | Android |
| ------ | ------------------ | ------------------ | ------------------ | -------------- | ------- |
| core | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x: |
| rgui | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | | :x: |
| physac | :construction: | :construction: | :construction: | | :x: |
| rlgl | :heavy_check_mark: | :x: | :x: | | :x: |

## Build Dependencies

Expand All @@ -56,7 +57,7 @@ Follow instructions for building raylib for your platform [here](https://github.

```toml
[dependencies]
raylib = { version = "3.7" }
raylib = { version = "5.0" }
```

2. Start coding!
Expand All @@ -81,10 +82,11 @@ fn main() {

# Tech Notes

- Structs holding resources have RAII/move semantics, including: `Image`, `Texture2D`, `RenderTexture2D`, `Font`, `Mesh`, `Shader`, `Material`, `Model`, `Wave`, `Sound`, `Music`, and `AudioStream`.
- Structs holding resources have RAII/move semantics, including: `Image`, `Texture2D`, `RenderTexture2D`, `Font`, `Mesh`, `Shader`, `Material`, and `Model`.
- `Wave`, `Sound`, `Music`, and `AudioStream` have lifetimes bound to `AudioHandle`.
- Functions dealing with string data take in `&str` and/or return an owned `String`, for the sake of safety. The exception to this is the gui draw functions which take &CStr to avoid per frame allocations. The `rstr!` macro helps make this easy.
- In C, `LoadFontData` returns a pointer to a heap-allocated array of `CharInfo` structs. In this Rust binding, said array is copied into an owned `Vec<CharInfo>`, the original data is freed, and the owned Vec is returned.
- In C, `GetDroppedFiles` returns a pointer to an array of strings owned by raylib. Again, for safety and also ease of use, this binding copies said array into a `Vec<String>` which is returned to the caller.
- In C, `LoadDroppedFiles` returns a pointer to an array of strings owned by raylib. Again, for safety and also ease of use, this binding copies said array into a `Vec<String>` which is returned to the caller.
- I've tried to make linking automatic, though I've only tested on Windows 10, Ubuntu, and MacOS 15. Other platforms may have other considerations.
- OpenGL 3.3, 2.1, and ES 2.0 may be forced via adding `["opengl_33"]`, `["opengl_21"]` or `["opengl_es_20]` to the `features` array in your Cargo.toml dependency definition.

Expand Down
Loading

0 comments on commit 2ce9836

Please sign in to comment.