Commit 39baaacf authored by Yonggang Luo's avatar Yonggang Luo
Browse files

Getting c source and header to be compiled with msvc.

parent 84898d78
......@@ -53,12 +53,21 @@ fn main() {
generate_bindings(&p);
});
cc::Build::new()
.flag("-nostdinc")
.flag("-nostdlib")
.include(&format!("{}/include", crate_dir))
.flag("-fno-stack-protector")
.flag("-Wno-expansion-to-defined")
let mut build = cc::Build::new();
let compiler = build.get_compiler();
if compiler.is_like_msvc() {
build.ar_flag("-NODEFAULTLIB"); // Skip all default lib
} else {
build
.flag("-nostdinc")
.flag("-nostdlib")
.flag("-fno-stack-protector")
.flag("-Wno-expansion-to-defined")
.include(&format!("{}/include", crate_dir))
.include(&format!("{}/target/include", crate_dir));
}
build
.files(
fs::read_dir("src/c")
.expect("src/c directory missing")
......@@ -68,3 +77,8 @@ fn main() {
println!("cargo:rustc-link-lib=static=rulibc_c");
}
//
// cargo b -Zbuild-std=core --target x86_64-pc-windows-msvc
// cargo b
// cl /MD kernel32.lib target\debug\rulibc.lib examples\test.c -X -Iinclude -Itarget\include -link -NODEFAULTLIB
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <setjmp.h>
int main(int argc, char* argv) {
jmp_buf buf;
float f = 1000.0f;
double d = 1000000000.0;
long double ld = 100000.0f;
int32_t i32f = (int32_t)f;
int32_t i32d = (int32_t)d;
uint32_t u32f = (uint32_t)f;
uint32_t u32d = (uint32_t)d;
int64_t i64f = (int64_t)f;
int64_t i64d = (int64_t)d;
uint64_t u64f = (uint64_t)f;
uint64_t u64d = (uint64_t)d;
f = (float)i32f;
d = (double)i32d;
f = (float)u32f;
d = (double)u32d;
f = (float)i64f;
d = (double)i64d;
f = (float)u64f;
d = (double)u64d;
ld = (long double)u64d;
printf("Hello, the world %.10Lf\n", ld);
setjmp(buf);
}
\ No newline at end of file
#ifndef _ALLOCA_H
#define _ALLOCA_H
#include <stddef.h>
#define alloca(size) __builtin_alloca (size)
#endif /* _ALLOCA_H */
#ifndef _BITS_ERRNO_H
#define _BITS_ERRNO_H
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
......
......@@ -2,6 +2,12 @@
#define _BITS_WCHAR_H
#include <stdint.h>
#if defined(_MSC_VER)
#include "wchar_rulibc_msvc.h"
#else
#define WEOF (0xffffffffu)
#define WCHAR_MIN (0)
#define WCHAR_MAX (0x7fffffff)
......@@ -11,4 +17,6 @@
#define __need_wint_t
#define __need_NULL
#endif
#endif /* _BITS_WCHAR_H */
#ifndef _BITS_WCHAR_H
#define _BITS_WCHAR_H
#define WEOF (0xffff)
#define __need_size_t
#define __need_wchar_t
#define __need_wint_t
#define __need_NULL
#endif /* _BITS_WCHAR_H */
#include <stddef.h>
#include <openlibm_complex.h>
......@@ -6,6 +6,8 @@
#ifndef _FEATURES_H
#define _FEATURES_H
#include <stddef.h>
#if __STDC_VERSION__ >= 199901L
#define __restrict restrict
#elif !defined(__GNUC__)
......
#include <stddef.h>
#include <openlibm_fenv.h>
#undef complex
#undef I
#include <stddef.h>
#include <openlibm_math.h>
// Included to fix mesa issues
......
#include <stddef.h>
#include <string.h>
#ifndef _SETJMP_H
#define _SETJMP_H
#include <stddef.h>
#if defined(_WIN32)
#if defined(__i386__) || defined(_X86_) || defined(_M_IX86)
typedef unsigned long long jmp_buf[8];
#endif
#if defined(__x86_64__) || defined(_AMD64_) || defined(_M_X64)
typedef unsigned long jmp_buf[8];
#endif
#else
#ifdef __aarch64__
typedef unsigned long jmp_buf[22];
#endif
......@@ -61,6 +75,8 @@ typedef unsigned long long jmp_buf[8];
typedef unsigned long jmp_buf[8];
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
......
#ifndef _STDARG_H
#define _STDARG_H
#include <stddef.h>
#if defined(_MSC_VER)
#include "stdarg_rulibc_msvc.h"
#else
typedef __builtin_va_list va_list;
#define va_start(v,l) __builtin_va_start(v,l)
#define va_end(v) __builtin_va_end(v)
#define va_arg(v,l) __builtin_va_arg(v,l)
#define va_copy(d,s) __builtin_va_copy(d,s)
#endif
#endif /* _STDARG_H */
typedef char* va_list;
void __cdecl __va_start(va_list* , ...);
#define va_start(ap, x) ((void)(__va_start(&ap, x)))
#define va_arg(ap, t) \
((sizeof(t) > sizeof(__int64) || (sizeof(t) & (sizeof(t) - 1)) != 0) \
? **(t**)((ap += sizeof(__int64)) - sizeof(__int64)) \
: *(t* )((ap += sizeof(__int64)) - sizeof(__int64)))
#define va_end(ap) ((void)(ap = (va_list)0))
#define va_copy(destination, source) ((destination) = (source))
#ifndef _STDBOOL_H
#define _STDBOOL_H
#include <stddef.h>
#ifndef __cplusplus
typedef _Bool bool;
#define true 1
......
#ifndef _STDDEF_H
#define _STDDEF_H
#include <stdint.h>
#include "sys/__shared_header_rulibc.h"
#if defined(_MSC_VER)
#include "stddef_rulibc_msvc.h"
#else
#define NULL 0
......@@ -10,9 +17,9 @@
typedef __PTRDIFF_TYPE__ ptrdiff_t;
#ifndef __cplusplus
typedef int32_t wchar_t;
typedef int wchar_t;
#endif /* #ifndef __cplusplus */
typedef int32_t wint_t;
typedef int wint_t;
typedef long unsigned int size_t;
......@@ -21,4 +28,6 @@ typedef struct { long long __ll; long double __ld; } max_align_t;
#define offsetof(type, member) __builtin_offsetof(type, member)
#endif
#endif /* _STDDEF_H */
/* Define NULL pointer value and the offset() macro */
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *)0)
#endif
#endif
/* TODO: support for 32 bit */
#ifndef _PTRDIFF_T_DEFINED
#define __PTRDIFF_TYPE__ long long int
typedef __PTRDIFF_TYPE__ ptrdiff_t;
#define _PTRDIFF_T_DEFINED
#endif
#ifndef _SIZE_T_DEFINED
typedef unsigned long long int size_t;
#define _SIZE_T_DEFINED
#endif
#ifndef _WCHAR_T_DEFINED
typedef unsigned short wchar_t;
#define _WCHAR_T_DEFINED
#endif
typedef struct { long long __ll; long double __ld; } max_align_t;
#define offsetof(s,m) (size_t)&(((s *)0)->m)
......@@ -28,6 +28,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#ifndef _STDINT_H
#define _STDINT_H
#include <stddef.h>
#if defined(_MSC_VER)
#include "stdint_rulibc_msvc.h"
#else
/* 7.8.1.1 Exact-width integer types */
#ifdef __INT8_TYPE__
......@@ -364,4 +372,6 @@ typedef __UINTMAX_TYPE__ uintmax_t;
typedef long sig_atomic_t;
#endif
#endif /* _GCC_STDINT_H */
// ISO C9x compliant stdint.h for Microsoft Visual Studio
// Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124
//
// Copyright (c) 2006-2013 Alexander Chemeris
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the product nor the names of its contributors may
// be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////////
#if _MSC_VER > 1000
#pragma once
#endif
#include "bits/limits.h"
#include "bits/wchar.h"
// Define _W64 macros to mark types changing their size, like intptr_t.
#ifndef _W64
# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
# define _W64 __w64
# else
# define _W64
# endif
#endif
// 7.18.1 Integer types
// 7.18.1.1 Exact-width integer types
// Visual Studio 6 and Embedded Visual C++ 4 doesn't
// realize that, e.g. char has the same size as __int8
// so we give up on __intX for them.
#if (_MSC_VER < 1300)
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed int int32_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#else
typedef signed __int8 int8_t;
typedef signed __int16 int16_t;
typedef signed __int32 int32_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
#endif
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
// 7.18.1.2 Minimum-width integer types
typedef int8_t int_least8_t;
typedef int16_t int_least16_t;
typedef int32_t int_least32_t;
typedef int64_t int_least64_t;
typedef uint8_t uint_least8_t;
typedef uint16_t uint_least16_t;
typedef uint32_t uint_least32_t;
typedef uint64_t uint_least64_t;
// 7.18.1.3 Fastest minimum-width integer types
typedef int8_t int_fast8_t;
typedef int16_t int_fast16_t;
typedef int32_t int_fast32_t;
typedef int64_t int_fast64_t;
typedef uint8_t uint_fast8_t;
typedef uint16_t uint_fast16_t;
typedef uint32_t uint_fast32_t;
typedef uint64_t uint_fast64_t;
// 7.18.1.4 Integer types capable of holding object pointers
#ifdef _WIN64 // [
typedef signed __int64 intptr_t;
typedef unsigned __int64 uintptr_t;
#else // _WIN64 ][
typedef _W64 signed int intptr_t;
typedef _W64 unsigned int uintptr_t;
#endif // _WIN64 ]
// 7.18.1.5 Greatest-width integer types
typedef int64_t intmax_t;
typedef uint64_t uintmax_t;
// 7.18.2 Limits of specified-width integer types
#if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259
// 7.18.2.1 Limits of exact-width integer types
#define INT8_MIN ((int8_t)_I8_MIN)
#define INT8_MAX _I8_MAX
#define INT16_MIN ((int16_t)_I16_MIN)
#define INT16_MAX _I16_MAX
#define INT32_MIN ((int32_t)_I32_MIN)
#define INT32_MAX _I32_MAX
#define INT64_MIN ((int64_t)_I64_MIN)
#define INT64_MAX _I64_MAX
#define UINT8_MAX _UI8_MAX
#define UINT16_MAX _UI16_MAX
#define UINT32_MAX _UI32_MAX
#define UINT64_MAX _UI64_MAX
// 7.18.2.2 Limits of minimum-width integer types
#define INT_LEAST8_MIN INT8_MIN
#define INT_LEAST8_MAX INT8_MAX
#define INT_LEAST16_MIN INT16_MIN
#define INT_LEAST16_MAX INT16_MAX
#define INT_LEAST32_MIN INT32_MIN
#define INT_LEAST32_MAX INT32_MAX
#define INT_LEAST64_MIN INT64_MIN
#define INT_LEAST64_MAX INT64_MAX
#define UINT_LEAST8_MAX UINT8_MAX
#define UINT_LEAST16_MAX UINT16_MAX
#define UINT_LEAST32_MAX UINT32_MAX
#define UINT_LEAST64_MAX UINT64_MAX
// 7.18.2.3 Limits of fastest minimum-width integer types
#define INT_FAST8_MIN INT8_MIN
#define INT_FAST8_MAX INT8_MAX
#define INT_FAST16_MIN INT16_MIN
#define INT_FAST16_MAX INT16_MAX
#define INT_FAST32_MIN INT32_MIN
#define INT_FAST32_MAX INT32_MAX
#define INT_FAST64_MIN INT64_MIN
#define INT_FAST64_MAX INT64_MAX
#define UINT_FAST8_MAX UINT8_MAX
#define UINT_FAST16_MAX UINT16_MAX
#define UINT_FAST32_MAX UINT32_MAX
#define UINT_FAST64_MAX UINT64_MAX
// 7.18.2.4 Limits of integer types capable of holding object pointers
#ifdef _WIN64 // [
# define INTPTR_MIN INT64_MIN
# define INTPTR_MAX INT64_MAX
# define UINTPTR_MAX UINT64_MAX
#else // _WIN64 ][
# define INTPTR_MIN INT32_MIN
# define INTPTR_MAX INT32_MAX
# define UINTPTR_MAX UINT32_MAX
#endif // _WIN64 ]
// 7.18.2.5 Limits of greatest-width integer types
#define INTMAX_MIN INT64_MIN
#define INTMAX_MAX INT64_MAX
#define UINTMAX_MAX UINT64_MAX
// 7.18.3 Limits of other integer types
#ifdef _WIN64 // [
# define PTRDIFF_MIN _I64_MIN
# define PTRDIFF_MAX _I64_MAX
#else // _WIN64 ][
# define PTRDIFF_MIN _I32_MIN
# define PTRDIFF_MAX _I32_MAX
#endif // _WIN64 ]
#define SIG_ATOMIC_MIN INT_MIN
#define SIG_ATOMIC_MAX INT_MAX
#ifndef SIZE_MAX // [
# ifdef _WIN64 // [
# define SIZE_MAX _UI64_MAX
# else // _WIN64 ][
# define SIZE_MAX _UI32_MAX
# endif // _WIN64 ]
#endif // SIZE_MAX ]
// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
#ifndef WCHAR_MIN // [
# define WCHAR_MIN 0
#endif // WCHAR_MIN ]
#ifndef WCHAR_MAX // [
# define WCHAR_MAX _UI16_MAX
#endif // WCHAR_MAX ]
#define WINT_MIN 0
#define WINT_MAX _UI16_MAX
#endif // __STDC_LIMIT_MACROS ]
// 7.18.4 Limits of other integer types
#if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260
// 7.18.4.1 Macros for minimum-width integer constants
#define INT8_C(val) val##i8
#define INT16_C(val) val##i16
#define INT32_C(val) val##i32
#define INT64_C(val) val##i64
#define UINT8_C(val) val##ui8
#define UINT16_C(val) val##ui16
#define UINT32_C(val) val##ui32
#define UINT64_C(val) val##ui64
// 7.18.4.2 Macros for greatest-width integer constants
// These #ifndef's are needed to prevent collisions with <boost/cstdint.hpp>.
// Check out Issue 9 for the details.
#ifndef INTMAX_C // [
# define INTMAX_C INT64_C
#endif // INTMAX_C ]
#ifndef UINTMAX_C // [
# define UINTMAX_C UINT64_C
#endif // UINTMAX_C ]
#endif // __STDC_CONSTANT_MACROS ]
#define __RULIBC__ 1
#if defined(_MSC_VER)
#include "__shared_header_rulibc_msvc.h"
#endif
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment