@@ -24,6 +24,7 @@ const LibCInstallation = std.zig.LibCInstallation;
24
24
const glibc = @import ("libs/glibc.zig" );
25
25
const musl = @import ("libs/musl.zig" );
26
26
const freebsd = @import ("libs/freebsd.zig" );
27
+ const netbsd = @import ("libs/netbsd.zig" );
27
28
const mingw = @import ("libs/mingw.zig" );
28
29
const libunwind = @import ("libs/libunwind.zig" );
29
30
const libcxx = @import ("libs/libcxx.zig" );
@@ -250,6 +251,7 @@ fuzzer_lib: ?CrtFile = null,
250
251
251
252
glibc_so_files : ? glibc.BuiltSharedObjects = null ,
252
253
freebsd_so_files : ? freebsd.BuiltSharedObjects = null ,
254
+ netbsd_so_files : ? netbsd.BuiltSharedObjects = null ,
253
255
wasi_emulated_libs : []const wasi_libc.CrtFile ,
254
256
255
257
/// For example `Scrt1.o` and `libc_nonshared.a`. These are populated after building libc from source,
@@ -297,13 +299,15 @@ const QueuedJobs = struct {
297
299
musl_crt_file : [@typeInfo (musl .CrtFile ).@"enum" .fields .len ]bool = @splat (false ),
298
300
glibc_crt_file : [@typeInfo (glibc .CrtFile ).@"enum" .fields .len ]bool = @splat (false ),
299
301
freebsd_crt_file : [@typeInfo (freebsd .CrtFile ).@"enum" .fields .len ]bool = @splat (false ),
302
+ netbsd_crt_file : [@typeInfo (netbsd .CrtFile ).@"enum" .fields .len ]bool = @splat (false ),
300
303
/// one of WASI libc static objects
301
304
wasi_libc_crt_file : [@typeInfo (wasi_libc .CrtFile ).@"enum" .fields .len ]bool = @splat (false ),
302
305
/// one of the mingw-w64 static objects
303
306
mingw_crt_file : [@typeInfo (mingw .CrtFile ).@"enum" .fields .len ]bool = @splat (false ),
304
307
/// all of the glibc shared objects
305
308
glibc_shared_objects : bool = false ,
306
309
freebsd_shared_objects : bool = false ,
310
+ netbsd_shared_objects : bool = false ,
307
311
/// libunwind.a, usually needed when linking libc
308
312
libunwind : bool = false ,
309
313
libcxx : bool = false ,
@@ -795,6 +799,8 @@ pub const MiscTask = enum {
795
799
musl_crt_file ,
796
800
freebsd_crt_file ,
797
801
freebsd_shared_objects ,
802
+ netbsd_crt_file ,
803
+ netbsd_shared_objects ,
798
804
mingw_crt_file ,
799
805
windows_import_lib ,
800
806
libunwind ,
@@ -832,6 +838,9 @@ pub const MiscTask = enum {
832
838
@"freebsd libc Scrt1.o" ,
833
839
@"freebsd libc shared object" ,
834
840
841
+ @"netbsd libc Scrt0.o" ,
842
+ @"netbsd libc shared object" ,
843
+
835
844
@"mingw-w64 crt2.o" ,
836
845
@"mingw-w64 dllcrt2.o" ,
837
846
@"mingw-w64 libmingw32.lib" ,
@@ -1893,6 +1902,16 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
1893
1902
1894
1903
comp .queued_jobs .freebsd_shared_objects = true ;
1895
1904
comp .remaining_prelink_tasks += freebsd .sharedObjectsCount ();
1905
+ } else if (target .isNetBSDLibC ()) {
1906
+ if (! std .zig .target .canBuildLibC (target )) return error .LibCUnavailable ;
1907
+
1908
+ if (netbsd .needsCrt0 (comp .config .output_mode )) | f | {
1909
+ comp .queued_jobs .netbsd_crt_file [@intFromEnum (f )] = true ;
1910
+ comp .remaining_prelink_tasks += 1 ;
1911
+ }
1912
+
1913
+ comp .queued_jobs .netbsd_shared_objects = true ;
1914
+ comp .remaining_prelink_tasks += netbsd .sharedObjectsCount ();
1896
1915
} else if (target .isWasiLibC ()) {
1897
1916
if (! std .zig .target .canBuildLibC (target )) return error .LibCUnavailable ;
1898
1917
@@ -2051,6 +2070,10 @@ pub fn destroy(comp: *Compilation) void {
2051
2070
freebsd_file .deinit (gpa );
2052
2071
}
2053
2072
2073
+ if (comp .netbsd_so_files ) | * netbsd_file | {
2074
+ netbsd_file .deinit (gpa );
2075
+ }
2076
+
2054
2077
for (comp .c_object_table .keys ()) | key | {
2055
2078
key .destroy (gpa );
2056
2079
}
@@ -3866,6 +3889,10 @@ fn performAllTheWorkInner(
3866
3889
comp .link_task_wait_group .spawnManager (buildFreeBSDSharedObjects , .{ comp , main_progress_node });
3867
3890
}
3868
3891
3892
+ if (comp .queued_jobs .netbsd_shared_objects ) {
3893
+ comp .link_task_wait_group .spawnManager (buildNetBSDSharedObjects , .{ comp , main_progress_node });
3894
+ }
3895
+
3869
3896
if (comp .queued_jobs .libunwind ) {
3870
3897
comp .link_task_wait_group .spawnManager (buildLibUnwind , .{ comp , main_progress_node });
3871
3898
}
@@ -3907,6 +3934,13 @@ fn performAllTheWorkInner(
3907
3934
}
3908
3935
}
3909
3936
3937
+ for (0.. @typeInfo (netbsd .CrtFile ).@"enum" .fields .len ) | i | {
3938
+ if (comp .queued_jobs .netbsd_crt_file [i ]) {
3939
+ const tag : netbsd.CrtFile = @enumFromInt (i );
3940
+ comp .link_task_wait_group .spawnManager (buildNetBSDCrtFile , .{ comp , tag , main_progress_node });
3941
+ }
3942
+ }
3943
+
3910
3944
for (0.. @typeInfo (wasi_libc .CrtFile ).@"enum" .fields .len ) | i | {
3911
3945
if (comp .queued_jobs .wasi_libc_crt_file [i ]) {
3912
3946
const tag : wasi_libc.CrtFile = @enumFromInt (i );
@@ -4933,6 +4967,29 @@ fn buildFreeBSDSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) v
4933
4967
}
4934
4968
}
4935
4969
4970
+ fn buildNetBSDCrtFile (comp : * Compilation , crt_file : netbsd.CrtFile , prog_node : std.Progress.Node ) void {
4971
+ if (netbsd .buildCrtFile (comp , crt_file , prog_node )) | _ | {
4972
+ comp .queued_jobs .netbsd_crt_file [@intFromEnum (crt_file )] = false ;
4973
+ } else | err | switch (err ) {
4974
+ error .SubCompilationFailed = > return , // error reported already
4975
+ else = > comp .lockAndSetMiscFailure (.netbsd_crt_file , "unable to build NetBSD {s}: {s}" , .{
4976
+ @tagName (crt_file ), @errorName (err ),
4977
+ }),
4978
+ }
4979
+ }
4980
+
4981
+ fn buildNetBSDSharedObjects (comp : * Compilation , prog_node : std.Progress.Node ) void {
4982
+ if (netbsd .buildSharedObjects (comp , prog_node )) | _ | {
4983
+ // The job should no longer be queued up since it succeeded.
4984
+ comp .queued_jobs .netbsd_shared_objects = false ;
4985
+ } else | err | switch (err ) {
4986
+ error .SubCompilationFailed = > return , // error reported already
4987
+ else = > comp .lockAndSetMiscFailure (.netbsd_shared_objects , "unable to build NetBSD libc shared objects: {s}" , .{
4988
+ @errorName (err ),
4989
+ }),
4990
+ }
4991
+ }
4992
+
4936
4993
fn buildMingwCrtFile (comp : * Compilation , crt_file : mingw.CrtFile , prog_node : std.Progress.Node ) void {
4937
4994
if (mingw .buildCrtFile (comp , crt_file , prog_node )) | _ | {
4938
4995
comp .queued_jobs .mingw_crt_file [@intFromEnum (crt_file )] = false ;
0 commit comments