forked from karx/catbox
we now have zip files, one step closer to ultimate greatness
This commit is contained in:
parent
7b023a006a
commit
3aecca7482
|
@ -20,6 +20,7 @@ rodio = { version = "0.15.0", optional = true}
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
ureq = "2.6.2"
|
ureq = "2.6.2"
|
||||||
zip = "0.6.4"
|
zip = "0.6.4"
|
||||||
|
tempfile = "3.5.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["audio"]
|
default = ["audio"]
|
||||||
|
|
61
build.rs
61
build.rs
|
@ -1,61 +1,66 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{copy, BufWriter};
|
use std::io::{copy, BufWriter};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use ureq::{Agent};
|
||||||
use zip::ZipArchive;
|
use zip::ZipArchive;
|
||||||
use ureq::{Error, Agent, AgentBuilder};
|
|
||||||
|
use tempfile::tempdir;
|
||||||
|
|
||||||
|
|
||||||
|
enum State {
|
||||||
|
Six,
|
||||||
|
Three,
|
||||||
|
}
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let target = env::var("TARGET")?;
|
let target = env::var("TARGET")?;
|
||||||
if target.contains("pc-windows") {
|
if target.contains("pc-windows-gnu") {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?);
|
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?);
|
||||||
|
|
||||||
//CREATING TEMP DIR FOR DOWNLOADS
|
//CREATING TEMP DIR FOR DOWNLOADS
|
||||||
let mut temp_dir = manifest_dir.clone();
|
let temp_dir = tempdir()?;
|
||||||
temp_dir.push("/tmp");
|
let temp_path = temp_dir.path();
|
||||||
std::fs::create_dir(temp_dir.clone());
|
//returns zip files
|
||||||
|
let url_sdl = download_files("https://github.com/libsdl-org/SDL/releases/download/release-2.26.4/SDL2-devel-2.26.4-mingw.zip")?;
|
||||||
|
|
||||||
let url_sdl = downloadFiles(temp_dir.clone(), "https://github.com/libsdl-org/SDL/releases/download/release-2.26.4/SDL2-devel-2.26.4-mingw.zip");
|
let url_ttf = download_files("https://github.com/libsdl-org/SDL_ttf/releases/download/release-2.20.2/SDL2_ttf-devel-2.20.2-mingw.zip")?;
|
||||||
let url_ttf = downloadFiles(temp_dir.clone(), "https://github.com/libsdl-org/SDL_ttf/releases/download/release-2.20.2/SDL2_ttf-devel-2.20.2-mingw.zip");
|
|
||||||
let url_image = downloadFiles(temp_dir.clone(), "https://github.com/libsdl-org/SDL_image/releases/download/release-2.6.3/SDL2_image-devel-2.6.3-mingw.zip");
|
|
||||||
|
|
||||||
|
let url_image = download_files("https://github.com/libsdl-org/SDL_image/releases/download/release-2.6.3/SDL2_image-devel-2.6.3-mingw.zip")?;
|
||||||
|
|
||||||
|
|
||||||
|
//GETTING LIBRARY DIRECTORIES GIVEN THE BUILD TARGET
|
||||||
let mut lib_dir = manifest_dir.clone();
|
let mut lib_dir = manifest_dir.clone();
|
||||||
let mut dll_dir = manifest_dir.clone();
|
let mut dll_dir = manifest_dir.clone();
|
||||||
|
|
||||||
|
let mut state: State = State::Six;
|
||||||
if target.contains("msvc") {
|
|
||||||
lib_dir.push("msvc");
|
|
||||||
dll_dir.push("msvc");
|
|
||||||
} else {
|
|
||||||
lib_dir.push("gnu-mingw");
|
lib_dir.push("gnu-mingw");
|
||||||
|
|
||||||
dll_dir.push("gnu-mingw");
|
dll_dir.push("gnu-mingw");
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
lib_dir.push("lib");
|
lib_dir.push("lib");
|
||||||
dll_dir.push("dll");
|
dll_dir.push("dll");
|
||||||
|
|
||||||
|
|
||||||
if target.contains("x86_64") {
|
if target.contains("x86_64") {
|
||||||
lib_dir.push("64");
|
lib_dir.push("64");
|
||||||
dll_dir.push("64");
|
dll_dir.push("64");
|
||||||
} else {
|
} else {
|
||||||
|
state = State::Three;
|
||||||
lib_dir.push("32");
|
lib_dir.push("32");
|
||||||
dll_dir.push("32");
|
dll_dir.push("32");
|
||||||
}
|
}
|
||||||
|
//could only error if dir already exists so no need to handle error lolz
|
||||||
std::fs::create_dir_all(&lib_dir);
|
std::fs::create_dir_all(&lib_dir);
|
||||||
|
std::fs::create_dir_all(&dll_dir);
|
||||||
|
|
||||||
|
//NOW THAT WE HAVE THE OUTPUT DIRECTORIES, WE NEED TO EXTRACT THE ZIP FILES INTO THE
|
||||||
|
//CORRECT DIRECTORIES
|
||||||
|
let mut zip_sdl2 = ZipArchive::new(url_sdl)?;
|
||||||
|
let mut zip_ttf = ZipArchive::new(url_ttf)?;
|
||||||
|
let mut zip_image = ZipArchive::new(url_image)?;
|
||||||
|
zip_ttf.extract(&temp_path)?;
|
||||||
|
zip_image.extract(&temp_path)?;
|
||||||
|
zip_sdl2.extract(&temp_path)?;
|
||||||
|
|
||||||
|
//SEARCHES AND LINKS LIBRARIES WITH CARGO
|
||||||
println!("cargo:rustc-link-search=all={}", lib_dir.display());
|
println!("cargo:rustc-link-search=all={}", lib_dir.display());
|
||||||
|
|
||||||
for entry in std::fs::read_dir(dll_dir).expect("Can't read DLL dir") {
|
for entry in std::fs::read_dir(dll_dir).expect("Can't read DLL dir") {
|
||||||
|
@ -75,8 +80,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn downloadFiles<P: AsRef<Path>>(path: P, url: &str) -> Result<File, Box<dyn std::error::Error>>
|
pub fn download_files(url: &str) -> Result<File, Box<dyn std::error::Error>> {
|
||||||
{
|
|
||||||
let agent = Agent::new();
|
let agent = Agent::new();
|
||||||
let resp = agent.get(url).call()?;
|
let resp = agent.get(url).call()?;
|
||||||
|
|
||||||
|
@ -97,6 +101,5 @@ pub fn downloadFiles<P: AsRef<Path>>(path: P, url: &str) -> Result<File, Box<dyn
|
||||||
let mut writer = BufWriter::new(file);
|
let mut writer = BufWriter::new(file);
|
||||||
copy(&mut resp.into_reader(), &mut writer)?;
|
copy(&mut resp.into_reader(), &mut writer)?;
|
||||||
|
|
||||||
|
|
||||||
Ok(writer.into_inner()?)
|
Ok(writer.into_inner()?)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue