Skip to content

Commit 17142a6

Browse files
authored
remove unused dependencies (deltaphc#94)
* remove raylib src directory copy to out dir * fix callback.rs not compiling due to inline-const experimental * remove libc dependency refactor: libc::c_void -> std::is::raw:::c_void libc::malloc -> ffi::MemAlloc (using raylibs bindings to malloc instead) * removed unused crate lazy_static remove unused crate parking_lot make specs-derive optional remove arr_macro which was only needed for the examples * make specs an optional dependency * bump bindgen 0.69 -> 0.70 * raylib-sys remove fs_extra dependency update cmake 0.1.49 -> 0.1.51 * remove arr_macro from samples fix 3d_camera_first_person to compile
1 parent 0c8d134 commit 17142a6

File tree

8 files changed

+38
-49
lines changed

8 files changed

+38
-49
lines changed

raylib-sys/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ edition = "2018"
1212
exclude = ["raylib/examples/*", "raylib/projects/*", "raylib/templates/*"]
1313

1414
[build-dependencies]
15-
fs_extra = "1.2"
16-
cmake = "0.1.49"
15+
cmake = "0.1.51"
1716
cc = "1.0"
18-
bindgen = "0.69.0"
17+
bindgen = "0.70"
1918

2019
[features]
2120
default = []

raylib-sys/build.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ fn build_with_cmake(src_path: &str) {
128128

129129
// Allows disabling the default maping of screenshot and gif recording in raylib
130130
{
131-
#[cfg(any(
132-
feature = "noscreenshot",
133-
feature = "nogif"
134-
))]
131+
#[cfg(any(feature = "noscreenshot", feature = "nogif"))]
135132
builder.define("CUSTOMIZE_BUILD", "ON");
136133

137134
#[cfg(feature = "noscreenshot")]
@@ -333,9 +330,11 @@ fn main() {
333330
}
334331
let (platform, platform_os) = platform_from_target(&target);
335332

336-
// Donwload raylib source
337-
let src = cp_raylib();
338-
build_with_cmake(&src);
333+
let raylib_src = "./raylib";
334+
if is_directory_empty(raylib_src) {
335+
panic!("raylib source does not exist in: `raylib-sys/raylib`. Please copy it in");
336+
}
337+
build_with_cmake(raylib_src);
339338

340339
gen_bindings();
341340

@@ -344,17 +343,13 @@ fn main() {
344343
gen_rgui();
345344
}
346345

347-
// cp_raylib copy raylib to an out dir
348-
fn cp_raylib() -> String {
349-
let out = env::var("OUT_DIR").unwrap();
350-
let out = Path::new(&out); //.join("raylib_source");
351-
352-
let mut options = fs_extra::dir::CopyOptions::new();
353-
options.skip_exist = true;
354-
fs_extra::dir::copy("raylib", out, &options)
355-
.unwrap_or_else(|_| panic!("failed to copy raylib source to {}", &out.to_string_lossy()));
356-
357-
out.join("raylib").to_string_lossy().to_string()
346+
#[must_use]
347+
/// returns false if the directory does not exist
348+
fn is_directory_empty(path: &str) -> bool {
349+
match std::fs::read_dir(path) {
350+
Ok(mut dir) => dir.next().is_none(),
351+
Err(_) => true,
352+
}
358353
}
359354

360355
// run_command runs a command to completion or panics. Used for running curl and powershell.

raylib/Cargo.toml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,19 @@ autoexamples = false
1414

1515
[dependencies]
1616
raylib-sys = { version = "5.5.0", path = "../raylib-sys" }
17-
libc = "0.2.45"
18-
lazy_static = "1.2.0"
1917
cfg-if = "1.0.0"
2018
serde = { version = "1.0.125", features = ["derive"], optional = true }
2119
serde_json = { version = "1.0.64", optional = true }
2220

2321
mint = { version = "0.5.9", optional = true }
24-
parking_lot = "0.12.1"
2522

26-
specs-derive = "0.4.1"
23+
specs = { version = "0.16.1", default = false, optional = true }
24+
specs-derive = { version = "0.4.1", optional = true }
2725
thiserror = "1.0.61"
2826

2927
[dev-dependencies]
3028
structopt = "0.3"
3129
rand = "0.8.5"
32-
arr_macro = "0.1.3"
33-
34-
[dependencies.specs]
35-
version = "0.16.1"
36-
default-features = false
3730

3831
[features]
3932
nightly = []

raylib/src/core/callbacks.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,37 @@ static LOAD_FILE_TEXT_CALLBACK: AtomicUsize = AtomicUsize::new(0);
3232
static AUDIO_STREAM_CALLBACK: AtomicUsize = AtomicUsize::new(0);
3333

3434
fn trace_log_callback() -> Option<RustTraceLogCallback> {
35-
const { assert!(size_of::<RustTraceLogCallback>() == size_of::<usize>()) };
35+
debug_assert!(size_of::<RustTraceLogCallback>() == size_of::<usize>());
3636
unsafe { transmute(TRACE_LOG_CALLBACK.load(Ordering::Relaxed)) }
3737
}
3838

3939
fn save_file_data_callback() -> Option<RustSaveFileDataCallback> {
40-
const { assert!(size_of::<RustSaveFileDataCallback>() == size_of::<usize>()) };
40+
debug_assert!(size_of::<RustSaveFileDataCallback>() == size_of::<usize>());
4141
unsafe { transmute(SAVE_FILE_DATA_CALLBACK.load(Ordering::Relaxed)) }
4242
}
4343

4444
fn load_file_data_callback() -> Option<RustLoadFileDataCallback> {
45-
const { assert!(size_of::<RustLoadFileDataCallback>() == size_of::<usize>()) };
45+
debug_assert!(size_of::<RustLoadFileDataCallback>() == size_of::<usize>());
4646
unsafe { transmute(LOAD_FILE_DATA_CALLBACK.load(Ordering::Relaxed)) }
4747
}
4848

4949
fn save_file_text_callback() -> Option<RustSaveFileTextCallback> {
50-
const { assert!(size_of::<RustSaveFileTextCallback>() == size_of::<usize>()) };
50+
debug_assert!(size_of::<RustSaveFileTextCallback>() == size_of::<usize>());
5151
unsafe { transmute(SAVE_FILE_TEXT_CALLBACK.load(Ordering::Relaxed)) }
5252
}
5353

5454
fn load_file_text_callback() -> Option<RustLoadFileTextCallback> {
55-
const { assert!(size_of::<RustLoadFileTextCallback>() == size_of::<usize>()) };
55+
debug_assert!(size_of::<RustLoadFileTextCallback>() == size_of::<usize>());
5656
unsafe { transmute(LOAD_FILE_TEXT_CALLBACK.load(Ordering::Relaxed)) }
5757
}
5858

5959
fn audio_stream_callback() -> Option<RustAudioStreamCallback> {
60-
const { assert!(size_of::<RustAudioStreamCallback>() == size_of::<usize>()) };
60+
debug_assert!(size_of::<RustAudioStreamCallback>() == size_of::<usize>());
6161
unsafe { transmute(AUDIO_STREAM_CALLBACK.load(Ordering::Relaxed)) }
6262
}
6363

6464
#[no_mangle]
65-
pub extern "C" fn custom_trace_log_callback(level: TraceLogLevel, text: *const c_char) {
65+
pub unsafe extern "C" fn custom_trace_log_callback(level: TraceLogLevel, text: *const c_char) {
6666
if let Some(trace_log) = trace_log_callback() {
6767
let text = if text.is_null() {
6868
Cow::Borrowed("(MESSAGE WAS NULL)")

raylib/src/core/models.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl RaylibHandle {
100100
}
101101
}
102102
unsafe {
103-
ffi::MemFree(m_ptr as *mut libc::c_void);
103+
ffi::MemFree(m_ptr as *mut ::std::os::raw::c_void);
104104
}
105105
Ok(m_vec)
106106
}
@@ -470,7 +470,7 @@ impl Material {
470470
}
471471
}
472472
unsafe {
473-
ffi::MemFree(m_ptr as *mut libc::c_void);
473+
ffi::MemFree(m_ptr as *mut ::std::os::raw::c_void);
474474
}
475475
Ok(m_vec)
476476
}

raylib/src/core/text.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::error::{error, Error};
99
use crate::ffi;
1010
use crate::math::Rectangle;
1111

12-
use std::convert::{AsMut, AsRef};
12+
use std::convert::{AsMut, AsRef, TryInto};
1313
use std::ffi::{CString, OsString};
1414
use std::mem::ManuallyDrop;
1515
use std::ops::Deref;
@@ -371,7 +371,7 @@ impl Font {
371371
unsafe {
372372
self.glyphCount = chars.len() as i32;
373373
let data_size = self.glyphCount as usize * std::mem::size_of::<ffi::GlyphInfo>();
374-
let ci_arr_ptr = libc::malloc(data_size); // raylib frees this data in UnloadFont
374+
let ci_arr_ptr = ffi::MemAlloc(data_size.try_into().unwrap()); // raylib frees this data in UnloadFont
375375
std::ptr::copy(
376376
chars.as_ptr(),
377377
ci_arr_ptr as *mut ffi::GlyphInfo,
@@ -415,7 +415,7 @@ pub fn gen_image_font_atlas(
415415
#[allow(clippy::uninit_vec)]
416416
recs.set_len(chars.len());
417417
std::ptr::copy(ptr, recs.as_mut_ptr(), chars.len());
418-
ffi::MemFree(ptr as *mut libc::c_void);
418+
ffi::MemFree(ptr as *mut ::std::os::raw::c_void);
419419
return (img, recs);
420420
}
421421
}

samples/3d_camera_first_person.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use arr_macro::arr;
21
use rand::prelude::*;
32
use raylib::prelude::*;
43

54
const WINDOW_WIDTH: i32 = 1280;
65
const WINDOW_HEIGHT: i32 = 720;
76

7+
#[derive(Copy, Clone, Default)]
88
struct Column {
99
height: f32,
1010
position: Vector3,
@@ -14,13 +14,13 @@ struct Column {
1414
impl Column {
1515
fn create_random() -> Column {
1616
let mut rng = rand::thread_rng();
17-
let height: f32 = rng.gen_range(1.0, 12.0);
17+
let height: f32 = rng.gen_range(1.0..12.0);
1818
let position = Vector3::new(
19-
rng.gen_range(-15.0, 15.0),
19+
rng.gen_range(-15.0..15.0),
2020
height / 2.0,
21-
rng.gen_range(-15.0, 15.0),
21+
rng.gen_range(-15.0..15.0),
2222
);
23-
let color = Color::new(rng.gen_range(20, 255), rng.gen_range(10, 55), 30, 255);
23+
let color = Color::new(rng.gen_range(20..255), rng.gen_range(10..55), 30, 255);
2424

2525
Column {
2626
height,
@@ -42,7 +42,10 @@ fn main() {
4242
Vector3::new(0.0, 1.0, 0.0),
4343
60.0,
4444
);
45-
let columns: [Column; 20] = arr![Column::create_random(); 20];
45+
let mut columns = [Column::default(); 20];
46+
for col in columns.iter_mut() {
47+
*col = Column::create_random();
48+
}
4649

4750
rl.set_target_fps(60);
4851

samples/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ rand = "0.7"
1616
#tcod = "0.14"
1717
serde = { version = "1.0", features = ["derive"] }
1818
serde_json = "1.0"
19-
arr_macro = "0.1.3"
2019

2120
[dependencies.specs]
2221
version = "0.16.1"

0 commit comments

Comments
 (0)