Browse Source

Update bindings + fix build errors

* Update to 2021 edition
* Fix build errors for duplicate impls, type mismatch, etc.
* don't compile texenv yet - need the macros
* Update deps for recent changes
pull/18/head
Ian Chamberlain 3 years ago
parent
commit
940c3fd69d
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 3
      .gitignore
  2. 5
      Cargo.toml
  3. 8
      bindgen.sh
  4. 19
      build.rs
  5. 9
      src/base.rs
  6. 267
      src/bindgen.rs
  7. 1511
      src/bindings.rs
  8. 38
      src/lib.rs
  9. 6
      src/texenv.rs
  10. 16
      src/uniforms.rs

3
.gitignore vendored

@ -1,2 +1,5 @@ @@ -1,2 +1,5 @@
target
Cargo.lock
rust-toolchain
rust-toolchain.toml

5
Cargo.toml

@ -2,7 +2,8 @@ @@ -2,7 +2,8 @@
name = "citro3d-sys"
version = "0.1.0"
authors = ["panicbit <panicbit.dev@gmail.com>"]
edition = "2021"
[dependencies]
libc = "0.2.26"
ctru-sys = { git = "https://github.com/rust3ds/ctru-rs" }
libc = "0.2.116"
ctru-sys = { path = "../ctru-rs/ctru-sys" }

8
bindgen.sh

@ -22,7 +22,6 @@ bindgen "$DEVKITPRO/libctru/include/citro3d.h" \ @@ -22,7 +22,6 @@ bindgen "$DEVKITPRO/libctru/include/citro3d.h" \
--ctypes-prefix "::libc" \
--no-prepend-enum-name \
--generate "functions,types,vars" \
--blacklist-type "u(8|16|32|64)" \
--blacklist-type "__builtin_va_list" \
--blacklist-type "__va_list" \
--no-recursive-whitelist \
@ -32,7 +31,7 @@ bindgen "$DEVKITPRO/libctru/include/citro3d.h" \ @@ -32,7 +31,7 @@ bindgen "$DEVKITPRO/libctru/include/citro3d.h" \
--whitelist-function 'AttrInfo_(Init|AddLoader|AddFixed)' \
--whitelist-function 'BufInfo_(Init|Add)' \
--whitelist-function 'Mtx_.*' \
--raw-line "use libctru::*;" \
--raw-line "use ctru_sys::*;" \
-- \
--target=arm-none-eabi \
--sysroot=$DEVKITARM/arm-none-eabi \
@ -45,4 +44,7 @@ bindgen "$DEVKITPRO/libctru/include/citro3d.h" \ @@ -45,4 +44,7 @@ bindgen "$DEVKITPRO/libctru/include/citro3d.h" \
-mfpu=vfp \
-DARM11 \
-D_3DS \
> src/bindgen.rs
-D__3DS__ \
> src/bindings.rs
rustfmt src/bindings.rs

19
build.rs

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
use std::env;
fn main() {
let dkp_path = env::var("DEVKITPRO").unwrap();
let debug_symbols = env::var("DEBUG").unwrap();
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=DEVKITPRO");
println!("cargo:rustc-link-search=native={}/libctru/lib", dkp_path);
println!(
"cargo:rustc-link-lib=static={}",
match debug_symbols.as_str() {
// Based on valid values described in
// https://doc.rust-lang.org/cargo/reference/profiles.html#debug
"0" | "false" => "citro3d",
_ => "citro3dd",
}
);
}

9
src/base.rs

@ -1,10 +1,9 @@ @@ -1,10 +1,9 @@
#![allow(non_snake_case)]
// c3d/base.h
//! `<c3d/base.h>`
use libc::c_int;
use super::*;
use libc::c_int;
pub unsafe fn C3D_FixedAttribSet(id: c_int, x: f32, y: f32, z: f32, w: f32) {
let mut ptr = C3D_FixedAttribGetWritePtr(id);
*(*ptr).c.as_mut() = [x, y, z, w];
let ptr = C3D_FixedAttribGetWritePtr(id);
(*ptr).c.copy_from_slice(&[x, y, z, w]);
}

267
src/bindgen.rs

File diff suppressed because one or more lines are too long

1511
src/bindings.rs

File diff suppressed because it is too large Load Diff

38
src/lib.rs

@ -1,33 +1,21 @@ @@ -1,33 +1,21 @@
extern crate libc;
extern crate core;
#[macro_use] extern crate ctru_sys as libctru;
#![no_std]
#![allow(non_snake_case)]
#![feature(untagged_unions)] // used for [`C3D_Mtx`]
#[allow(warnings)]
mod bindgen;
pub mod base;
pub mod texenv;
pub mod uniforms;
pub use bindgen::*;
#[allow(warnings)]
#[allow(warnings)]
#[allow(non_upper_case_globals)]
#[allow(non_camel_case_types)]
#[allow(clippy::all)]
mod bindings;
pub use base::*;
pub use texenv::*;
pub use bindings::*;
pub use uniforms::*;
#[link(name="citro3d")]
#[link(name="ctru")]
extern {}
impl Copy for C3D_FVec {}
impl Clone for C3D_FVec {
fn clone(&self) -> Self {
*self
}
}
impl From<libctru::GPU_DEPTHBUF> for C3D_DEPTHTYPE {
fn from(fmt: libctru::GPU_DEPTHBUF) -> Self {
Self {
__e: fmt,
}
}
}
#[cfg(todo = "gpu_tev_macros")]
pub use texenv::*;

6
src/texenv.rs

@ -1,8 +1,8 @@ @@ -1,8 +1,8 @@
#![allow(non_snake_case)]
// c3d/texenv.h
#![cfg(todo = "gpu_tev_macros")]
//! `<c3d/texenv.h>`
use libc::c_int;
use super::*;
use libc::c_int;
pub unsafe fn C3D_TexEnvSrc(env: *mut C3D_TexEnv, mode: c_int, s1: c_int, s2: c_int, s3: c_int) {
let param = gpu_tevsources!(s1, s2, s3);

16
src/uniforms.rs

@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
#![allow(non_snake_case)]
// c3d/uniforms.h
//! `<c3d/uniforms.h>`
use libc::c_int;
use super::*;
use libctru::GPU_SHADER_TYPE;
use ctru_sys::GPU_SHADER_TYPE;
use libc::c_int;
#[inline]
pub unsafe fn C3D_FVUnifWritePtr(type_: GPU_SHADER_TYPE, id: c_int, size: c_int) -> *mut C3D_FVec {
for i in 0 .. size {
C3D_FVUnifDirty[type_ as usize][(id+i) as usize] = true;
for i in 0..size {
C3D_FVUnifDirty[type_ as usize][(id + i) as usize] = true;
}
return &mut C3D_FVUnif[type_ as usize][id as usize];
@ -18,7 +18,7 @@ pub unsafe fn C3D_FVUnifWritePtr(type_: GPU_SHADER_TYPE, id: c_int, size: c_int) @@ -18,7 +18,7 @@ pub unsafe fn C3D_FVUnifWritePtr(type_: GPU_SHADER_TYPE, id: c_int, size: c_int)
pub unsafe fn C3D_FVUnifMtxNx4(type_: GPU_SHADER_TYPE, id: c_int, mtx: *const C3D_Mtx, num: c_int) {
let ptr = C3D_FVUnifWritePtr(type_, id, num);
for i in 0 .. num {
for i in 0..num {
*ptr.offset(i as isize) = (*mtx).r.as_ref()[i as usize];
}
}
@ -31,5 +31,5 @@ pub unsafe fn C3D_FVUnifMtx4x4(type_: GPU_SHADER_TYPE, id: c_int, mtx: *const C3 @@ -31,5 +31,5 @@ pub unsafe fn C3D_FVUnifMtx4x4(type_: GPU_SHADER_TYPE, id: c_int, mtx: *const C3
#[inline]
pub unsafe fn C3D_FVUnifSet(type_: GPU_SHADER_TYPE, id: c_int, x: f32, y: f32, z: f32, w: f32) {
let ptr = C3D_FVUnifWritePtr(type_, id, 1);
*(*ptr).c.as_mut() = [x, y, z, w];
(*ptr).c.copy_from_slice(&[x, y, z, w]);
}

Loading…
Cancel
Save