@@ -263,6 +263,11 @@ fn generateSystemDefines(comp: *Compilation, w: *std.Io.Writer) !void {
263
263
};
264
264
try w .print ("#define __ARO_EMULATE__ {s}\n " , .{emulated });
265
265
266
+ if (comp .langopts .emulate == .msvc ) {
267
+ try w .writeAll ("#define _MSC_VER 1933\n " );
268
+ try w .writeAll ("#define _MSC_FULL_VER 193300000\n " );
269
+ }
270
+
266
271
if (comp .code_gen_options .optimization_level .hasAnyOptimizations ()) {
267
272
try define (w , "__OPTIMIZE__" );
268
273
}
@@ -1663,13 +1668,11 @@ const FindInclude = struct {
1663
1668
only_search_after_dir : []const u8 ,
1664
1669
},
1665
1670
) Allocator.Error ! ? Result {
1666
- var wait_for : ? []u8 = null ;
1667
1671
var find : FindInclude = .{
1668
1672
.comp = comp ,
1669
1673
.include_path = include_path ,
1670
1674
.wait_for = null ,
1671
1675
};
1672
- defer if (wait_for ) | buf | comp .gpa .free (buf );
1673
1676
1674
1677
if (std .fs .path .isAbsolute (include_path )) {
1675
1678
switch (search_strat ) {
@@ -1690,12 +1693,7 @@ const FindInclude = struct {
1690
1693
// because a file might not be directly inside of an include directory. To implement
1691
1694
// this correctly, we will need to track which include directory a file has been
1692
1695
// included from.
1693
- wait_for = if (std .fs .path .dirname (other_file )) | path |
1694
- try std .fs .path .resolve (comp .gpa , &.{path })
1695
- else
1696
- null ;
1697
-
1698
- find .wait_for = wait_for ;
1696
+ find .wait_for = std .fs .path .dirname (other_file );
1699
1697
},
1700
1698
}
1701
1699
switch (include_type ) {
@@ -1724,9 +1722,28 @@ const FindInclude = struct {
1724
1722
}
1725
1723
return null ;
1726
1724
}
1725
+ fn pathMatches (a : []const u8 , b : []const u8 ) bool {
1726
+ if (@import ("builtin" ).os .tag != .windows ) {
1727
+ return std .mem .eql (u8 , a , b );
1728
+ }
1729
+
1730
+ const separators = std .fs .path .sep_str_windows ++ std .fs .path .sep_str_posix ;
1731
+ var a_iter = std .mem .splitAny (u8 , a , separators );
1732
+ var b_iter = std .mem .splitAny (u8 , b , separators );
1733
+ var a_component = a_iter .next ();
1734
+ var b_component = b_iter .next ();
1735
+ while (a_component != null and b_component != null ) : ({
1736
+ a_component = a_iter .next ();
1737
+ b_component = b_iter .next ();
1738
+ }) {
1739
+ if (! std .mem .eql (u8 , a_component .? , b_component .? )) return false ;
1740
+ }
1741
+
1742
+ return a_component == null and b_component == null ;
1743
+ }
1727
1744
fn checkIncludeDir (find : * FindInclude , include_dir : []const u8 , kind : Source.Kind ) Allocator.Error ! ? Result {
1728
1745
if (find .wait_for ) | wait_for | {
1729
- if (std . mem . eql ( u8 , include_dir , wait_for )) find .wait_for = null ;
1746
+ if (pathMatches ( include_dir , wait_for )) find .wait_for = null ;
1730
1747
return null ;
1731
1748
}
1732
1749
return find .check ("{s}{c}{s}" , .{
@@ -1739,7 +1756,7 @@ const FindInclude = struct {
1739
1756
const path = find .comp .getSource (source_id ).path ;
1740
1757
const dir = std .fs .path .dirname (path ) orelse "." ;
1741
1758
if (find .wait_for ) | wait_for | {
1742
- if (std . mem . eql ( u8 , dir , wait_for )) find .wait_for = null ;
1759
+ if (pathMatches ( dir , wait_for )) find .wait_for = null ;
1743
1760
return null ;
1744
1761
}
1745
1762
return find .check ("{s}{c}{s}" , .{
@@ -1754,7 +1771,7 @@ const FindInclude = struct {
1754
1771
// If this is a match, then `wait_for` looks like '.../Foo.framework/Headers'.
1755
1772
const wait_framework = std .fs .path .dirname (wait_for ) orelse break :match ;
1756
1773
const wait_framework_dir = std .fs .path .dirname (wait_framework ) orelse break :match ;
1757
- if (! std . mem . eql ( u8 , framework_dir , wait_framework_dir )) break :match ;
1774
+ if (! pathMatches ( framework_dir , wait_framework_dir )) break :match ;
1758
1775
find .wait_for = null ;
1759
1776
}
1760
1777
return null ;
0 commit comments