- Rust Programming By Example
- Guillaume Gomez Antoni Boucher
- 330字
- 2021-07-02 19:13:03
Windows with Build Script
A few steps will be required in order to make all of it work. Follow the guide!
- Download the mingw and msvc development libraries from http://www.libsdl.org/ (SDL2-devel-2.0.x-mingw.tar.gz and SDL2-devel-2.0.x-VC.zip).
- Unpack to folders of your choice. (You can delete it afterward.)
- Create the following folder structure in the same folder as your Cargo.toml:
gnu-mingw\dll\32 gnu-mingw\dll\64 gnu-mingw\lib\32 gnu-mingw\lib\64 msvc\dll\32 msvc\dll\64 msvc\lib\32 msvc\lib\64
- Copy the lib and dll files from the source archive to the directories we created in step 3 as follows:
SDL2-devel-2.0.x-mingw.tar.gz\SDL2-2.0.x\i686-w64-mingw32\bin -> gnu-mingw\dll\32 SDL2-devel-2.0.x-mingw.tar.gz\SDL2-2.0.x\x86_64-w64-mingw32\bin -> gnu-mingw\dll\64 SDL2-devel-2.0.x-mingw.tar.gz\SDL2-2.0.x\i686-w64-mingw32\lib -> gnu-mingw\lib\32 SDL2-devel-2.0.x-mingw.tar.gz\SDL2-2.0.x\x86_64-w64-mingw32\lib -> gnu-mingw\lib\64 SDL2-devel-2.0.5-VC.zip\SDL2-2.0.x\lib\x86\*.dll -> msvc\dll\32 SDL2-devel-2.0.5-VC.zip\SDL2-2.0.x\lib\x64\*.dll -> msvc\dll\64 SDL2-devel-2.0.5-VC.zip\SDL2-2.0.x\lib\x86\*.lib -> msvc\lib\32 SDL2-devel-2.0.5-VC.zip\SDL2-2.0.x\lib\x64\*.lib -> msvc\lib\64
- Create a Build Script. If you don't already have one, put this in your Cargo.toml file under [package]:
build = "build.rs"
- Create a file in the same directory as Cargo.toml called build.rs and write this into it:
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"); } } } } }
- On build, the Build Script will copy the needed DLLs into the same directory as your Cargo.toml file. You probably don't want to commit these to any Git repositories though, so add the following line to your .gitignore file:
/*.dll
- When you're shipping your game, make sure that you copy the corresponding SDL2.dll to the same directory that your compiled exe is in; otherwise, the game won't launch.
And now your project should build and run on any Windows computer!
推薦閱讀
- 圖書館服務(wù)思維研究
- 中國人民大學(xué)“復(fù)印報(bào)刊資料”轉(zhuǎn)載指數(shù)排名研究報(bào)告(2014)
- 檔案庫房技術(shù)管理
- Mobile Artificial Intelligence Projects
- 信息資源的公共獲取機(jī)制研究
- 大數(shù)據(jù)環(huán)境下高校圖書館知識(shí)服務(wù)模式研究
- 法學(xué)研究與文獻(xiàn)檢索
- 國學(xué)研究文萃·文學(xué)卷
- 高校圖書館創(chuàng)新服務(wù)(谷臻小簡(jiǎn)·AI導(dǎo)讀版)
- 讓文明得到更好的傳承:公共文化服務(wù)體系中公共檔案館發(fā)展戰(zhàn)略
- 人文通識(shí)講演錄:歷史卷
- “秦陵杯”講解員職業(yè)技能大賽講解詞匯編
- 數(shù)字信息環(huán)境下圖書館信息資源建設(shè)與共享
- 兒童閱讀的世界Ⅳ:學(xué)校、家庭與社區(qū)的實(shí)踐研究
- 中國石羊河流域地理學(xué)研究文獻(xiàn)目錄索引