-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include SDL 2.30.1 and link to Rust project for Windows development
Make it easier to develop with SDL2 and Rust on Windows by getting a build environment setup. Previously attempted using 'cargo-vcpkg' but encountered build issues due to vcpkg relying on liblzma port that has been taken down due to being compromised: microsoft/vcpkg#37839
- Loading branch information
Showing
7 changed files
with
47 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,10 @@ | ||
[package] | ||
build = "build.rs" | ||
name = "pong" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies.sdl2] | ||
version = "0.36" | ||
default-features = false | ||
features = ["ttf","image","gfx","mixer","static-link","use-vcpkg"] | ||
|
||
[package.metadata.vcpkg] | ||
dependencies = ["sdl2", "sdl2-image[libjpeg-turbo,tiff,libwebp]", "sdl2-ttf", "sdl2-gfx", "sdl2-mixer"] | ||
git = "https://github.com/microsoft/vcpkg" | ||
rev = "a34c873a9717a888f58dc05268dea15592c2f0ff" | ||
|
||
[package.metadata.vcpkg.target] | ||
x86_64-pc-windows-msvc = { triplet = "x64-windows-static-md" } | ||
[dependencies] | ||
sdl2 = "0.36" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
default: build | ||
|
||
build: | ||
cargo install cargo-vcpkg | ||
cargo vcpkg build | ||
cargo build | ||
|
||
run: | ||
cargo run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
let target = env::var("TARGET").unwrap(); | ||
if target.contains("pc-windows") { | ||
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); | ||
let mut lib_dir = manifest_dir.clone(); | ||
let mut dll_dir = manifest_dir.clone(); | ||
if target.contains("msvc") { | ||
lib_dir.push("msvc"); | ||
dll_dir.push("msvc"); | ||
} else { | ||
lib_dir.push("gnu-mingw"); | ||
dll_dir.push("gnu-mingw"); | ||
} | ||
lib_dir.push("lib"); | ||
dll_dir.push("dll"); | ||
if target.contains("x86_64") { | ||
lib_dir.push("64"); | ||
dll_dir.push("64"); | ||
} else { | ||
lib_dir.push("32"); | ||
dll_dir.push("32"); | ||
} | ||
println!("cargo:rustc-link-search=all={}", lib_dir.display()); | ||
for entry in std::fs::read_dir(dll_dir).expect("Can't read DLL dir") { | ||
let entry_path = entry.expect("Invalid fs entry").path(); | ||
let file_name_result = entry_path.file_name(); | ||
let mut new_file_path = manifest_dir.clone(); | ||
if let Some(file_name) = file_name_result { | ||
let file_name = file_name.to_str().unwrap(); | ||
if file_name.ends_with(".dll") { | ||
new_file_path.push(file_name); | ||
std::fs::copy(&entry_path, new_file_path.as_path()) | ||
.expect("Can't copy from DLL dir"); | ||
} | ||
} | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.