-
Notifications
You must be signed in to change notification settings - Fork 36
Add MSVC and MSYS2 UCRT64 Build #6
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| #ifndef _UNISTD_H | ||
| #define _UNISTD_H 1 | ||
|
|
||
| /* This file intended to serve as a drop-in replacement for | ||
| * unistd.h on Windows | ||
| * Please add functionality as neeeded | ||
| */ | ||
|
|
||
| #include <stdlib.h> | ||
| #include <io.h> | ||
| #include <process.h> /* for getpid() and the exec..() family */ | ||
| #include <direct.h> /* for _getcwd() and _chdir() */ | ||
|
|
||
| #define srandom srand | ||
| #define random rand | ||
|
|
||
| /* Values for the second argument to access. | ||
| These may be OR'd together. */ | ||
| #define R_OK 4 /* Test for read permission. */ | ||
| #define W_OK 2 /* Test for write permission. */ | ||
| //#define X_OK 1 /* execute permission - unsupported in windows*/ | ||
| #define F_OK 0 /* Test for existence. */ | ||
|
|
||
| #define access _access | ||
| #define dup2 _dup2 | ||
| #define execve _execve | ||
| #define ftruncate _chsize | ||
| #define unlink _unlink | ||
| #define fileno _fileno | ||
| #define getcwd _getcwd | ||
| #define chdir _chdir | ||
| #define isatty _isatty | ||
| #define lseek _lseek | ||
| /* read, write, and close are NOT being #defined here, because while there are file handle specific versions for Windows, they probably don't work for sockets. You need to look at your app and consider whether to call e.g. closesocket(). */ | ||
|
|
||
| #define ssize_t int | ||
|
|
||
| #define STDIN_FILENO 0 | ||
| #define STDOUT_FILENO 1 | ||
| #define STDERR_FILENO 2 | ||
|
|
||
| #endif /* unistd.h */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,6 +87,10 @@ | |
| * evaluates to 1. The other evaluates to 0. Note that newer gcc supports | ||
| * __BYTE_ORDER__ for easily determining the endianness; older gcc doesn't. In | ||
| * the latter case we fall back to a configure-time check. */ | ||
| #ifdef _MSC_VER | ||
| #define CPU_IS_BIG_ENDIAN() 0 | ||
| #include<assert.h> | ||
| #endif | ||
| #ifdef __BYTE_ORDER__ | ||
| # define CPU_IS_BIG_ENDIAN() (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) | ||
| #elif defined(HAVE_CONFIG_H) | ||
|
|
@@ -110,15 +114,23 @@ | |
|
|
||
| /* Get the minimum of two variables, without multiple evaluation. */ | ||
| #undef min | ||
| #ifdef _MSC_VER | ||
| #define min(a, b) ((a < b) ? a : b) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NB: MSVC's |
||
| #else | ||
| #define min(a, b) ({ typeof(a) _a = (a); typeof(b) _b = (b); \ | ||
| (_a < _b) ? _a : _b; }) | ||
| #endif | ||
| #undef MIN | ||
| #define MIN(a, b) min((a), (b)) | ||
|
|
||
| /* Get the maximum of two variables, without multiple evaluation. */ | ||
| #undef max | ||
| #ifdef _MSC_VER | ||
| #define max(a, b) ((a > b) ? a : b) | ||
| #else | ||
| #define max(a, b) ({ typeof(a) _a = (a); typeof(b) _b = (b); \ | ||
| (_a > _b) ? _a : _b; }) | ||
| #endif | ||
| #undef MAX | ||
| #define MAX(a, b) max((a), (b)) | ||
|
|
||
|
|
@@ -127,10 +139,13 @@ | |
| #define max3(a, b, c) max(max((a), (b)), (c)) | ||
|
|
||
| /* Swap the values of two variables, without multiple evaluation. */ | ||
| #ifdef _MSC_VER | ||
| # define swap(a, b, type) { type _a = (a); (a) = (b); (b) = _a; } | ||
| #endif | ||
| #ifndef swap | ||
| # define swap(a, b) ({ typeof(a) _a = (a); (a) = (b); (b) = _a; }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Latest Visual Studio supports For this specific macro, we can also use the more universally compatible: # define swap(a, b) do { typeof(a) _a = (a); (a) = (b); (b) = _a; } while(0) |
||
| # define swap(a, b, type) ({ typeof(a) _a = (a); (a) = (b); (b) = _a; }) | ||
| #endif | ||
| #define SWAP(a, b) swap((a), (b)) | ||
| #define SWAP(a, b ,type) swap((a), (b),type) | ||
|
|
||
| /* Optional definitions for checking with 'sparse'. */ | ||
| #ifdef __CHECKER__ | ||
|
|
@@ -142,21 +157,127 @@ | |
| #endif | ||
|
|
||
| /* STATIC_ASSERT() - verify the truth of an expression at compilation time. */ | ||
| #ifdef _MSC_VER | ||
| #define STATIC_ASSERT(expr) assert(expr) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Current Visual Studio (even without |
||
| #else | ||
| #ifdef __CHECKER__ | ||
| # define STATIC_ASSERT(expr) | ||
| #elif __STDC_VERSION__ >= 201112L | ||
| # define STATIC_ASSERT(expr) _Static_assert((expr), "") | ||
| #else | ||
| # define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)])) | ||
| #endif | ||
|
|
||
| #endif | ||
| /* STATIC_ASSERT_ZERO() - verify the truth of an expression at compilation time | ||
| * and also produce a result of value '0' to be used in constant expressions */ | ||
| #ifdef _MSC_VER | ||
| #pragma comment(lib, "ntdll") | ||
| #define STATIC_ASSERT_ZERO(expr) 0 | ||
| #else | ||
| #define STATIC_ASSERT_ZERO(expr) ((int)sizeof(char[-!(expr)])) | ||
|
|
||
| #endif | ||
| #define CONCAT_IMPL(s1, s2) s1##s2 | ||
|
|
||
| /* CONCAT() - concatenate two tokens at preprocessing time. */ | ||
| #define CONCAT(s1, s2) CONCAT_IMPL(s1, s2) | ||
| #ifndef PACKAGE_VERSION | ||
| #define PACKAGE_VERSION "" | ||
| #endif | ||
| #ifndef PACKAGE_BUGREPORT | ||
| #define PACKAGE_BUGREPORT "" | ||
| #endif | ||
| #ifdef _MSC_VER | ||
| //We are using Microsoft's MSVC, gcc specific functions are not available | ||
| #include<assert.h> | ||
| #define __attribute__(x) | ||
| #define POINTER_FIX() (size_t) | ||
| #define smart_array(type, name, size) type * name=_alloca((size)*(sizeof(type))) | ||
| #define restrict | ||
| #define EMPTY 0 | ||
| #define FILE_SHARE_VALID_FLAGS FILE_SHARE_DELETE | FILE_SHARE_READ |FILE_SHARE_WRITE | ||
| #include<wchar.h> | ||
| static inline wchar_t * wmempcpy(wchar_t *_S1, wchar_t const *_S2, size_t _N) | ||
| { | ||
| return wmemcpy(_S1,_S2,_N)+_N; | ||
|
|
||
| } | ||
| #define alloca _alloca | ||
|
|
||
| #include <intrin.h> | ||
| #include <stdint.h> | ||
| uint32_t __inline __builtin_ctz(uint32_t value) | ||
| { | ||
| unsigned long trailing_zero = 0; | ||
| if (_BitScanForward(&trailing_zero, value)) | ||
| return trailing_zero; | ||
| return 32; | ||
| } | ||
|
|
||
| #endif /* _WIMLIB_COMPILER_H */ | ||
| uint32_t __inline __builtin_clz(uint32_t value) | ||
| { | ||
| unsigned long leading_zero = 0; | ||
| if (_BitScanReverse(&leading_zero, value)) | ||
| return 31 - leading_zero; | ||
| return 32; | ||
| } | ||
| #define __builtin_constant_p(x) 0 | ||
| #define __builtin_prefetch(x, y) 0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefetch is available for MSVC on x86 (but not on ARM) so you should be able to use: |
||
| #define __builtin_expect(x,y) (x) | ||
| #define gmtime_r(x, y) gmtime_s(y,x) | ||
| #define vsnwprintf _vsnwprintf | ||
| #define snwprintf _snwprintf | ||
| #undef PRIu64 | ||
| #define PRIu64 "I64u" | ||
| #undef PRId64 | ||
| #define PRId64 "I64d" | ||
| #undef PRIi64 | ||
| #define PRIi64 "I64i" | ||
| #undef PRIo64 | ||
| #define PRIo64 "I64o" | ||
| #undef PRIx64 | ||
| #define PRIx64 "I64x" | ||
| #if defined(_M_ARM64) || defined(_M_X64) | ||
| uint32_t __inline __builtin_clzll(uint64_t value) | ||
| { | ||
| unsigned long leading_zero = 0; | ||
| if (_BitScanReverse64(&leading_zero, value)) | ||
| return 63 - leading_zero; | ||
| return 64; | ||
| } | ||
| uint32_t __inline __builtin_ctzll(uint32_t value) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ctzll works on 64-bit so it should be |
||
| { | ||
| unsigned long trailing_zero = 0; | ||
| if (_BitScanForward64(&trailing_zero, value)) | ||
| return trailing_zero; | ||
| return 64; | ||
| } | ||
| #else | ||
| uint32_t __inline __builtin_clzll(uint64_t value) | ||
| { | ||
| if (value == 0) | ||
| return 64; | ||
| uint32_t msh = (uint32_t)(value >> 32); | ||
| uint32_t lsh = (uint32_t)(value & 0xFFFFFFFF); | ||
| if (msh != 0) | ||
| return __builtin_clz(msh); | ||
| return 32 + __builtin_clz(lsh); | ||
| } | ||
| uint32_t __inline __builtin_ctzll(uint64_t value) | ||
| { | ||
| if (value == 0) | ||
| return 64; | ||
| uint32_t msh = (uint32_t)(value >> 32); | ||
| uint32_t lsh = (uint32_t)(value & 0xFFFFFFFF); | ||
| if (msh != 0) | ||
| return __builtin_ctz(msh); | ||
| return 32 + __builtin_ctz(lsh); | ||
| } | ||
| #endif | ||
| #define __builtin_clzl __builtin_clzll | ||
| #else | ||
| #define POINTER_FIX() | ||
| #define smart_array(type, name, size) type name[size] | ||
| #define EMPTY | ||
| #endif | ||
| #endif | ||
| /* _WIMLIB_COMPILER_H */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -400,17 +400,22 @@ read_huffsym(struct input_bitstream *is, const u16 decode_table[], | |
| * structure, then the outer structure must be allocated on a | ||
| * DECODE_TABLE_ALIGNMENT-byte aligned boundary as well. | ||
| */ | ||
| #ifdef _MSC_VER | ||
| #pragma pack(push, 16) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe better to define PRAGMA_BEGIN_PACKED(x) / PRAGMA_END_PACKED macros, as this could reduce all this 3 line boilerplate to a single less conspicuous line. |
||
| #endif | ||
| #define DECODE_TABLE(name, num_syms, table_bits, max_codeword_len) \ | ||
| u16 name[DECODE_TABLE_SIZE((num_syms), (table_bits), \ | ||
| (max_codeword_len))] \ | ||
| __attribute__((aligned(DECODE_TABLE_ALIGNMENT))) | ||
|
|
||
| #ifdef _MSC_VER | ||
| #pragma pack(pop) | ||
| #endif | ||
| /* | ||
| * Declare the temporary "working_space" array needed for building the decode | ||
| * table for a Huffman code. | ||
| */ | ||
| #define DECODE_TABLE_WORKING_SPACE(name, num_syms, max_codeword_len) \ | ||
| u16 name[2 * ((max_codeword_len) + 1) + (num_syms)]; | ||
| u16 name[2 * ((max_codeword_len) + 1) + (num_syms)] | ||
|
|
||
| int | ||
| make_huffman_decode_table(u16 decode_table[], unsigned num_syms, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,27 +11,27 @@ | |
| struct filedes { | ||
| int fd; | ||
| unsigned int is_pipe : 1; | ||
| off_t offset; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can avoid this whole patch by adding the following in the MSVC preprocessor definitions: If you do just that, then |
||
| uint64_t offset; | ||
| }; | ||
|
|
||
| int | ||
| full_read(struct filedes *fd, void *buf, size_t n); | ||
|
|
||
| int | ||
| full_pread(struct filedes *fd, void *buf, size_t nbyte, off_t offset); | ||
| full_pread(struct filedes *fd, void *buf, size_t nbyte, uint64_t offset); | ||
|
|
||
| int | ||
| full_write(struct filedes *fd, const void *buf, size_t n); | ||
|
|
||
| int | ||
| full_pwrite(struct filedes *fd, const void *buf, size_t count, off_t offset); | ||
| full_pwrite(struct filedes *fd, const void *buf, size_t count, uint64_t offset); | ||
|
|
||
| #ifndef _WIN32 | ||
| # define O_BINARY 0 | ||
| #endif | ||
|
|
||
| off_t | ||
| filedes_seek(struct filedes *fd, off_t offset); | ||
| uint64_t | ||
| filedes_seek(struct filedes *fd, uint64_t offset); | ||
|
|
||
| bool | ||
| filedes_is_seekable(struct filedes *fd); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ssize_tshould be 64-bit on 64-bit platforms.You can use the following from MinGW:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
typedef ptrdiff_t ssize_t;instead?