Skip to content

Fix building under windows targets. #210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -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%
62 changes: 47 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
20 changes: 15 additions & 5 deletions src/engines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -41,6 +41,16 @@ pub use self::tex::TexEngine;
pub use self::xdvipdfmx::XdvipdfmxEngine;


#[cfg(unix)]
fn osstr_from_cstr(s: &CStr) -> Cow<OsStr> {
use std::os::unix::ffi::OsStrExt;
Cow::Borrowed(OsStr::from_bytes(s.to_bytes()))
}
#[cfg(windows)]
fn osstr_from_cstr(s: &CStr) -> Cow<OsStr> {
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
Expand Down Expand Up @@ -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
Expand All @@ -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 _
Expand Down Expand Up @@ -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;

Expand Down
21 changes: 10 additions & 11 deletions src/io/format_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(())
}
}
Loading