Skip to content

Commit 0527095

Browse files
committed
Fix building under windows-gnu target.
1 parent 8a29132 commit 0527095

File tree

11 files changed

+120
-64
lines changed

11 files changed

+120
-64
lines changed

Cargo.lock

+47-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fs2 = "^0.4"
4747
hyper = "^0.10"
4848
hyper-native-tls = "^0.2"
4949
libc = "^0.2"
50-
mkstemp-rs = "^1.0.0"
50+
tempfile = "^3.0"
5151
md-5 = "^0.7"
5252
sha2 = "^0.7"
5353
serde = "^1.0"

src/driver.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use std::collections::{HashMap, HashSet};
1616
use std::ffi::{OsStr, OsString};
1717
use std::fs::File;
1818
use std::io::Write;
19-
use std::os::unix::ffi::OsStrExt;
2019
use std::path::{Path, PathBuf};
2120

2221
use digest::DigestData;
@@ -593,7 +592,7 @@ impl ProcessingSession {
593592
ctry!(write!(mf_dest, ": "); "couldn't write to Makefile-rules file");
594593

595594
if let Some(ref pip) = self.primary_input_path {
596-
ctry!(mf_dest.write_all(pip.as_os_str().as_bytes()); "couldn't write to Makefile-rules file");
595+
ctry!(mf_dest.write_all(pip.to_string_lossy().as_ref().as_bytes()); "couldn't write to Makefile-rules file");
597596
}
598597

599598
for (name, info) in &self.events.0 {

src/engines/mod.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ use md5::{Md5, Digest};
1818
use libc;
1919
use std::ffi::{CStr, OsStr, OsString};
2020
use std::io::{Read, SeekFrom, Write};
21-
use std::os::unix::ffi::OsStrExt;
2221
use std::path::Path;
2322
use std::{io, ptr, slice};
23+
use std::borrow::Cow;
2424

2525
use digest::DigestData;
2626
use errors::{Error, ErrorKind, Result};
@@ -41,6 +41,16 @@ pub use self::tex::TexEngine;
4141
pub use self::xdvipdfmx::XdvipdfmxEngine;
4242

4343

44+
#[cfg(unix)]
45+
fn osstr_from_cstr(s: &CStr) -> Cow<OsStr> {
46+
use std::os::unix::ffi::OsStrExt;
47+
OsStr::from_bytes(s.to_bytes()).into()
48+
}
49+
#[cfg(windows)]
50+
fn osstr_from_cstr(s: &CStr) -> Cow<OsStr> {
51+
Cow::Owned(OsString::from(s.to_string_lossy().to_owned().to_string()))
52+
}
53+
4454
// Now, the public API.
4555

4656
/// 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
478488

479489
fn get_file_md5<'a, I: 'a + IoProvider>(es: *mut ExecutionState<'a, I>, path: *const libc::c_char, digest: *mut u8) -> libc::c_int {
480490
let es = unsafe { &mut *es };
481-
let rpath = OsStr::from_bytes(unsafe { CStr::from_ptr(path) }.to_bytes());
491+
let rpath = osstr_from_cstr(unsafe { CStr::from_ptr(path) });
482492
let rdest = unsafe { slice::from_raw_parts_mut(digest, 16) };
483493

484-
if es.get_file_md5(rpath, rdest) {
494+
if es.get_file_md5(rpath.as_ref(), rdest) {
485495
1
486496
} else {
487497
0
@@ -503,7 +513,7 @@ fn get_data_md5<'a, I: 'a + IoProvider>(_es: *mut ExecutionState<'a, I>, data: *
503513

504514
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 {
505515
let es = unsafe { &mut *es };
506-
let rname = OsStr::from_bytes(unsafe { CStr::from_ptr(name) }.to_bytes());
516+
let rname = osstr_from_cstr(&unsafe { CStr::from_ptr(name) });
507517
let ris_gz = is_gz != 0;
508518

509519
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:
571581

572582
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 {
573583
let es = unsafe { &mut *es };
574-
let rname = OsStr::from_bytes(unsafe { CStr::from_ptr(name) }.to_bytes());
584+
let rname = osstr_from_cstr(unsafe { CStr::from_ptr(name) });
575585
let rformat = c_format_to_rust(format);
576586
let ris_gz = is_gz != 0;
577587

src/io/format_cache.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
//! Code for locally caching compiled format files.
77
8-
use mkstemp;
8+
use tempfile;
99
use std::ffi::{OsStr};
1010
use std::fs;
1111
use std::io::{BufReader, Write};
@@ -82,15 +82,15 @@ impl IoProvider for FormatCache {
8282
fn write_format(&mut self, name: &str, data: &[u8], _status: &mut StatusBackend) -> Result<()> {
8383
let final_path = self.path_for_format(OsStr::new(name))?;
8484

85-
let mut templ = self.formats_base.clone();
86-
templ.push("format_XXXXXX");
85+
let mut temp_dest = tempfile::Builder::new()
86+
.prefix("format_")
87+
.rand_bytes(6)
88+
.tempfile_in(&self.formats_base)?;
8789

88-
let temp_path = {
89-
let mut temp_dest = mkstemp::TempFile::new(&templ.to_string_lossy(), false)?;
90-
temp_dest.write_all(data)?;
91-
temp_dest.path().to_owned()
92-
};
93-
94-
fs::rename(&temp_path, &final_path).map_err(|e| e.into())
90+
temp_dest.write_all(data)?;
91+
92+
temp_dest.persist(&final_path).map_err(|e| e.error)?;
93+
94+
Ok(())
9595
}
9696
}

src/io/local_cache.rs

+24-28
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Licensed under the MIT License.
44

55
use fs2::FileExt;
6-
use mkstemp;
6+
use tempfile;
77
use std::collections::HashMap;
88
use std::ffi::{OsStr, OsString};
99
use std::fs::{self, File};
@@ -257,34 +257,30 @@ impl<B: Bundle> LocalCache<B> {
257257
let mut digest_builder = digest::create();
258258
let mut length = 0;
259259

260-
let temp_path = {
261-
let mut templ = self.data_path.clone();
262-
templ.push("download_XXXXXX");
263-
264-
let mut temp_dest = match mkstemp::TempFile::new(&templ.to_string_lossy(), false) {
265-
Ok(f) => f,
266-
Err(e) => return OpenResult::Err(e.into()),
267-
};
268-
269-
let mut buf = [0u8; 8192];
270-
271-
while let Ok(nbytes) = stream.read(&mut buf) {
272-
if nbytes == 0 {
273-
break;
274-
}
260+
let mut temp_dest = match tempfile::Builder::new()
261+
.prefix("download_")
262+
.rand_bytes(6)
263+
.tempfile_in(&self.data_path) {
264+
Ok(f) => f,
265+
Err(e) => return OpenResult::Err(e.into()),
266+
};
275267

276-
length += nbytes;
277-
let chunk = &buf[..nbytes];
268+
let mut buf = [0u8; 8192];
278269

279-
digest_builder.input(chunk);
280-
if let Err(e) = temp_dest.write_all(chunk) {
281-
return OpenResult::Err(e.into());
282-
}
283-
}
270+
while let Ok(nbytes) = stream.read(&mut buf) {
271+
if nbytes == 0 {
272+
break;
273+
}
284274

285-
temp_dest.path().to_owned()
286-
};
275+
length += nbytes;
276+
let chunk = &buf[..nbytes];
287277

278+
digest_builder.input(chunk);
279+
if let Err(e) = temp_dest.write_all(chunk) {
280+
return OpenResult::Err(e.into());
281+
}
282+
}
283+
288284
let digest = DigestData::from(digest_builder);
289285

290286
// Now we can move it to its final destination ..
@@ -294,9 +290,9 @@ impl<B: Bundle> LocalCache<B> {
294290
Err(e) => return OpenResult::Err(e.into()),
295291
};
296292

297-
if let Err(e) = fs::rename(&temp_path, &final_path) {
298-
return OpenResult::Err(e.into());
299-
}
293+
if let Err(e) = temp_dest.persist(&final_path) {
294+
return OpenResult::Err(e.error.into());
295+
};
300296

301297
// Make the file readonly once it's at its final path.
302298
// XXX: It would be better to set these using the already-open file handle owned by the

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extern crate hyper;
4141
extern crate hyper_native_tls;
4242
extern crate libc;
4343
extern crate md5;
44-
extern crate mkstemp;
44+
extern crate tempfile;
4545
#[macro_use] extern crate serde_derive;
4646
extern crate serde;
4747
extern crate sha2;

tectonic/TECkit_Engine.h

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ extern "C" {
7979

8080
#ifdef _WIN32
8181
/* MS compiler has predefined _WIN32, so assume Windows target */
82+
#ifdef INPUT
83+
#undef INPUT
84+
#endif
85+
8286
#include <windows.h>
8387
#undef WINAPI
8488
#define WINAPI

tectonic/XeTeX_web.h

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ authorization from the copyright holders.
3939
#include "xetex-core.h"
4040
#include "XeTeX_ext.h"
4141

42+
#ifndef M_PI
43+
#define M_PI 3.14159265358979323846264338327950288
44+
#endif
45+
4246
BEGIN_EXTERN_C
4347

4448
void print_nl(int s);

tectonic/bibtex.c

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "bibtex.h"
22
#include "internals.h"
33

4+
/* hack: the name eof conflicts with other function declarations under mingw. */
5+
#define eof tectonic_eof
6+
47
/* (Re)Allocate N items of type T using xmalloc/xrealloc. */
58
#define XTALLOC(n, t) (xmalloc ((n) * sizeof (t)))
69

0 commit comments

Comments
 (0)