@@ -23,6 +23,7 @@ const build_options = @import("build_options");
23
23
const LibCInstallation = std .zig .LibCInstallation ;
24
24
const glibc = @import ("libs/glibc.zig" );
25
25
const musl = @import ("libs/musl.zig" );
26
+ const freebsd = @import ("libs/freebsd.zig" );
26
27
const mingw = @import ("libs/mingw.zig" );
27
28
const libunwind = @import ("libs/libunwind.zig" );
28
29
const libcxx = @import ("libs/libcxx.zig" );
@@ -248,6 +249,7 @@ compiler_rt_obj: ?CrtFile = null,
248
249
fuzzer_lib : ? CrtFile = null ,
249
250
250
251
glibc_so_files : ? glibc.BuiltSharedObjects = null ,
252
+ freebsd_so_files : ? freebsd.BuiltSharedObjects = null ,
251
253
wasi_emulated_libs : []const wasi_libc.CrtFile ,
252
254
253
255
/// For example `Scrt1.o` and `libc_nonshared.a`. These are populated after building libc from source,
@@ -294,12 +296,14 @@ const QueuedJobs = struct {
294
296
update_builtin_zig : bool ,
295
297
musl_crt_file : [@typeInfo (musl .CrtFile ).@"enum" .fields .len ]bool = @splat (false ),
296
298
glibc_crt_file : [@typeInfo (glibc .CrtFile ).@"enum" .fields .len ]bool = @splat (false ),
299
+ freebsd_crt_file : [@typeInfo (freebsd .CrtFile ).@"enum" .fields .len ]bool = @splat (false ),
297
300
/// one of WASI libc static objects
298
301
wasi_libc_crt_file : [@typeInfo (wasi_libc .CrtFile ).@"enum" .fields .len ]bool = @splat (false ),
299
302
/// one of the mingw-w64 static objects
300
303
mingw_crt_file : [@typeInfo (mingw .CrtFile ).@"enum" .fields .len ]bool = @splat (false ),
301
304
/// all of the glibc shared objects
302
305
glibc_shared_objects : bool = false ,
306
+ freebsd_shared_objects : bool = false ,
303
307
/// libunwind.a, usually needed when linking libc
304
308
libunwind : bool = false ,
305
309
libcxx : bool = false ,
@@ -789,6 +793,8 @@ pub const MiscTask = enum {
789
793
glibc_crt_file ,
790
794
glibc_shared_objects ,
791
795
musl_crt_file ,
796
+ freebsd_crt_file ,
797
+ freebsd_shared_objects ,
792
798
mingw_crt_file ,
793
799
windows_import_lib ,
794
800
libunwind ,
@@ -823,6 +829,9 @@ pub const MiscTask = enum {
823
829
@"glibc libc_nonshared.a" ,
824
830
@"glibc shared object" ,
825
831
832
+ @"freebsd libc Scrt1.o" ,
833
+ @"freebsd libc shared object" ,
834
+
826
835
@"mingw-w64 crt2.o" ,
827
836
@"mingw-w64 dllcrt2.o" ,
828
837
@"mingw-w64 libmingw32.lib" ,
@@ -1874,6 +1883,16 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
1874
1883
1875
1884
comp .queued_jobs .glibc_crt_file [@intFromEnum (glibc .CrtFile .libc_nonshared_a )] = true ;
1876
1885
comp .remaining_prelink_tasks += 1 ;
1886
+ } else if (target .isFreeBSDLibC ()) {
1887
+ if (! std .zig .target .canBuildLibC (target )) return error .LibCUnavailable ;
1888
+
1889
+ if (freebsd .needsCrt0 (comp .config .output_mode )) | f | {
1890
+ comp .queued_jobs .freebsd_crt_file [@intFromEnum (f )] = true ;
1891
+ comp .remaining_prelink_tasks += 1 ;
1892
+ }
1893
+
1894
+ comp .queued_jobs .freebsd_shared_objects = true ;
1895
+ comp .remaining_prelink_tasks += freebsd .sharedObjectsCount ();
1877
1896
} else if (target .isWasiLibC ()) {
1878
1897
if (! std .zig .target .canBuildLibC (target )) return error .LibCUnavailable ;
1879
1898
@@ -2028,6 +2047,10 @@ pub fn destroy(comp: *Compilation) void {
2028
2047
glibc_file .deinit (gpa );
2029
2048
}
2030
2049
2050
+ if (comp .freebsd_so_files ) | * freebsd_file | {
2051
+ freebsd_file .deinit (gpa );
2052
+ }
2053
+
2031
2054
for (comp .c_object_table .keys ()) | key | {
2032
2055
key .destroy (gpa );
2033
2056
}
@@ -3839,6 +3862,10 @@ fn performAllTheWorkInner(
3839
3862
comp .link_task_wait_group .spawnManager (buildGlibcSharedObjects , .{ comp , main_progress_node });
3840
3863
}
3841
3864
3865
+ if (comp .queued_jobs .freebsd_shared_objects ) {
3866
+ comp .link_task_wait_group .spawnManager (buildFreeBSDSharedObjects , .{ comp , main_progress_node });
3867
+ }
3868
+
3842
3869
if (comp .queued_jobs .libunwind ) {
3843
3870
comp .link_task_wait_group .spawnManager (buildLibUnwind , .{ comp , main_progress_node });
3844
3871
}
@@ -3873,6 +3900,13 @@ fn performAllTheWorkInner(
3873
3900
}
3874
3901
}
3875
3902
3903
+ for (0.. @typeInfo (freebsd .CrtFile ).@"enum" .fields .len ) | i | {
3904
+ if (comp .queued_jobs .freebsd_crt_file [i ]) {
3905
+ const tag : freebsd.CrtFile = @enumFromInt (i );
3906
+ comp .link_task_wait_group .spawnManager (buildFreeBSDCrtFile , .{ comp , tag , main_progress_node });
3907
+ }
3908
+ }
3909
+
3876
3910
for (0.. @typeInfo (wasi_libc .CrtFile ).@"enum" .fields .len ) | i | {
3877
3911
if (comp .queued_jobs .wasi_libc_crt_file [i ]) {
3878
3912
const tag : wasi_libc.CrtFile = @enumFromInt (i );
@@ -4876,6 +4910,29 @@ fn buildGlibcSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) voi
4876
4910
}
4877
4911
}
4878
4912
4913
+ fn buildFreeBSDCrtFile (comp : * Compilation , crt_file : freebsd.CrtFile , prog_node : std.Progress.Node ) void {
4914
+ if (freebsd .buildCrtFile (comp , crt_file , prog_node )) | _ | {
4915
+ comp .queued_jobs .freebsd_crt_file [@intFromEnum (crt_file )] = false ;
4916
+ } else | err | switch (err ) {
4917
+ error .SubCompilationFailed = > return , // error reported already
4918
+ else = > comp .lockAndSetMiscFailure (.freebsd_crt_file , "unable to build FreeBSD {s}: {s}" , .{
4919
+ @tagName (crt_file ), @errorName (err ),
4920
+ }),
4921
+ }
4922
+ }
4923
+
4924
+ fn buildFreeBSDSharedObjects (comp : * Compilation , prog_node : std.Progress.Node ) void {
4925
+ if (freebsd .buildSharedObjects (comp , prog_node )) | _ | {
4926
+ // The job should no longer be queued up since it succeeded.
4927
+ comp .queued_jobs .freebsd_shared_objects = false ;
4928
+ } else | err | switch (err ) {
4929
+ error .SubCompilationFailed = > return , // error reported already
4930
+ else = > comp .lockAndSetMiscFailure (.freebsd_shared_objects , "unable to build FreeBSD libc shared objects: {s}" , .{
4931
+ @errorName (err ),
4932
+ }),
4933
+ }
4934
+ }
4935
+
4879
4936
fn buildMingwCrtFile (comp : * Compilation , crt_file : mingw.CrtFile , prog_node : std.Progress.Node ) void {
4880
4937
if (mingw .buildCrtFile (comp , crt_file , prog_node )) | _ | {
4881
4938
comp .queued_jobs .mingw_crt_file [@intFromEnum (crt_file )] = false ;
0 commit comments