summaryrefslogtreecommitdiff
path: root/build.rs
diff options
context:
space:
mode:
authorZac Pullar-Strecker <zacps@users.noreply.github.com>2018-10-17 06:02:52 +1300
committerJoe Wilm <jwilm@users.noreply.github.com>2018-10-16 10:02:52 -0700
commit15e0deae2b49078b47a782679300cdf99d9ce687 (patch)
tree8175fbed0def1af08cd2db41583975adbb27dff1 /build.rs
parentb41c6b736d67d61e92b174dfea58ae46813934cd (diff)
downloadalacritty-15e0deae2b49078b47a782679300cdf99d9ce687.tar.gz
alacritty-15e0deae2b49078b47a782679300cdf99d9ce687.zip
Add support for Windows (#1374)
Initial support for Windows is implemented using the winpty translation layer. Clipboard support for Windows is provided through the `clipboard` crate, and font rasterization is provided by RustType. The tty.rs file has been split into OS-specific files to separate standard pty handling from the winpty implementation. Several binary components are fetched via build script on windows including libclang and winpty. These could be integrated more directly in the future either by building those dependencies as part of the Alacritty build process or by leveraging git lfs to store the artifacts. Fixes #28.
Diffstat (limited to 'build.rs')
-rw-r--r--build.rs71
1 files changed, 66 insertions, 5 deletions
diff --git a/build.rs b/build.rs
index 0bdea324..5d0dace0 100644
--- a/build.rs
+++ b/build.rs
@@ -11,20 +11,81 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
+#[cfg(windows)]
+extern crate embed_resource;
+#[cfg(windows)]
+extern crate tempdir;
+#[cfg(windows)]
+extern crate reqwest;
+#[cfg(windows)]
+extern crate zip;
+
+#[cfg(windows)]
+use tempdir::TempDir;
+
extern crate gl_generator;
-use gl_generator::{Registry, Api, Profile, Fallbacks, GlobalGenerator};
+use gl_generator::{Api, Fallbacks, GlobalGenerator, Profile, Registry};
+
use std::env;
use std::fs::File;
use std::path::Path;
+#[cfg(windows)]
+use std::io;
+#[cfg(windows)]
+use std::fs::OpenOptions;
+
+#[cfg(windows)]
+const WINPTY_PACKAGE_URL: &str = "https://www.nuget.org/api/v2/package/winpty.NET/0.4.2";
+
fn main() {
let dest = env::var("OUT_DIR").unwrap();
let mut file = File::create(&Path::new(&dest).join("gl_bindings.rs")).unwrap();
- Registry::new(Api::Gl, (4, 5), Profile::Core, Fallbacks::All, [
- "GL_ARB_blend_func_extended"
- ])
- .write_bindings(GlobalGenerator, &mut file)
+ Registry::new(
+ Api::Gl,
+ (4, 5),
+ Profile::Core,
+ Fallbacks::All,
+ ["GL_ARB_blend_func_extended"],
+ ).write_bindings(GlobalGenerator, &mut file)
.unwrap();
+
+ #[cfg(windows)]
+ {
+ embed_resource::compile("assets/windows/windows.rc");
+
+ // Path is relative to target/{profile}/build/alacritty-HASH/out
+ let file = Path::new(&env::var("OUT_DIR").unwrap()).join("../../../winpty-agent.exe");
+ if !file.exists() {
+ aquire_winpty_agent(&file);
+ }
+ }
+}
+
+#[cfg(windows)]
+fn aquire_winpty_agent(out_path: &Path) {
+ let tmp_dir = TempDir::new("alacritty_build").unwrap();
+
+ let mut response = reqwest::get(WINPTY_PACKAGE_URL).unwrap();
+ let mut file = OpenOptions::new()
+ .read(true)
+ .write(true)
+ .create(true)
+ .open(tmp_dir.path().join("winpty_package.zip")).unwrap();
+
+ io::copy(&mut response, &mut file).unwrap();
+
+ let mut archive = zip::ZipArchive::new(file).unwrap();
+
+ let target = match env::var("TARGET").unwrap().split("-").next().unwrap() {
+ "x86_64" => "x86",
+ "i386" => "x64",
+ _ => panic!("architecture has no winpty binary")
+ };
+
+ let mut winpty_agent = archive.by_name(&format!("content/winpty/{}/winpty-agent.exe", target)).unwrap();
+
+ io::copy(&mut winpty_agent, &mut File::create(out_path).unwrap()).unwrap();
}