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

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!

主站蜘蛛池模板: 林州市| 喀喇沁旗| 靖宇县| 鹤山市| 恩施市| 宜城市| 沁源县| 买车| 桐梓县| 海丰县| 桦南县| 阿鲁科尔沁旗| 宝应县| 河池市| 滨海县| 祁连县| 华安县| 化隆| 西华县| 邯郸市| 南召县| 彝良县| 翼城县| 凤凰县| 堆龙德庆县| 库车县| 天台县| 大冶市| 黔西| 凌源市| 无棣县| 德保县| 醴陵市| 宜黄县| 桐乡市| 逊克县| 延边| 历史| 滦南县| 堆龙德庆县| 安岳县|