My aggregated monorepo of OCaml code, automaintained
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

JTW: stack tool layer as deps instead of bind-mounting binaries

Unlike odoc, jtw uses ocamlfind at runtime to discover libraries,
so it needs the full tool layer stacked (not just bind-mounted binaries).
Per-package generation now works (46/61 packages with ox compiler).

Worker.js still fails — needs js_top_worker-web which isn't in the
js_top_worker-bin solution. Day10 handled this by installing jtw
packages inside the container via opam install.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+14 -36
+14 -36
day11/jtw/generate.ml
··· 1 1 open Day11_layer.Layer_type 2 2 3 - let extract_bin ~os_dir tool_builds name = 4 - let switch = Day11_build.Types.switch in 5 - List.find_map (fun (bl : build) -> 6 - let bin = Fpath.(build_dir ~os_dir bl / "fs" / "home" / "opam" 7 - / ".opam" / switch / "bin" / name) in 8 - if Bos.OS.File.exists bin |> Result.get_ok then Some bin 9 - else None 10 - ) tool_builds 11 - 12 - let make_jtw_mounts ~os_dir ~(jtw_tool : tool) = 13 - let find name = 14 - match extract_bin ~os_dir jtw_tool.builds name with 15 - | Some p -> p 16 - | None -> failwith (Printf.sprintf "JTW binary %s not found" name) 17 - in 18 - let mount src dst = Day11_container.Mount.bind_ro 19 - ~src:(Fpath.to_string src) dst in 20 - [ mount (find "jtw") "/home/opam/jtw-tools/bin/jtw"; 21 - mount (find "js_of_ocaml") "/home/opam/jtw-tools/bin/js_of_ocaml" ] 22 - 23 - let jtw_cleanup _env upper = 24 - ignore (Day11_exec.Sudo.rm_rf _env 25 - Fpath.(upper / "home" / "opam" / "jtw-tools")) 26 - 27 3 let generate_package env benv ~os_dir ~jtw_tool (node : build) = 28 4 let pkg_dir = build_dir ~os_dir node in 29 5 let installed_libs = Day11_layer.Installed_files.scan_libs ··· 33 9 let findlib_names = Gen.findlib_names_of_installed_libs installed_libs in 34 10 if findlib_names = [] then None 35 11 else begin 36 - let jtw_mounts = make_jtw_mounts ~os_dir ~jtw_tool in 12 + (* JTW needs the full tool layer stacked (not just bind-mounted binaries) 13 + because jtw uses ocamlfind at runtime to discover libraries *) 37 14 let cmd = 38 - "export PATH=/home/opam/jtw-tools/bin:$PATH && " ^ 15 + "eval $(opam env) && " ^ 39 16 Gen.container_script ~pkg:node.pkg ~installed_libs in 40 17 let hash = Gen.compute_layer_hash 41 18 ~build_hash:node.hash ~tools_hash:jtw_tool.hash in 42 19 let jtw_node : build = 43 - { hash; pkg = node.pkg; deps = [ node ] } in 20 + { hash; pkg = node.pkg; 21 + deps = jtw_tool.builds @ [ node ] } in 44 22 match Day11_build.Build_layer.build env benv 45 - ~mounts:jtw_mounts jtw_node 46 - ~strategy:{ cmd; cleanup = jtw_cleanup } () with 23 + jtw_node 24 + ~strategy:{ cmd; cleanup = fun _ _ -> () } () with 47 25 | Day11_build.Types.Success bl -> 48 26 Printf.printf " %s: OK\n%!" (OpamPackage.to_string node.pkg); 49 27 Some bl ··· 54 32 55 33 (** Build worker.js for a solution. Stacks all build layers from the 56 34 solution and runs [jtw opam -o ... stdlib]. *) 57 - let build_worker env benv ~os_dir ~jtw_tool ~solution_nodes = 58 - let jtw_mounts = make_jtw_mounts ~os_dir ~jtw_tool in 35 + let build_worker env benv ~jtw_tool ~solution_nodes = 59 36 let cmd = 60 - "export PATH=/home/opam/jtw-tools/bin:$PATH && eval $(opam env) && " ^ 37 + "eval $(opam env) && " ^ 61 38 "jtw opam -o /home/opam/jtw-worker-output stdlib" in 62 39 let dep_hashes = List.map (fun (n : build) -> n.hash) solution_nodes in 63 40 let hash = Day11_layer.Hash.of_strings 64 41 ([ "jtw-worker"; jtw_tool.hash ] @ dep_hashes) in 65 42 let dummy_pkg = OpamPackage.of_string "jtw-worker.0" in 66 43 let worker_node : build = 67 - { hash; pkg = dummy_pkg; deps = solution_nodes } in 44 + { hash; pkg = dummy_pkg; 45 + deps = jtw_tool.builds @ solution_nodes } in 68 46 match Day11_build.Build_layer.build env benv 69 - ~mounts:jtw_mounts worker_node 70 - ~strategy:{ cmd; cleanup = jtw_cleanup } () with 47 + worker_node 48 + ~strategy:{ cmd; cleanup = fun _ _ -> () } () with 71 49 | Day11_build.Types.Success bl -> 72 50 Printf.printf " worker.js: OK\n%!"; 73 51 Some bl ··· 118 96 let solution_nodes = List.filter (fun (node : build) -> 119 97 OpamPackage.Map.mem node.pkg solution 120 98 ) nodes in 121 - match build_worker env benv ~os_dir ~jtw_tool ~solution_nodes with 99 + match build_worker env benv ~jtw_tool ~solution_nodes with 122 100 | Some bl -> Some (compiler, bl) 123 101 | None -> None 124 102 ) solutions in