| ... | @@ -734,6 +734,7 @@ pub const MiscTask = enum { | ... | @@ -734,6 +734,7 @@ pub const MiscTask = enum { |
| 734 | zig_libc, | 734 | zig_libc, |
| 735 | analyze_mod, | 735 | analyze_mod, |
| 736 | docs_copy, | 736 | docs_copy, |
| | 737 | docs_wasm, |
| 737 | | 738 | |
| 738 | @"musl crti.o", | 739 | @"musl crti.o", |
| 739 | @"musl crtn.o", | 740 | @"musl crtn.o", |
| ... | @@ -3322,6 +3323,9 @@ pub fn performAllTheWork( | ... | @@ -3322,6 +3323,9 @@ pub fn performAllTheWork( |
| 3322 | var zir_prog_node = main_progress_node.start("AST Lowering", 0); | 3323 | var zir_prog_node = main_progress_node.start("AST Lowering", 0); |
| 3323 | defer zir_prog_node.end(); | 3324 | defer zir_prog_node.end(); |
| 3324 | | 3325 | |
| | 3326 | var wasm_prog_node = main_progress_node.start("Compile Autodocs", 0); |
| | 3327 | defer wasm_prog_node.end(); |
| | 3328 | |
| 3325 | var c_obj_prog_node = main_progress_node.start("Compile C Objects", comp.c_source_files.len); | 3329 | var c_obj_prog_node = main_progress_node.start("Compile C Objects", comp.c_source_files.len); |
| 3326 | defer c_obj_prog_node.end(); | 3330 | defer c_obj_prog_node.end(); |
| 3327 | | 3331 | |
| ... | @@ -3334,7 +3338,7 @@ pub fn performAllTheWork( | ... | @@ -3334,7 +3338,7 @@ pub fn performAllTheWork( |
| 3334 | if (!build_options.only_c and !build_options.only_core_functionality) { | 3338 | if (!build_options.only_c and !build_options.only_core_functionality) { |
| 3335 | if (comp.docs_emit != null) { | 3339 | if (comp.docs_emit != null) { |
| 3336 | try taskDocsCopy(comp, &comp.work_queue_wait_group); | 3340 | try taskDocsCopy(comp, &comp.work_queue_wait_group); |
| 3337 | try taskDocsWasm(comp, &comp.work_queue_wait_group); | 3341 | comp.work_queue_wait_group.spawnManager(workerDocsWasm, .{ comp, &wasm_prog_node }); |
| 3338 | } | 3342 | } |
| 3339 | } | 3343 | } |
| 3340 | | 3344 | |
| ... | @@ -3758,12 +3762,6 @@ fn taskDocsCopy(comp: *Compilation, wg: *WaitGroup) !void { | ... | @@ -3758,12 +3762,6 @@ fn taskDocsCopy(comp: *Compilation, wg: *WaitGroup) !void { |
| 3758 | try comp.thread_pool.spawn(workerDocsCopy, .{ comp, wg }); | 3762 | try comp.thread_pool.spawn(workerDocsCopy, .{ comp, wg }); |
| 3759 | } | 3763 | } |
| 3760 | | 3764 | |
| 3761 | fn taskDocsWasm(comp: *Compilation, wg: *WaitGroup) !void { | | |
| 3762 | wg.start(); | | |
| 3763 | errdefer wg.finish(); | | |
| 3764 | try comp.thread_pool.spawn(workerDocsWasm, .{ comp, wg }); | | |
| 3765 | } | | |
| 3766 | | | |
| 3767 | fn workerDocsCopy(comp: *Compilation, wg: *WaitGroup) void { | 3765 | fn workerDocsCopy(comp: *Compilation, wg: *WaitGroup) void { |
| 3768 | defer wg.finish(); | 3766 | defer wg.finish(); |
| 3769 | docsCopyFallible(comp) catch |err| { | 3767 | docsCopyFallible(comp) catch |err| { |
| ... | @@ -3869,11 +3867,141 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void { | ... | @@ -3869,11 +3867,141 @@ fn docsCopyFallible(comp: *Compilation) anyerror!void { |
| 3869 | } | 3867 | } |
| 3870 | } | 3868 | } |
| 3871 | | 3869 | |
| 3872 | fn workerDocsWasm(comp: *Compilation, wg: *WaitGroup) void { | 3870 | fn workerDocsWasm(comp: *Compilation, prog_node: *std.Progress.Node) void { |
| 3873 | defer wg.finish(); | 3871 | workerDocsWasmFallible(comp, prog_node) catch |err| { |
| | 3872 | comp.lockAndSetMiscFailure(.docs_wasm, "unable to build autodocs: {s}", .{ |
| | 3873 | @errorName(err), |
| | 3874 | }); |
| | 3875 | }; |
| | 3876 | } |
| | 3877 | |
| | 3878 | fn workerDocsWasmFallible(comp: *Compilation, prog_node: *std.Progress.Node) anyerror!void { |
| | 3879 | const gpa = comp.gpa; |
| | 3880 | |
| | 3881 | var arena_allocator = std.heap.ArenaAllocator.init(gpa); |
| | 3882 | defer arena_allocator.deinit(); |
| | 3883 | const arena = arena_allocator.allocator(); |
| | 3884 | |
| | 3885 | const optimize_mode = std.builtin.OptimizeMode.ReleaseSmall; |
| | 3886 | const output_mode = std.builtin.OutputMode.Exe; |
| | 3887 | const resolved_target: Package.Module.ResolvedTarget = .{ |
| | 3888 | .result = std.zig.system.resolveTargetQuery(.{ |
| | 3889 | .cpu_arch = .wasm32, |
| | 3890 | .os_tag = .freestanding, |
| | 3891 | .cpu_features_add = std.Target.wasm.featureSet(&.{ |
| | 3892 | .atomics, |
| | 3893 | .bulk_memory, |
| | 3894 | // .extended_const, not supported by Safari |
| | 3895 | .multivalue, |
| | 3896 | .mutable_globals, |
| | 3897 | .nontrapping_fptoint, |
| | 3898 | .reference_types, |
| | 3899 | //.relaxed_simd, not supported by Firefox or Safari |
| | 3900 | .sign_ext, |
| | 3901 | // observed to cause Error occured during wast conversion : |
| | 3902 | // Unknown operator: 0xfd058 in Firefox 117 |
| | 3903 | //.simd128, |
| | 3904 | // .tail_call, not supported by Safari |
| | 3905 | }), |
| | 3906 | }) catch unreachable, |
| | 3907 | |
| | 3908 | .is_native_os = false, |
| | 3909 | .is_native_abi = false, |
| | 3910 | }; |
| | 3911 | |
| | 3912 | const config = try Config.resolve(.{ |
| | 3913 | .output_mode = output_mode, |
| | 3914 | .resolved_target = resolved_target, |
| | 3915 | .is_test = false, |
| | 3916 | .have_zcu = true, |
| | 3917 | .emit_bin = true, |
| | 3918 | .root_optimize_mode = optimize_mode, |
| | 3919 | .link_libc = false, |
| | 3920 | .rdynamic = true, |
| | 3921 | }); |
| | 3922 | |
| | 3923 | const src_basename = "main.zig"; |
| | 3924 | const root_name = std.fs.path.stem(src_basename); |
| | 3925 | |
| | 3926 | const root_mod = try Package.Module.create(arena, .{ |
| | 3927 | .global_cache_directory = comp.global_cache_directory, |
| | 3928 | .paths = .{ |
| | 3929 | .root = .{ |
| | 3930 | .root_dir = comp.zig_lib_directory, |
| | 3931 | .sub_path = "docs/wasm", |
| | 3932 | }, |
| | 3933 | .root_src_path = src_basename, |
| | 3934 | }, |
| | 3935 | .fully_qualified_name = root_name, |
| | 3936 | .inherited = .{ |
| | 3937 | .resolved_target = resolved_target, |
| | 3938 | .optimize_mode = optimize_mode, |
| | 3939 | }, |
| | 3940 | .global = config, |
| | 3941 | .cc_argv = &.{}, |
| | 3942 | .parent = null, |
| | 3943 | .builtin_mod = null, |
| | 3944 | }); |
| | 3945 | const bin_basename = try std.zig.binNameAlloc(arena, .{ |
| | 3946 | .root_name = root_name, |
| | 3947 | .target = resolved_target.result, |
| | 3948 | .output_mode = output_mode, |
| | 3949 | }); |
| | 3950 | |
| | 3951 | const sub_compilation = try Compilation.create(gpa, arena, .{ |
| | 3952 | .global_cache_directory = comp.global_cache_directory, |
| | 3953 | .local_cache_directory = comp.global_cache_directory, |
| | 3954 | .zig_lib_directory = comp.zig_lib_directory, |
| | 3955 | .self_exe_path = comp.self_exe_path, |
| | 3956 | .config = config, |
| | 3957 | .root_mod = root_mod, |
| | 3958 | .entry = .disabled, |
| | 3959 | .cache_mode = .whole, |
| | 3960 | .root_name = root_name, |
| | 3961 | .thread_pool = comp.thread_pool, |
| | 3962 | .libc_installation = comp.libc_installation, |
| | 3963 | .emit_bin = .{ |
| | 3964 | .directory = null, // Put it in the cache directory. |
| | 3965 | .basename = bin_basename, |
| | 3966 | }, |
| | 3967 | .verbose_cc = comp.verbose_cc, |
| | 3968 | .verbose_link = comp.verbose_link, |
| | 3969 | .verbose_air = comp.verbose_air, |
| | 3970 | .verbose_intern_pool = comp.verbose_intern_pool, |
| | 3971 | .verbose_generic_instances = comp.verbose_intern_pool, |
| | 3972 | .verbose_llvm_ir = comp.verbose_llvm_ir, |
| | 3973 | .verbose_llvm_bc = comp.verbose_llvm_bc, |
| | 3974 | .verbose_cimport = comp.verbose_cimport, |
| | 3975 | .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features, |
| | 3976 | }); |
| | 3977 | defer sub_compilation.destroy(); |
| | 3978 | |
| | 3979 | try comp.updateSubCompilation(sub_compilation, .docs_wasm, prog_node); |
| | 3980 | |
| | 3981 | const emit = comp.docs_emit.?; |
| | 3982 | var out_dir = emit.directory.handle.makeOpenPath(emit.sub_path, .{}) catch |err| { |
| | 3983 | return comp.lockAndSetMiscFailure( |
| | 3984 | .docs_copy, |
| | 3985 | "unable to create output directory '{}{s}': {s}", |
| | 3986 | .{ emit.directory, emit.sub_path, @errorName(err) }, |
| | 3987 | ); |
| | 3988 | }; |
| | 3989 | defer out_dir.close(); |
| 3874 | | 3990 | |
| 3875 | _ = comp; | 3991 | sub_compilation.local_cache_directory.handle.copyFile( |
| 3876 | log.err("TODO workerDocsWasm", .{}); | 3992 | sub_compilation.cache_use.whole.bin_sub_path.?, |
| | 3993 | out_dir, |
| | 3994 | "main.wasm", |
| | 3995 | .{}, |
| | 3996 | ) catch |err| { |
| | 3997 | return comp.lockAndSetMiscFailure(.docs_copy, "unable to copy '{}{s}' to '{}{s}': {s}", .{ |
| | 3998 | sub_compilation.local_cache_directory, |
| | 3999 | sub_compilation.cache_use.whole.bin_sub_path.?, |
| | 4000 | emit.directory, |
| | 4001 | emit.sub_path, |
| | 4002 | @errorName(err), |
| | 4003 | }); |
| | 4004 | }; |
| 3877 | } | 4005 | } |
| 3878 | | 4006 | |
| 3879 | const AstGenSrc = union(enum) { | 4007 | const AstGenSrc = union(enum) { |