SDL bindings for Rust

Overview

Rust-SDL

Bindings for SDL in Rust

Overview

Rust-SDL is a library for talking to SDL from Rust. Low-level C components are wrapped in Rust code to make them more idiomatic and abstract away inappropriate manual memory management.

In addition, it provides optional APIs to a number of common SDL extension libraries.

Rust-SDL uses the MIT license.

Requirements

Optional

Installation

Clone this repo, run cargo build. To see an example of the code in use, rustc -L ./target src/sdl-demo/main.rs.

SDL_mixer and SDL_image are available through separate packages, from within their respective directories, run cargo build to build. They depend on the main SDL library.

When things go wrong

Rust, and Rust-SDL, are both still heavily in development, and you may run into teething issues when using this. Before panicking, check that you're using the latest Master branch of Rust, check that you've updated Rust-SDL to the latest version, and run cargo clean. If that fails, please let us know on the issue tracker.

Comments
  • Build Failure on OSX

    Build Failure on OSX

    Trying to build on OSX-10.8.2. libSDL installed using macports.

    ./configure && make make: *** No rule to make target /usr/local/lib/libSDLmain.a', needed bylibSDLXmain.a'. Stop.

    Edited Makefile SDL_PREFIX to match where macports installed it: SDL_PREFIX ?= /usr/local/lib -> SDL_PREFIX ?= /opt/local/lib

    make rustc sdl.rc -o libsdl.dummy error: linking with cc failed with code 1 note: cc arguments: -L/usr/local/lib/rustc/x86_64-apple-darwin/lib -m64 -o libsdl-34b7eedb9132850-0.2.dylib libsdl.o -L/usr/local/lib/rustc/x86_64-apple-darwin/lib -lcore-c3ca5d77d81b46c1-0.6 -L/usr/local/lib/rustc/x86_64-apple-darwin/lib -lstd-4782a756585a81-0.6 -L. -lSDLXmain -framework AppKit -framework Foundation -lSDL -dynamiclib -Wl,-install_name,@rpath/libsdl-34b7eedb9132850-0.2.dylib -lrustrt -Wl,-no_compact_unwind -lmorestack -Wl,-rpath,@executable_path/../../../../../usr/local/lib/rustc/x86_64-apple-darwin/lib -Wl,-rpath,/usr/local/lib/rustc/x86_64-apple-darwin/lib note: ld: library not found for -lSDL clang: error: linker command failed with exit code 1 (use -v to see invocation)

    error: aborting due to previous error make: *** [libsdl.dummy] Error 101

    opened by xasmx 15
  • Fixed sdl::get_error to not segfault

    Fixed sdl::get_error to not segfault

    This one was a bit tricky as I am not sure what the initial version had tried to do. SDL_GetError() returns a constant char pointer. (char const *) However they are already in bytes. c_str_to_bytes expects a pointer to a c_str as seen here: Rust Source

    This version seems safer to me as we do not transmute, and since SDL explicitely states that those strings are fixed in memory this should not segfault.

    opened by TheNeikos 8
  • Migrate to SDL2?

    Migrate to SDL2?

    http://wiki.libsdl.org/moin.fcg/MigrationGuide

    http://lists.libsdl.org/pipermail/sdl-libsdl.org/2013-August/089854.html

    Better cross-platform support, better accelerated 2d graphics, and improvements to threading:

    There's no SDL_main! Well, okay, there is, and it now does what it was always meant to: be a small piece of code that hides the difference between main() and WinMain() on Windows. There's no initialization code in it, and it's completely optional. This means you can use SDL without it taking over your mainline, which is nice for plugins that use SDL, or scripting languages with an SDL module. All the stuff you'd want the 1.2 SDL_main for is now in SDL_Init() where it belongs.

    opened by itdaniher 6
  • Upload 0.3.6 to cargo.io

    Upload 0.3.6 to cargo.io

    The version 0.3.5 that is uploaded to crates.io is not the latest and it's not compiling with rust version 1.0.0, please upload the latest version. Also it would be nice if there are the tags and releases for the new versions

    opened by mikezaby 5
  • Demo still uses `sdl::start`

    Demo still uses `sdl::start`

    Simply removing the call to sdl::start in demo/video.rs allows the demo to be compiled, but then it fails when run:

    $ ./demo/demo
    2013-09-05 15:23:01.713 demo[54886:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error (1000) creating CGSWindow on line 259'
    *** First throw call stack:
    (
    )
    libc++abi.dylib: terminate called throwing an exception
    Abort trap: 6
    

    I'm not sure this is a related or completely different problem.

    opened by jsanders 5
  • Complete more bindings and make API follow Rust idioms

    Complete more bindings and make API follow Rust idioms

    I don't think it's necessary to prefix all the key variants with "SDLK" for example. I've experimented with a more "rusty" looking API here: https://github.com/z0w0/rust-sdl/tree/revamp

    Another example is the KeyboardEvent structs. If you take a look at how I did it, I just make one KeyEvent variant with a state boolean as to whether it was down or up, instead of both a keydown and keyup variant. I think this works nicely and gets rid of the need for an extra struct.

    Secondly, these bindings still needs a lot of work to actually have all the SDL functions mirrored. I'll do my best to add what I can.

    opened by z0w0 5
  • PlatformThread spawn mode removed

    PlatformThread spawn mode removed

    Rust removed the PlatformThread spawn mode at mozilla/rust@5d2b8d43729f3c616f0af0125f05e2cab9d0aae4. This breaks sdl/start.rs. I'll see if I can't figure out what replaced it.

    opened by itdaniher 4
  • Compiling on OS X - unresolved name std::as_c_str, std::as_buf

    Compiling on OS X - unresolved name std::as_c_str, std::as_buf

    Just cloned the master branch of rust this morning.

    $ rustc --version
    rustc 0.8-pre (4cf3072 2013-07-25 05:22:44 -0700)
    host: x86_64-apple-darwin
    

    Getting the following errors on make. I don't know enough about Rust (yet) to fix this myself, so I figured I'd throw it over the wall at you guys.

    $ make
    rustc --cfg image --cfg mixer --cfg mac_dylib src/sdl.rc -o libsdl.dummy
    src/video.rs:496:19: 496:32 error: unresolved name `str::as_c_str`.
    src/video.rs:496                 do str::as_c_str("rb") |mode_buf| {
                                        ^~~~~~~~~~~~~
    src/video.rs:495:15: 495:28 error: unresolved name `str::as_c_str`.
    src/video.rs:495             do str::as_c_str(path.to_str()) |buf| {
                                    ^~~~~~~~~~~~~
    src/video.rs:621:19: 621:32 error: unresolved name `str::as_c_str`.
    src/video.rs:621                 do str::as_c_str("wb") |mode_buf| {
                                        ^~~~~~~~~~~~~
    src/video.rs:620:15: 620:28 error: unresolved name `str::as_c_str`.
    src/video.rs:620             do str::as_c_str(path.to_str()) |buf| {
                                    ^~~~~~~~~~~~~
    src/wm.rs:38:5: 38:18 error: unresolved name `str::as_c_str`.
    src/wm.rs:38        do str::as_c_str(icon) |icon_buf| {
                           ^~~~~~~~~~~~~
    src/wm.rs:37:4: 37:17 error: unresolved name `str::as_c_str`.
    src/wm.rs:37    do str::as_c_str(title) |title_buf| {
                       ^~~~~~~~~~~~~
    src/img.rs:54:4: 54:15 error: unresolved name `str::as_buf`.
    src/img.rs:54     str::as_buf(file.to_str(), |buf, _len| {
                      ^~~~~~~~~~~
    src/mixer.rs:117:19: 117:32 error: unresolved name `str::as_c_str`.
    src/mixer.rs:117                 do str::as_c_str("rb") |mode_buf| {
                                        ^~~~~~~~~~~~~
    src/mixer.rs:116:15: 116:28 error: unresolved name `str::as_c_str`.
    src/mixer.rs:116             do str::as_c_str(path.to_str()) |buf| {
                                    ^~~~~~~~~~~~~
    src/sdl.rs:161:7: 161:20 error: unresolved name `str::as_c_str`.
    src/sdl.rs:161     do str::as_c_str(err) |buf| {
                          ^~~~~~~~~~~~~
    error: aborting due to 10 previous errors
    make: *** [libsdl.dummy] Error 101
    
    opened by rikthevik 4
  • Add support for the SDL mixer.

    Add support for the SDL mixer.

    This is the only way to get audio support in Rust at the moment; the low-level SDL_audio stuff wants to run a callback on a separate thread and that will segfault at the moment. brson's stuff should eventually fix this, but for now the SDL mixer must be used.

    opened by pcwalton 4
  • Added bindings for SDL_WM_GrabInput to module sdl::mouse

    Added bindings for SDL_WM_GrabInput to module sdl::mouse

    Although SDL_WM_GrabInput may affect the way keyboard events are handled, this was done in the mouse module since it's primary use is generally to capture the cursor without having to spam SDL_WarpMouse.

    opened by jaburns 3
  • Possible fix for automation in rust's memory management?

    Possible fix for automation in rust's memory management?

    Not 100% sure if this is a net positive, but it's one resolution to a handful of compiler errors. Googled a bit and 'finalize' may not be necessary at this point?

    opened by itdaniher 3
  • provide `Debug` and `PartialEq`

    provide `Debug` and `PartialEq`

    It would be nice for development if most structs and enums would provide both Debug and PartialEq. For printing out values and for comparing during tests with assert_eq!. Would you accept a PR adding derive attributes?

    opened by soenkehahn 1
  • implemented Clone trait for Surface

    implemented Clone trait for Surface

    In this implementation, clone() does deep copy of surface, resulting in independent duplicated pixel data. Alternatively, it could be done using refcounting (SDL already supports that), but it would be counterintuitive when blitting on the copied surface, or using copy-on-write, but this would be much harder to implement.

    opened by Xirdus 2
  • Linking sdl-demo/sdl_main.rs fails

    Linking sdl-demo/sdl_main.rs fails

    Hi, I'm trying to run the demo using the sdl_main.rs approach, but it does not seems to be working. This is the linking error I got:

    error: linking with `cc` failed: exit code: 1
    note: cc arguments: '-m64' '-L/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-o' 'sdl_main' 'sdl_main.o' '-lmorestack' '-nodefaultlibs' '-Wl,--as-needed' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libnative-83574243-0.11-pre.rlib' '/home/.../sdl/libsdl-e351513a-0.3.2.rlib' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-dd29dab1-0.11-pre.rlib' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-aad93cea-0.11-pre.rlib' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-3574b280-0.11-pre.rlib' '-L.' '-L/home/.../sdl/.rust' '-L/home/.../sdl' '-Wl,-Bdynamic' '-lSDL' '-ldl' '-lpthread' '-lgcc_s' '-lc' '-lm' '-Wl,-rpath,$ORIGIN/../../../../../../../usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-Wl,-rpath,/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-lcompiler-rt'
    note: /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o: In function `_start':
    (.text+0x20): undefined reference to `main'
    collect2: error: ld returned 1 exit status
    
    error: aborting due to previous error
    

    This is the Rust version I'm using:

    rustc 0.11-pre-nightly (a5cd502 2014-04-22 02:06:35 -0700)
    host: x86_64-unknown-linux-gnu
    

    Running the main.rs demo worked fine. Any ideas?

    opened by albertofem 1
  • Issue running the demo app

    Issue running the demo app

    I am getting the following error:

    [hammackj@taco:~/Documents/opensource/rust-sdl]$ rustc -L$PWD demo/demo.rc
    warning: no debug symbols in executable (-arch x86_64)
    [hammackj@taco:~/Documents/opensource/rust-sdl]$ ./demo/demo
    2013-10-25 23:38:10.990 demo[5196:1003] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error (1000) creating CGSWindow on line 263'
    *** First throw call stack:
    (
    )
    libc++abi.dylib: terminating with uncaught exception of type NSException
    Abort trap: 6
    [hammackj@taco:~/Documents/opensource/rust-sdl]$ 
    

    I am trying to compile the demo. I am using OSX 10.9 with rust from brew. I am a bit new to rust, so I am not exactly sure what is needed to fix this.

    Any tips/thoughts would be great. Thanks

    opened by hammackj 2
  • src/video.rs:5:4: 5:22 error: unresolved import: there is no `RngUtil` in `std::rand`

    src/video.rs:5:4: 5:22 error: unresolved import: there is no `RngUtil` in `std::rand`

    On Rust master branch, get the following error after a fresh clone:

    $ ./configure
    
    $ make
    rustc --cfg image --cfg mixer src/sdl.rc -o libsdl.dummy
    src/video.rs:5:4: 5:22 error: unresolved import: there is no `RngUtil` in `std::rand`
    src/video.rs:5 use std::rand::RngUtil;
                       ^~~~~~~~~~~~~~~~~~
    src/video.rs:5:4: 5:22 error: failed to resolve import `std::rand::RngUtil`
    src/video.rs:5 use std::rand::RngUtil;
                       ^~~~~~~~~~~~~~~~~~
    error: aborting due to 2 previous errors
    make: *** [libsdl.dummy] Error 101
    
    opened by radarsat1 1
  • doesn't link on ubuntu 12, cc: error: Foundation: No such file or directory

    doesn't link on ubuntu 12, cc: error: Foundation: No such file or directory

    rust-sdl$ make rustc --cfg image --cfg mixer src/sdl.rc -o libsdl.dummy src/mixer.rs:3:4: 3:13 warning: unused import [-W unused-imports (default)] src/mixer.rs:3 use std::uint; ^~~~~~~~~ warning: ignoring specified output filename for library. error: linking with cc failed with code 1 note: cc arguments: -L/usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib -m64 -o libsdl-95460b1b072257-0.3.0.so libsdl.o -L/usr/local/lib/rustc/x86_64-unknown
    -linux-gnu/lib -lstd-6c65cf4b443341b1-0.8-pre -lSDL_image -lSDL_mixer -lSDL -lSDLmain -framework Foundation -framework AppKit -lrustrt -lrt -lpthread -L/usr/
    cn/rust/rust-sdl/.rust -L/usr/cn/rust/rust-sdl -shared -lrt -ldl -lm -lmorestack -lrustrt -Wl,-rpath,$ORIGIN/../../../local/lib/rustc/x86_64-unknown-linux-gn
    u/lib -Wl,-rpath,/usr/local/lib/rustc/x86_64-unknown-linux-gnu/lib note: cc: error: Foundation: No such file or directory cc: error: AppKit: No such file or directory

    error: aborting due to previous error make: *** [libsdl.dummy] Error 101

    $/rust/rust-sdl$ git branch -v

    • master b5c0c39 Merge pull request #91 from pcwalton/remove-start
    opened by glycerine 1
Owner
Brian Anderson
Brian Anderson
Rust bindings for GDNative

GDNative bindings for Rust Rust bindings to the Godot game engine. Website | User Guide | API Documentation Stability The bindings cover most of the e

null 3.2k Jan 9, 2023
SDL2 bindings for Rust

Rust-SDL2 Bindings for SDL2 in Rust Changelog for 0.34.2 Overview Rust-SDL2 is a library for talking to the new SDL2.0 libraries from Rust. Low-level

null 2.2k Jan 5, 2023
SFML bindings for Rust

rust-sfml Rust bindings for SFML, the Simple and Fast Multimedia Library. Requirements Linux, Windows, or OS X Rust 1.42 or later SFML 2.5 CSFML 2.5 D

Jeremy Letang 567 Jan 7, 2023
Rust bindings for libtcod 1.6.3 (the Doryen library/roguelike toolkit)

Warning: Not Maintained This project is no longer actively developed or maintained. Please accept our apologies. Open pull requests may still get merg

Tomas Sedovic 226 Nov 17, 2022
Some Rust bindings for Binary Ninja

Binary Ninja Rust Bindings Work in progress Rust bindings geared towards analysis. Features added as they come up. No promises anything works at this

Cory Duplantis 21 May 5, 2022
Qt Quick / QML bindings for Rust

qmlrsng Qt Quick bindings for Rust, based on libqmlbind. The crate libqmlbind-sys wraps libqmlbind C library in Rust and exposes an unsafe API. The go

Nicolas Bigaouette 5 Jul 13, 2017
Idiomatic Rust bindings for Pdfium

Idiomatic Rust bindings for Pdfium pdfium-render provides an idiomatic high-level Rust interface around the low-level bindings to Pdfium exposed by th

Alastair Carey 65 Jan 8, 2023
Wein2D.js bindings for creating browser games in Rust using WebAssembly.

Wein2D.js-WASM Wein2D.js bindings for creating browser games in Rust using WebAssembly. Wein2D.js-WASM requires Wein2d.js to be loaded in the same doc

DevTaube 1 Apr 14, 2022
A simple Verlet integration solver written using the Rust SDL2 bindings.

Rust Verlet Solver A simple Verlet integration solver written using the Rust SDL2 bindings. Where's the friction?! Building cargo-vcpkg is required in

Will 8 Jun 6, 2022
MMDeploy bindings for Rust.

rust-mmdeploy-sys MMDeploy bindings for Rust. ?? THIS REPO IS STILL UNDER CONSTRUCTION! Prerequisites NOTICE: Linux only. Onnxruntime only. In order t

梦阳 2 Sep 29, 2022
Rust bindings for googleprojectzero/TinyInst

tinyinst-rs FFI to TinyInst. Created for LibAFL. Dependencies cxxbridge cargo-make python3 git Running the test Open a terminal and set up your build

Advanced Fuzzing League ++ 12 Jan 20, 2023
Rust bindings for entity-gym.

EntityGym for Rust EntityGym is a Python library that defines a novel entity-based abstraction for reinforcement learning environments which enables h

null 18 Apr 15, 2023
A simple Verlet integration solver written using the Rust SDL2 bindings.

Rust Verlet Solver A simple Verlet integration solver written using the Rust SDL2 bindings. Where's the friction?! Building cargo-vcpkg is required in

Will 8 Jun 6, 2022
corange-rs CorangeCorange lucidscape/corange-rs — Corange bindings

CORANGE-RS This crate provides an interface to the Corange game engine, written in Pure C, SDL and OpenGL by Daniel Holden. Features include: deferred

null 43 Jul 22, 2022
Pure and simple Vulkan bindings generated from Vulkan-Headers!

mira Pure and simple Vulkan bindings generated from Vulkan-Headers! Mira provides a simple and straightforward way to interact with Vulkan. Everything

maresia 3 Mar 3, 2022
Python bindings for egg

Python bindings for egg Installing Install maturin, a cool Rust/Python builder thingy. Download from their site or just pip install maturin. Type make

null 28 Dec 25, 2022
Bindings to TinyGL, a Small, Free and Fast Subset of OpenGL

TinyGL is a very lightweight partial OpenGL implementation. Its small size makes it ideal for static linking.

null 12 Oct 13, 2022
Safe, fully-featured bindings to the Tracy profiler

Complete Rust bindings for the Tracy profiler. Getting Started Just add the following to your Cargo.toml: [dependencies.tracy] package = "tracy_full"

Shaye Garg 12 May 6, 2023
Rust-raytracer - 🔭 A simple ray tracer in Rust 🦀

rust-raytracer An implementation of a very simple raytracer based on Ray Tracing in One Weekend by Peter Shirley in Rust. I used this project to learn

David Singleton 159 Nov 28, 2022