authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-13 22:42:04-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-07-13 22:42:04-07:00
logbd7b2cc4b49127474a028e6726fce33c5db3df12
tree01e71492173186830a10157adfcc118a1e83806c
parentfba618a6c9ae4f70dc8a7879975adf31d3a44d4d
parentc31871065394c78d7d316b2a1709077437d29ccf
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #20620 from kcbanner/fixup_msvc_bootstrap

Fixes for bootrapping with MSVC

4 files changed, 99 insertions(+), 42 deletions(-)

lib/std/Build/Step/Compile.zig+9-2
...@@ -1635,9 +1635,16 @@ fn getZigArgs(compile: *Compile) ![][]const u8 {...@@ -1635,9 +1635,16 @@ fn getZigArgs(compile: *Compile) ![][]const u8 {
1635 });1635 });
1636 }1636 }
16371637
1638 if (compile.zig_lib_dir) |dir| {1638 const opt_zig_lib_dir = if (compile.zig_lib_dir) |dir|
1639 dir.getPath2(b, step)
1640 else if (b.graph.zig_lib_directory.path) |_|
1641 b.fmt("{}", .{b.graph.zig_lib_directory})
1642 else
1643 null;
1644
1645 if (opt_zig_lib_dir) |zig_lib_dir| {
1639 try zig_args.append("--zig-lib-dir");1646 try zig_args.append("--zig-lib-dir");
1640 try zig_args.append(dir.getPath2(b, step));1647 try zig_args.append(zig_lib_dir);
1641 }1648 }
16421649
1643 try addFlag(&zig_args, "PIE", compile.pie);1650 try addFlag(&zig_args, "PIE", compile.pie);
lib/zig.h+42-17
...@@ -3636,7 +3636,7 @@ typedef int zig_memory_order;...@@ -3636,7 +3636,7 @@ typedef int zig_memory_order;
3636#define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_min_ ##Type(obj, arg)3636#define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_min_ ##Type(obj, arg)
3637#define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_max_ ##Type(obj, arg)3637#define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_max_ ##Type(obj, arg)
3638#define zig_atomic_store( obj, arg, order, Type, ReprType) zig_msvc_atomic_store_ ##Type(obj, arg)3638#define zig_atomic_store( obj, arg, order, Type, ReprType) zig_msvc_atomic_store_ ##Type(obj, arg)
3639#define zig_atomic_load(res, obj, order, Type, ReprType) res = zig_msvc_atomic_load_ ##Type(obj)3639#define zig_atomic_load(res, obj, order, Type, ReprType) res = zig_msvc_atomic_load_ ##order##_##Type(obj)
3640#if _M_X643640#if _M_X64
3641#define zig_fence(order) __faststorefence()3641#define zig_fence(order) __faststorefence()
3642#else3642#else
...@@ -3670,7 +3670,7 @@ typedef int zig_memory_order;...@@ -3670,7 +3670,7 @@ typedef int zig_memory_order;
36703670
3671/* TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 */3671/* TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 */
36723672
3673#define zig_msvc_atomics(ZigType, Type, SigType, suffix) \3673#define zig_msvc_atomics(ZigType, Type, SigType, suffix, iso_suffix) \
3674 static inline bool zig_msvc_cmpxchg_##ZigType(Type volatile* obj, Type* expected, Type desired) { \3674 static inline bool zig_msvc_cmpxchg_##ZigType(Type volatile* obj, Type* expected, Type desired) { \
3675 Type comparand = *expected; \3675 Type comparand = *expected; \
3676 Type initial = _InterlockedCompareExchange##suffix((SigType volatile*)obj, (SigType)desired, (SigType)comparand); \3676 Type initial = _InterlockedCompareExchange##suffix((SigType volatile*)obj, (SigType)desired, (SigType)comparand); \
...@@ -3741,24 +3741,34 @@ typedef int zig_memory_order;...@@ -3741,24 +3741,34 @@ typedef int zig_memory_order;
3741 } \3741 } \
3742 static inline void zig_msvc_atomic_store_##ZigType(Type volatile* obj, Type value) { \3742 static inline void zig_msvc_atomic_store_##ZigType(Type volatile* obj, Type value) { \
3743 (void)_InterlockedExchange##suffix((SigType volatile*)obj, (SigType)value); \3743 (void)_InterlockedExchange##suffix((SigType volatile*)obj, (SigType)value); \
3744 } \
3745 static inline Type zig_msvc_atomic_load_zig_memory_order_relaxed_##ZigType(Type volatile* obj) { \
3746 return __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3744 } \3747 } \
3745 static inline Type zig_msvc_atomic_load_##ZigType(Type volatile* obj) { \3748 static inline Type zig_msvc_atomic_load_zig_memory_order_acquire_##ZigType(Type volatile* obj) { \
3746 return _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)0); \3749 Type val = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3750 _ReadWriteBarrier(); \
3751 return val; \
3752 } \
3753 static inline Type zig_msvc_atomic_load_zig_memory_order_seq_cst_##ZigType(Type volatile* obj) { \
3754 Type val = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3755 _ReadWriteBarrier(); \
3756 return val; \
3747 }3757 }
37483758
3749zig_msvc_atomics( u8, uint8_t, char, 8)3759zig_msvc_atomics( u8, uint8_t, char, 8, 8)
3750zig_msvc_atomics( i8, int8_t, char, 8)3760zig_msvc_atomics( i8, int8_t, char, 8, 8)
3751zig_msvc_atomics(u16, uint16_t, short, 16)3761zig_msvc_atomics(u16, uint16_t, short, 16, 16)
3752zig_msvc_atomics(i16, int16_t, short, 16)3762zig_msvc_atomics(i16, int16_t, short, 16, 16)
3753zig_msvc_atomics(u32, uint32_t, long, )3763zig_msvc_atomics(u32, uint32_t, long, , 32)
3754zig_msvc_atomics(i32, int32_t, long, )3764zig_msvc_atomics(i32, int32_t, long, , 32)
37553765
3756#if _M_X643766#if _M_X64
3757zig_msvc_atomics(u64, uint64_t, __int64, 64)3767zig_msvc_atomics(u64, uint64_t, __int64, 64, 64)
3758zig_msvc_atomics(i64, int64_t, __int64, 64)3768zig_msvc_atomics(i64, int64_t, __int64, 64, 64)
3759#endif3769#endif
37603770
3761#define zig_msvc_flt_atomics(Type, SigType, suffix) \3771#define zig_msvc_flt_atomics(Type, SigType, suffix, iso_suffix) \
3762 static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \3772 static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \
3763 SigType exchange; \3773 SigType exchange; \
3764 SigType comparand; \3774 SigType comparand; \
...@@ -3776,15 +3786,30 @@ zig_msvc_atomics(i64, int64_t, __int64, 64)...@@ -3776,15 +3786,30 @@ zig_msvc_atomics(i64, int64_t, __int64, 64)
3776 memcpy(&value, &arg, sizeof(value)); \3786 memcpy(&value, &arg, sizeof(value)); \
3777 (void)_InterlockedExchange##suffix((SigType volatile*)obj, value); \3787 (void)_InterlockedExchange##suffix((SigType volatile*)obj, value); \
3778 } \3788 } \
3779 static inline zig_##Type zig_msvc_atomic_load_##Type(zig_##Type volatile* obj) { \3789 static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_relaxed_##Type(zig_##Type volatile* obj) { \
3780 zig_##Type result; \3790 zig_##Type result; \
3781 SigType initial = _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)0); \3791 SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3782 memcpy(&result, &initial, sizeof(result)); \3792 memcpy(&result, &initial, sizeof(result)); \
3783 return result; \3793 return result; \
3794 } \
3795 static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_acquire_##Type(zig_##Type volatile* obj) { \
3796 zig_##Type result; \
3797 SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3798 _ReadWriteBarrier(); \
3799 memcpy(&result, &initial, sizeof(result)); \
3800 return result; \
3801 } \
3802 static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_seq_cst_##Type(zig_##Type volatile* obj) { \
3803 zig_##Type result; \
3804 SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3805 _ReadWriteBarrier(); \
3806 memcpy(&result, &initial, sizeof(result)); \
3807 return result; \
3784 }3808 }
3785zig_msvc_flt_atomics(f32, long, )3809
3810zig_msvc_flt_atomics(f32, long, , 32)
3786#if _M_X643811#if _M_X64
3787zig_msvc_flt_atomics(f64, int64_t, 64)3812zig_msvc_flt_atomics(f64, int64_t, 64, 64)
3788#endif3813#endif
37893814
3790#if _M_IX863815#if _M_IX86
src/main.zig+2-2
...@@ -2710,7 +2710,7 @@ fn buildOutputType(...@@ -2710,7 +2710,7 @@ fn buildOutputType(
2710 break :d getWasiPreopen("/lib");2710 break :d getWasiPreopen("/lib");
2711 } else if (self_exe_path) |p| {2711 } else if (self_exe_path) |p| {
2712 break :d introspect.findZigLibDirFromSelfExe(arena, p) catch |err| {2712 break :d introspect.findZigLibDirFromSelfExe(arena, p) catch |err| {
2713 fatal("unable to find zig installation directory: {s}", .{@errorName(err)});2713 fatal("unable to find zig installation directory '{s}': {s}", .{ p, @errorName(err) });
2714 };2714 };
2715 } else {2715 } else {
2716 unreachable;2716 unreachable;
...@@ -7403,7 +7403,7 @@ fn findTemplates(gpa: Allocator, arena: Allocator) Templates {...@@ -7403,7 +7403,7 @@ fn findTemplates(gpa: Allocator, arena: Allocator) Templates {
7403 fatal("unable to find self exe path: {s}", .{@errorName(err)});7403 fatal("unable to find self exe path: {s}", .{@errorName(err)});
7404 };7404 };
7405 var zig_lib_directory = introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {7405 var zig_lib_directory = introspect.findZigLibDirFromSelfExe(arena, self_exe_path) catch |err| {
7406 fatal("unable to find zig installation directory: {s}", .{@errorName(err)});7406 fatal("unable to find zig installation directory '{s}': {s}", .{ self_exe_path, @errorName(err) });
7407 };7407 };
74087408
7409 const s = fs.path.sep_str;7409 const s = fs.path.sep_str;
stage1/zig.h+46-21
...@@ -207,16 +207,16 @@ typedef char bool;...@@ -207,16 +207,16 @@ typedef char bool;
207 __asm(zig_mangle_c(name) " = " zig_mangle_c(symbol))207 __asm(zig_mangle_c(name) " = " zig_mangle_c(symbol))
208#endif208#endif
209209
210#define zig_mangled_tentative zig_mangled
211#define zig_mangled_final zig_mangled
210#if _MSC_VER212#if _MSC_VER
211#define zig_mangled_tentative(mangled, unmangled)213#define zig_mangled(mangled, unmangled) ; \
212#define zig_mangled_final(mangled, unmangled) ; \
213 zig_export(#mangled, unmangled)214 zig_export(#mangled, unmangled)
214#define zig_mangled_export(mangled, unmangled, symbol) \215#define zig_mangled_export(mangled, unmangled, symbol) \
215 zig_export(unmangled, #mangled) \216 zig_export(unmangled, #mangled) \
216 zig_export(symbol, unmangled)217 zig_export(symbol, unmangled)
217#else /* _MSC_VER */218#else /* _MSC_VER */
218#define zig_mangled_tentative(mangled, unmangled) __asm(zig_mangle_c(unmangled))219#define zig_mangled(mangled, unmangled) __asm(zig_mangle_c(unmangled))
219#define zig_mangled_final(mangled, unmangled) zig_mangled_tentative(mangled, unmangled)
220#define zig_mangled_export(mangled, unmangled, symbol) \220#define zig_mangled_export(mangled, unmangled, symbol) \
221 zig_mangled_final(mangled, unmangled) \221 zig_mangled_final(mangled, unmangled) \
222 zig_export(symbol, unmangled)222 zig_export(symbol, unmangled)
...@@ -3636,7 +3636,7 @@ typedef int zig_memory_order;...@@ -3636,7 +3636,7 @@ typedef int zig_memory_order;
3636#define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_min_ ##Type(obj, arg)3636#define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_min_ ##Type(obj, arg)
3637#define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_max_ ##Type(obj, arg)3637#define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = zig_msvc_atomicrmw_max_ ##Type(obj, arg)
3638#define zig_atomic_store( obj, arg, order, Type, ReprType) zig_msvc_atomic_store_ ##Type(obj, arg)3638#define zig_atomic_store( obj, arg, order, Type, ReprType) zig_msvc_atomic_store_ ##Type(obj, arg)
3639#define zig_atomic_load(res, obj, order, Type, ReprType) res = zig_msvc_atomic_load_ ##Type(obj)3639#define zig_atomic_load(res, obj, order, Type, ReprType) res = zig_msvc_atomic_load_ ##order##_##Type(obj)
3640#if _M_X643640#if _M_X64
3641#define zig_fence(order) __faststorefence()3641#define zig_fence(order) __faststorefence()
3642#else3642#else
...@@ -3670,7 +3670,7 @@ typedef int zig_memory_order;...@@ -3670,7 +3670,7 @@ typedef int zig_memory_order;
36703670
3671/* TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 */3671/* TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 */
36723672
3673#define zig_msvc_atomics(ZigType, Type, SigType, suffix) \3673#define zig_msvc_atomics(ZigType, Type, SigType, suffix, iso_suffix) \
3674 static inline bool zig_msvc_cmpxchg_##ZigType(Type volatile* obj, Type* expected, Type desired) { \3674 static inline bool zig_msvc_cmpxchg_##ZigType(Type volatile* obj, Type* expected, Type desired) { \
3675 Type comparand = *expected; \3675 Type comparand = *expected; \
3676 Type initial = _InterlockedCompareExchange##suffix((SigType volatile*)obj, (SigType)desired, (SigType)comparand); \3676 Type initial = _InterlockedCompareExchange##suffix((SigType volatile*)obj, (SigType)desired, (SigType)comparand); \
...@@ -3741,24 +3741,34 @@ typedef int zig_memory_order;...@@ -3741,24 +3741,34 @@ typedef int zig_memory_order;
3741 } \3741 } \
3742 static inline void zig_msvc_atomic_store_##ZigType(Type volatile* obj, Type value) { \3742 static inline void zig_msvc_atomic_store_##ZigType(Type volatile* obj, Type value) { \
3743 (void)_InterlockedExchange##suffix((SigType volatile*)obj, (SigType)value); \3743 (void)_InterlockedExchange##suffix((SigType volatile*)obj, (SigType)value); \
3744 } \
3745 static inline Type zig_msvc_atomic_load_zig_memory_order_relaxed_##ZigType(Type volatile* obj) { \
3746 return __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3744 } \3747 } \
3745 static inline Type zig_msvc_atomic_load_##ZigType(Type volatile* obj) { \3748 static inline Type zig_msvc_atomic_load_zig_memory_order_acquire_##ZigType(Type volatile* obj) { \
3746 return _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)0); \3749 Type val = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3750 _ReadWriteBarrier(); \
3751 return val; \
3752 } \
3753 static inline Type zig_msvc_atomic_load_zig_memory_order_seq_cst_##ZigType(Type volatile* obj) { \
3754 Type val = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3755 _ReadWriteBarrier(); \
3756 return val; \
3747 }3757 }
37483758
3749zig_msvc_atomics( u8, uint8_t, char, 8)3759zig_msvc_atomics( u8, uint8_t, char, 8, 8)
3750zig_msvc_atomics( i8, int8_t, char, 8)3760zig_msvc_atomics( i8, int8_t, char, 8, 8)
3751zig_msvc_atomics(u16, uint16_t, short, 16)3761zig_msvc_atomics(u16, uint16_t, short, 16, 16)
3752zig_msvc_atomics(i16, int16_t, short, 16)3762zig_msvc_atomics(i16, int16_t, short, 16, 16)
3753zig_msvc_atomics(u32, uint32_t, long, )3763zig_msvc_atomics(u32, uint32_t, long, , 32)
3754zig_msvc_atomics(i32, int32_t, long, )3764zig_msvc_atomics(i32, int32_t, long, , 32)
37553765
3756#if _M_X643766#if _M_X64
3757zig_msvc_atomics(u64, uint64_t, __int64, 64)3767zig_msvc_atomics(u64, uint64_t, __int64, 64, 64)
3758zig_msvc_atomics(i64, int64_t, __int64, 64)3768zig_msvc_atomics(i64, int64_t, __int64, 64, 64)
3759#endif3769#endif
37603770
3761#define zig_msvc_flt_atomics(Type, SigType, suffix) \3771#define zig_msvc_flt_atomics(Type, SigType, suffix, iso_suffix) \
3762 static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \3772 static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \
3763 SigType exchange; \3773 SigType exchange; \
3764 SigType comparand; \3774 SigType comparand; \
...@@ -3776,15 +3786,30 @@ zig_msvc_atomics(i64, int64_t, __int64, 64)...@@ -3776,15 +3786,30 @@ zig_msvc_atomics(i64, int64_t, __int64, 64)
3776 memcpy(&value, &arg, sizeof(value)); \3786 memcpy(&value, &arg, sizeof(value)); \
3777 (void)_InterlockedExchange##suffix((SigType volatile*)obj, value); \3787 (void)_InterlockedExchange##suffix((SigType volatile*)obj, value); \
3778 } \3788 } \
3779 static inline zig_##Type zig_msvc_atomic_load_##Type(zig_##Type volatile* obj) { \3789 static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_relaxed_##Type(zig_##Type volatile* obj) { \
3780 zig_##Type result; \3790 zig_##Type result; \
3781 SigType initial = _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)0); \3791 SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3782 memcpy(&result, &initial, sizeof(result)); \3792 memcpy(&result, &initial, sizeof(result)); \
3783 return result; \3793 return result; \
3794 } \
3795 static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_acquire_##Type(zig_##Type volatile* obj) { \
3796 zig_##Type result; \
3797 SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3798 _ReadWriteBarrier(); \
3799 memcpy(&result, &initial, sizeof(result)); \
3800 return result; \
3801 } \
3802 static inline zig_##Type zig_msvc_atomic_load_zig_memory_order_seq_cst_##Type(zig_##Type volatile* obj) { \
3803 zig_##Type result; \
3804 SigType initial = __iso_volatile_load##iso_suffix((SigType volatile*)obj); \
3805 _ReadWriteBarrier(); \
3806 memcpy(&result, &initial, sizeof(result)); \
3807 return result; \
3784 }3808 }
3785zig_msvc_flt_atomics(f32, long, )3809
3810zig_msvc_flt_atomics(f32, long, , 32)
3786#if _M_X643811#if _M_X64
3787zig_msvc_flt_atomics(f64, int64_t, 64)3812zig_msvc_flt_atomics(f64, int64_t, 64, 64)
3788#endif3813#endif
37893814
3790#if _M_IX863815#if _M_IX86