官术网_书友最值得收藏!

Windows with Build Script

A few steps will be required in order to make all of it work. Follow the guide!

  1. 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).
  2. Unpack to folders of your choice. (You can delete it afterward.)
  3. 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
  1. 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
  1. Create a Build Script. If you don't already have one, put this in your Cargo.toml file under [package]:
        build = "build.rs"
  1. 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"
); } } } } }
  1. 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
  1. 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!

主站蜘蛛池模板: 日土县| 友谊县| 忻州市| 吴忠市| 枣阳市| 冀州市| 邻水| 大田县| 施秉县| 抚宁县| 海阳市| 怀宁县| 忻城县| 隆林| 新晃| 磐石市| 商水县| 榆中县| 河津市| 会理县| 白银市| 绥中县| 宜兴市| 郑州市| 璧山县| 金塔县| 九龙坡区| 娱乐| 尚义县| 察隅县| 黄冈市| 内黄县| 平阳县| 客服| 石门县| 五大连池市| 湖口县| 高邮市| 横山县| 平潭县| 永丰县|