diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000000..2f2f3f029e --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,93 @@ +# Appveyor configuration template for Rust using rustup for Rust installation +# https://github.com/starkat99/appveyor-rust + +## Operating System (VM environment) ## + +# Rust needs at least Visual Studio 2013 Appveyor OS for MSVC targets. +os: Visual Studio 2015 + +## Build Matrix ## +environment: + matrix: + +### MSVC Targets ### + # Stable 64-bit MSVC + # - channel: stable + # toolchain: stable-x86_64-pc-windows-msvc + # target: x86_64-pc-windows-msvc + # target_env: msvc + # mingw_subdir: mingw64 + # mingw_target: x86_64-w64-mingw32 + # mingw_package_prefix: mingw-w64-x86_64 + # Stable 32-bit MSVC + # - channel: stable + # toolchain: stable-i686-pc-windows-msvc + # target: i686-pc-windows-msvc + # target_env: msvc + # mingw_subdir: mingw32 + # mingw_target: i686-w64-mingw32 + # mingw_package_prefix: mingw-w64-i686 + +### GNU Targets ### + # Stable 64-bit GNU + - channel: stable + toolchain: stable-x86_64-pc-windows-msvc + target: x86_64-pc-windows-gnu + target_env: gnu + mingw_subdir: mingw64 + mingw_target: x86_64-w64-mingw32 + mingw_package_prefix: mingw-w64-x86_64 + # Stable 32-bit GNU + # - channel: stable + # toolchain: stable-i686-pc-windows-msvc + # target: i686-pc-windows-gnu + # target_env: gnu + # mingw_subdir: mingw32 + # mingw_target: i686-w64-mingw32 + # mingw_package_prefix: mingw-w64-i686 + +cache: + - '%USERPROFILE%\.cargo\bin' + - '%USERPROFILE%\.cargo\config' + - '%USERPROFILE%\.cargo\env' + - '%USERPROFILE%\.cargo\.crates.toml' + - target + +## Install Script ## + +# This is the most important part of the Appveyor configuration. This installs the version of Rust +# specified by the 'channel' and 'target' environment variables from the build matrix. This uses +# rustup to install Rust. +# +# For simple configurations, instead of using the build matrix, you can simply set the +# default-toolchain and default-host manually here. +install: + - appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe + - rustup-init -yv --default-toolchain %channel%-msvc --default-host %target% + - set PATH=%PATH%;%USERPROFILE%\.cargo\bin + - set PATH=C:\msys64\%mingw_subdir%\bin;C:\msys64\usr\bin;%PATH% + - rustup target add %target% + - rustup component add rust-src + - pacman -S --noconfirm "%mingw_package_prefix%-fontconfig" "%mingw_package_prefix%-freetype" "%mingw_package_prefix%-icu" + - rustc -vV + - cargo -vV + +## Build Script ## + +# 'cargo test' takes care of building for us, so disable Appveyor's build stage. This prevents +# the "directory does not contain a project or solution file" error. +build: false + +before_test: + - set RUST_BACKTRACE=1 + # Building on msvc toolchain is seen as cross compilation. + - set PKG_CONFIG_ALLOW_CROSS=1 + # Workaround rust#53454 + - if "%target_env%" == "gnu" copy /y "C:\msys64\%mingw_subdir%\%mingw_target%\lib\crt2.o" %USERPROFILE%\.rustup\toolchains\%toolchain%\lib\rustlib\%target%\lib\crt2.o" + - if "%target_env%" == "gnu" copy /y "C:\msys64\%mingw_subdir%\%mingw_target%\lib\dllcrt2.o" %USERPROFILE%\.rustup\toolchains\%toolchain%\lib\rustlib\%target%\lib\dllcrt2.o" + +# Uses 'cargo test' to run tests and build. Alternatively, the project may call compiled programs +# directly or perform other testing commands. Rust will automatically be placed in the PATH +# environment variable. +test_script: + - cargo test --target %target% diff --git a/Cargo.lock b/Cargo.lock index 9434dd6410..8433fc86ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -156,6 +156,14 @@ dependencies = [ "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "core-foundation" version = "0.2.3" @@ -398,14 +406,6 @@ dependencies = [ "miniz_oxide 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "mkstemp-rs" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "msdos_time" version = "0.1.6" @@ -486,7 +486,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "proc-macro2" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -497,7 +497,7 @@ name = "quote" version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -510,6 +510,23 @@ dependencies = [ "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rand" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "redox_syscall" version = "0.1.40" @@ -600,7 +617,7 @@ name = "serde_derive" version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.14.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -635,7 +652,7 @@ name = "syn" version = "0.14.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -656,7 +673,6 @@ dependencies = [ "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "md-5 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "mkstemp-rs 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.71 (registry+https://github.com/rust-lang/crates.io-index)", @@ -664,6 +680,7 @@ dependencies = [ "sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "tectonic_xdv 0.1.9-dev", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "tempfile 3.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "termcolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "zip 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -686,6 +703,18 @@ dependencies = [ "remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tempfile" +version = "3.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "termcolor" version = "1.0.1" @@ -909,6 +938,7 @@ dependencies = [ "checksum cc 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "2119ea4867bd2b8ed3aecab467709720b2d55b1bcfe09f772fd68066eaf15275" "checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" +"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum core-foundation 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "25bfd746d203017f7d5cbd31ee5d8e17f94b6521c7af77ece6c9e4b2d4b16c67" "checksum core-foundation-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "065a5d7ffdcbc8fa145d6f0746f3555025b9097a9e9cda59f7467abae670c78d" "checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" @@ -939,7 +969,6 @@ dependencies = [ "checksum miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "609ce024854aeb19a0ef7567d348aaa5a746b32fb72e336df7fcc16869d7e2b4" "checksum miniz_oxide 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9ba430291c9d6cedae28bcd2d49d1c32fc57d60cd49086646c5dd5673a870eb5" "checksum miniz_oxide_c_api 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5a5b8234d6103ebfba71e29786da4608540f862de5ce980a1c94f86a40ca0d51" -"checksum mkstemp-rs 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ab06da7d0a30c709867eb54e757f86b69e3b4dd4ac3c0f9502edec4e077a604e" "checksum msdos_time 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "aad9dfe950c057b1bfe9c1f2aa51583a8468ef2a5baba2ebbe06d775efeb7729" "checksum native-tls 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f74dbadc8b43df7864539cedb7bc91345e532fdd913cfdc23ad94f4d2d40fbc0" "checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" @@ -949,9 +978,11 @@ dependencies = [ "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum pkg-config 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "104630aa1c83213cbc76db0703630fcb0421dac3585063be4ce9a8a2feeaa745" "checksum podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "780fb4b6698bbf9cf2444ea5d22411cef2953f0824b98f33cf454ec5615645bd" -"checksum proc-macro2 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "762eea716b821300a86da08870a64b597304866ceb9f54a11d67b4cf56459c6a" +"checksum proc-macro2 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "7a17a4d77bc20d344179de803a34694c0ac7a0b3fb4384bee99783215a8e0410" "checksum quote 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ed7d650913520df631972f21e104a4fa2f9c82a14afc65d17b388a2e29731e7c" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" +"checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c" +"checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum regex 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5bbbea44c5490a1e84357ff28b7d518b4619a159fed5d25f6c1de2d19cc42814" @@ -969,6 +1000,7 @@ dependencies = [ "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum syn 0.14.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b7bfcbb0c068d0f642a0ffbd5c604965a360a61f99e8add013cef23a838614f3" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" +"checksum tempfile 3.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c4b103c6d08d323b92ff42c8ce62abcd83ca8efa7fd5bf7927efefec75f58c76" "checksum termcolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "722426c4a0539da2c4ffd9b419d90ad540b4cff4a053be9069c908d4d07e2836" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" diff --git a/Cargo.toml b/Cargo.toml index 8ce7a90463..559b8d6fe6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ fs2 = "^0.4" hyper = "^0.10" hyper-native-tls = "^0.2" libc = "^0.2" -mkstemp-rs = "^1.0.0" +tempfile = "^3.0" md-5 = "^0.7" sha2 = "^0.7" serde = "^1.0" diff --git a/src/driver.rs b/src/driver.rs index cd2acfffc3..f488df52af 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -16,7 +16,6 @@ use std::collections::{HashMap, HashSet}; use std::ffi::{OsStr, OsString}; use std::fs::File; use std::io::Write; -use std::os::unix::ffi::OsStrExt; use std::path::{Path, PathBuf}; use digest::DigestData; @@ -593,7 +592,7 @@ impl ProcessingSession { ctry!(write!(mf_dest, ": "); "couldn't write to Makefile-rules file"); if let Some(ref pip) = self.primary_input_path { - ctry!(mf_dest.write_all(pip.as_os_str().as_bytes()); "couldn't write to Makefile-rules file"); + ctry!(mf_dest.write_all(pip.to_string_lossy().as_ref().as_bytes()); "couldn't write to Makefile-rules file"); } for (name, info) in &self.events.0 { diff --git a/src/engines/mod.rs b/src/engines/mod.rs index 2c4ed1030e..98d530e276 100644 --- a/src/engines/mod.rs +++ b/src/engines/mod.rs @@ -18,9 +18,9 @@ use md5::{Md5, Digest}; use libc; use std::ffi::{CStr, OsStr, OsString}; use std::io::{Read, SeekFrom, Write}; -use std::os::unix::ffi::OsStrExt; use std::path::Path; use std::{io, ptr, slice}; +use std::borrow::Cow; use digest::DigestData; use errors::{Error, ErrorKind, Result}; @@ -41,6 +41,16 @@ pub use self::tex::TexEngine; pub use self::xdvipdfmx::XdvipdfmxEngine; +#[cfg(unix)] +fn osstr_from_cstr(s: &CStr) -> Cow { + use std::os::unix::ffi::OsStrExt; + Cow::Borrowed(OsStr::from_bytes(s.to_bytes())) +} +#[cfg(windows)] +fn osstr_from_cstr(s: &CStr) -> Cow { + Cow::Owned(OsString::from(s.to_string_lossy().to_owned().to_string())) +} + // Now, the public API. /// The IoEventBackend trait allows the program driving the TeX engines to @@ -478,10 +488,10 @@ fn issue_error<'a, I: 'a + IoProvider>(es: *mut ExecutionState<'a, I>, text: *co fn get_file_md5<'a, I: 'a + IoProvider>(es: *mut ExecutionState<'a, I>, path: *const libc::c_char, digest: *mut u8) -> libc::c_int { let es = unsafe { &mut *es }; - let rpath = OsStr::from_bytes(unsafe { CStr::from_ptr(path) }.to_bytes()); + let rpath = osstr_from_cstr(unsafe { CStr::from_ptr(path) }); let rdest = unsafe { slice::from_raw_parts_mut(digest, 16) }; - if es.get_file_md5(rpath, rdest) { + if es.get_file_md5(rpath.as_ref(), rdest) { 1 } else { 0 @@ -503,7 +513,7 @@ fn get_data_md5<'a, I: 'a + IoProvider>(_es: *mut ExecutionState<'a, I>, data: * fn output_open<'a, I: 'a + IoProvider>(es: *mut ExecutionState<'a, I>, name: *const libc::c_char, is_gz: libc::c_int) -> *const libc::c_void { let es = unsafe { &mut *es }; - let rname = OsStr::from_bytes(unsafe { CStr::from_ptr(name) }.to_bytes()); + let rname = osstr_from_cstr(&unsafe { CStr::from_ptr(name) }); let ris_gz = is_gz != 0; es.output_open(&rname, ris_gz) as *const _ @@ -571,7 +581,7 @@ fn output_close<'a, I: 'a + IoProvider>(es: *mut ExecutionState<'a, I>, handle: fn input_open<'a, I: 'a + IoProvider>(es: *mut ExecutionState<'a, I>, name: *const libc::c_char, format: libc::c_int, is_gz: libc::c_int) -> *const libc::c_void { let es = unsafe { &mut *es }; - let rname = OsStr::from_bytes(unsafe { CStr::from_ptr(name) }.to_bytes()); + let rname = osstr_from_cstr(unsafe { CStr::from_ptr(name) }); let rformat = c_format_to_rust(format); let ris_gz = is_gz != 0; diff --git a/src/io/format_cache.rs b/src/io/format_cache.rs index b449748563..81e518b3d5 100644 --- a/src/io/format_cache.rs +++ b/src/io/format_cache.rs @@ -5,9 +5,8 @@ //! Code for locally caching compiled format files. -use mkstemp; +use tempfile; use std::ffi::{OsStr}; -use std::fs; use std::io::{BufReader, Write}; use std::path::PathBuf; @@ -82,15 +81,15 @@ impl IoProvider for FormatCache { fn write_format(&mut self, name: &str, data: &[u8], _status: &mut StatusBackend) -> Result<()> { let final_path = self.path_for_format(OsStr::new(name))?; - let mut templ = self.formats_base.clone(); - templ.push("format_XXXXXX"); + let mut temp_dest = tempfile::Builder::new() + .prefix("format_") + .rand_bytes(6) + .tempfile_in(&self.formats_base)?; - let temp_path = { - let mut temp_dest = mkstemp::TempFile::new(&templ.to_string_lossy(), false)?; - temp_dest.write_all(data)?; - temp_dest.path().to_owned() - }; - - fs::rename(&temp_path, &final_path).map_err(|e| e.into()) + temp_dest.write_all(data)?; + + temp_dest.persist(&final_path).map_err(|e| e.error)?; + + Ok(()) } } diff --git a/src/io/local_cache.rs b/src/io/local_cache.rs index aada065462..86af8671fd 100644 --- a/src/io/local_cache.rs +++ b/src/io/local_cache.rs @@ -3,7 +3,7 @@ // Licensed under the MIT License. use fs2::FileExt; -use mkstemp; +use tempfile; use std::collections::HashMap; use std::ffi::{OsStr, OsString}; use std::fs::{self, File}; @@ -264,34 +264,30 @@ impl LocalCache { let mut digest_builder = digest::create(); let mut length = 0; - let temp_path = { - let mut templ = self.data_path.clone(); - templ.push("download_XXXXXX"); - - let mut temp_dest = match mkstemp::TempFile::new(&templ.to_string_lossy(), false) { - Ok(f) => f, - Err(e) => return OpenResult::Err(e.into()), - }; - - let mut buf = [0u8; 8192]; - - while let Ok(nbytes) = stream.read(&mut buf) { - if nbytes == 0 { - break; - } + let mut temp_dest = match tempfile::Builder::new() + .prefix("download_") + .rand_bytes(6) + .tempfile_in(&self.data_path) { + Ok(f) => f, + Err(e) => return OpenResult::Err(e.into()), + }; - length += nbytes; - let chunk = &buf[..nbytes]; + let mut buf = [0u8; 8192]; - digest_builder.input(chunk); - if let Err(e) = temp_dest.write_all(chunk) { - return OpenResult::Err(e.into()); - } - } + while let Ok(nbytes) = stream.read(&mut buf) { + if nbytes == 0 { + break; + } - temp_dest.path().to_owned() - }; + length += nbytes; + let chunk = &buf[..nbytes]; + digest_builder.input(chunk); + if let Err(e) = temp_dest.write_all(chunk) { + return OpenResult::Err(e.into()); + } + } + let digest = DigestData::from(digest_builder); // Now we can move it to its final destination .. @@ -301,9 +297,9 @@ impl LocalCache { Err(e) => return OpenResult::Err(e.into()), }; - if let Err(e) = fs::rename(&temp_path, &final_path) { - return OpenResult::Err(e.into()); - } + if let Err(e) = temp_dest.persist(&final_path) { + return OpenResult::Err(e.error.into()); + }; // Make the file readonly once it's at its final path. // XXX: It would be better to set these using the already-open file handle owned by the diff --git a/src/lib.rs b/src/lib.rs index 3b5a91b550..e2e68c6bcd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -41,7 +41,7 @@ extern crate hyper; extern crate hyper_native_tls; extern crate libc; extern crate md5; -extern crate mkstemp; +extern crate tempfile; #[macro_use] extern crate serde_derive; extern crate serde; extern crate sha2; diff --git a/tectonic/TECkit_Engine.h b/tectonic/TECkit_Engine.h index 4152ee203b..4ab54243a1 100644 --- a/tectonic/TECkit_Engine.h +++ b/tectonic/TECkit_Engine.h @@ -79,6 +79,10 @@ extern "C" { #ifdef _WIN32 /* MS compiler has predefined _WIN32, so assume Windows target */ +#ifdef INPUT +#undef INPUT +#endif + #include #undef WINAPI #define WINAPI diff --git a/tectonic/XeTeX_web.h b/tectonic/XeTeX_web.h index 7fd6a185ae..d274be242c 100644 --- a/tectonic/XeTeX_web.h +++ b/tectonic/XeTeX_web.h @@ -39,6 +39,10 @@ authorization from the copyright holders. #include "xetex-core.h" #include "XeTeX_ext.h" +#ifndef M_PI +#define M_PI 3.14159265358979323846264338327950288 +#endif + BEGIN_EXTERN_C void print_nl(int s); diff --git a/tectonic/bibtex.c b/tectonic/bibtex.c index 92af4a0dbf..353d5d772f 100644 --- a/tectonic/bibtex.c +++ b/tectonic/bibtex.c @@ -1,6 +1,9 @@ #include "bibtex.h" #include "internals.h" +/* hack: the name eof conflicts with other function declarations under mingw. */ +#define eof tectonic_eof + /* (Re)Allocate N items of type T using xmalloc/xrealloc. */ #define XTALLOC(n, t) (xmalloc ((n) * sizeof (t))) diff --git a/tectonic/dpx-pdfdoc.c b/tectonic/dpx-pdfdoc.c index 7cde825db3..9c50bf553a 100644 --- a/tectonic/dpx-pdfdoc.c +++ b/tectonic/dpx-pdfdoc.c @@ -59,6 +59,14 @@ #define PDFDOC_ARTICLE_ALLOC_SIZE 16 #define PDFDOC_BEAD_ALLOC_SIZE 16 +#ifdef _WIN32 +#define tectonic_gmtime_r(a, b) gmtime_s(b, a) +#define tectonic_localtime_r(a, b) localtime_s(b, a) +#else +#define tectonic_gmtime_r(a, b) gmtime_r(a, b) +#define tectonic_localtime_r(a, b) localtime_r(a, b) +#endif + static int verbose = 0; static char manual_thumb_enabled = 0; @@ -436,8 +444,8 @@ compute_timezone_offset(void) now = get_unique_time_if_given(); if (now == INVALID_EPOCH_VALUE) { now = time(NULL); - localtime_r(&now, &local); - gmtime_r(&now, &tm); + tectonic_localtime_r(&now, &local); + tectonic_gmtime_r(&now, &tm); return (mktime(&local) - mktime(&tm)); } else { return(0); diff --git a/tectonic/xetexini.c b/tectonic/xetexini.c index e982168689..540c884f01 100644 --- a/tectonic/xetexini.c +++ b/tectonic/xetexini.c @@ -4398,33 +4398,33 @@ tt_run_engine(char *dump_name, char *input_file_name) trie_ptr = 0; trie_r[0] = 0; hyph_start = 0; - font_mapping = xmalloc_array(void *, font_max); - font_layout_engine = xmalloc_array(void *, font_max); - font_flags = xmalloc_array(char, font_max); - font_letter_space = xmalloc_array(scaled_t, font_max); - font_check = xmalloc_array(b16x4, font_max); - font_size = xmalloc_array(scaled_t, font_max); - font_dsize = xmalloc_array(scaled_t, font_max); - font_params = xmalloc_array(font_index, font_max); - font_name = xmalloc_array(str_number, font_max); - font_area = xmalloc_array(str_number, font_max); - font_bc = xmalloc_array(UTF16_code, font_max); - font_ec = xmalloc_array(UTF16_code, font_max); - font_glue = xmalloc_array(int32_t, font_max); - hyphen_char = xmalloc_array(int32_t, font_max); - skew_char = xmalloc_array(int32_t, font_max); - bchar_label = xmalloc_array(font_index, font_max); - font_bchar = xmalloc_array(nine_bits, font_max); - font_false_bchar = xmalloc_array(nine_bits, font_max); - char_base = xmalloc_array(int32_t, font_max); - width_base = xmalloc_array(int32_t, font_max); - height_base = xmalloc_array(int32_t, font_max); - depth_base = xmalloc_array(int32_t, font_max); - italic_base = xmalloc_array(int32_t, font_max); - lig_kern_base = xmalloc_array(int32_t, font_max); - kern_base = xmalloc_array(int32_t, font_max); - exten_base = xmalloc_array(int32_t, font_max); - param_base = xmalloc_array(int32_t, font_max); + font_mapping = xcalloc_array(void *, font_max); + font_layout_engine = xcalloc_array(void *, font_max); + font_flags = xcalloc_array(char, font_max); + font_letter_space = xcalloc_array(scaled_t, font_max); + font_check = xcalloc_array(b16x4, font_max); + font_size = xcalloc_array(scaled_t, font_max); + font_dsize = xcalloc_array(scaled_t, font_max); + font_params = xcalloc_array(font_index, font_max); + font_name = xcalloc_array(str_number, font_max); + font_area = xcalloc_array(str_number, font_max); + font_bc = xcalloc_array(UTF16_code, font_max); + font_ec = xcalloc_array(UTF16_code, font_max); + font_glue = xcalloc_array(int32_t, font_max); + hyphen_char = xcalloc_array(int32_t, font_max); + skew_char = xcalloc_array(int32_t, font_max); + bchar_label = xcalloc_array(font_index, font_max); + font_bchar = xcalloc_array(nine_bits, font_max); + font_false_bchar = xcalloc_array(nine_bits, font_max); + char_base = xcalloc_array(int32_t, font_max); + width_base = xcalloc_array(int32_t, font_max); + height_base = xcalloc_array(int32_t, font_max); + depth_base = xcalloc_array(int32_t, font_max); + italic_base = xcalloc_array(int32_t, font_max); + lig_kern_base = xcalloc_array(int32_t, font_max); + kern_base = xcalloc_array(int32_t, font_max); + exten_base = xcalloc_array(int32_t, font_max); + param_base = xcalloc_array(int32_t, font_max); font_ptr = FONT_BASE; fmem_ptr = 7; font_name[FONT_BASE] = maketexstring("nullfont");