More windows compat

[ci skip]
This commit is contained in:
Alex Crichton 2015-09-10 20:57:14 -07:00
parent 45ae2f4cd0
commit 7da9b10fc6
2 changed files with 34 additions and 17 deletions

View File

@ -74,10 +74,14 @@ impl<'a> TestGenerator<'a> {
}
if self.target.contains("windows") {
base.push("winsock2.h");
base.push("ws2ipdef.h");
base.push("windows.h");
base.push("winsock2.h"); // must be before windows.h
base.push("direct.h");
base.push("io.h");
base.push("sys/utime.h");
base.push("windows.h");
base.push("process.h");
base.push("ws2ipdef.h");
} else {
base.push("ctype.h");
base.push("dirent.h");
@ -131,6 +135,8 @@ impl<'a> TestGenerator<'a> {
t.to_string()
} else if windows && t == "stat" {
"struct __stat64".to_string()
} else if windows && t == "utimbuf" {
"struct __utimbuf64".to_string()
} else {
format!("struct {}", t)
}
@ -247,7 +253,8 @@ fn main() {
if tg.target.contains("msvc") {
cfg.flag("/W3").flag("/Wall").flag("/WX")
.flag("/wd4820") // weird warning about adding padding?
.flag("/wd4100"); // don't warn about unused parameters
.flag("/wd4100") // don't warn about unused parameters
.flag("/wd4996"); // don't warn about deprecated functions
} else {
cfg.flag("-Wall").flag("-Wextra").flag("-Werror")
.flag("-Wno-unused-parameter");
@ -378,13 +385,15 @@ impl<'a> TestGenerator<'a> {
"#, ty = rust_ty, name = name));
}
fn test_extern_fn(&mut self, name: &str, args: &[String], ret: &str,
fn test_extern_fn(&mut self, name: &str, cname: &str,
args: &[String], ret: &str,
variadic: bool) {
match name {
// manually verified
"execv" |
"execve" |
"execvp" |
"execvpe" |
"glob" |
"getrlimit" |
"setrlimit" |
@ -401,11 +410,12 @@ impl<'a> TestGenerator<'a> {
let cret = self.rust_ty_to_c_ty(ret);
t!(writeln!(self.c, r#"
{ret} (*__test_fn_{name}(void))({args}) {{
return {name};
return {cname};
}}
"#, name = name, args = args, ret = cret));
"#, name = name, cname = cname, args = args, ret = cret));
t!(writeln!(self.rust, r#"
#[test]
#[cfg_attr(windows, ignore)] // FIXME -- dllimport weirdness?
fn fn_{name}() {{
extern {{
fn __test_fn_{name}() -> size_t;
@ -497,7 +507,14 @@ impl<'a, 'v> Visitor<'v> for TestGenerator<'a> {
ast::ForeignItemFn(ref decl, ref generics) => {
self.assert_no_generics(i.ident, generics);
let (ret, args, variadic) = self.decl2rust(decl);
self.test_extern_fn(&i.ident.to_string(), &args, &ret,
let cname = match attr::first_attr_value_str_by_name(&i.attrs,
"link_name") {
Some(ref i) if !i.to_string().contains("$") => {
i.to_string()
}
_ => i.ident.to_string(),
};
self.test_extern_fn(&i.ident.to_string(), &cname, &args, &ret,
variadic);
}
ast::ForeignItemStatic(_, _) => {

View File

@ -12,6 +12,7 @@
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/",
html_playground_url = "https://play.rust-lang.org/")]
#![feature(linked_from)]
//! Bindings for the C standard library and other platform libraries
//!
@ -5397,6 +5398,8 @@ pub mod funcs {
use types::os::arch::c95::{c_long, c_uint, c_ulong};
use types::os::arch::c95::{size_t};
#[linked_from = "kernel32"]
#[link(name = "kernel32")]
extern {
pub fn abs(i: c_int) -> c_int;
pub fn labs(i: c_long) -> c_long;
@ -5527,11 +5530,9 @@ pub mod funcs {
use types::os::arch::c95::{c_int, c_char, wchar_t};
extern {
#[link_name = "_open"]
pub fn open(path: *const c_char, oflag: c_int, mode: c_int)
-> c_int;
pub fn open(path: *const c_char, oflag: c_int, ...) -> c_int;
#[link_name = "_wopen"]
pub fn wopen(path: *const wchar_t, oflag: c_int, mode: c_int)
-> c_int;
pub fn wopen(path: *const wchar_t, oflag: c_int, ...) -> c_int;
#[link_name = "_creat"]
pub fn creat(path: *const c_char, mode: c_int) -> c_int;
}
@ -5543,8 +5544,7 @@ pub mod funcs {
pub mod unistd {
use types::common::c95::c_void;
use types::os::arch::c95::{c_int, c_uint, c_char,
c_long, size_t};
use types::os::arch::c95::{c_int, c_uint, c_char, c_long};
use types::os::arch::c99::intptr_t;
extern {
@ -5572,7 +5572,7 @@ pub mod funcs {
pub fn execvpe(c: *const c_char, argv: *const *const c_char,
envp: *const *const c_char) -> c_int;
#[link_name = "_getcwd"]
pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char;
pub fn getcwd(buf: *mut c_char, size: c_int) -> *mut c_char;
#[link_name = "_getpid"]
pub fn getpid() -> c_int;
#[link_name = "_isatty"]
@ -6480,7 +6480,7 @@ pub mod funcs {
}
pub mod msvcrt {
use types::os::arch::c95::{c_int, c_long};
use types::os::arch::c95::c_int;
use types::os::arch::c99::intptr_t;
extern {
@ -6488,7 +6488,7 @@ pub mod funcs {
pub fn commit(fd: c_int) -> c_int;
#[link_name = "_get_osfhandle"]
pub fn get_osfhandle(fd: c_int) -> c_long;
pub fn get_osfhandle(fd: c_int) -> intptr_t;
#[link_name = "_open_osfhandle"]
pub fn open_osfhandle(osfhandle: intptr_t,