Skip to content

Commit 947dc30

Browse files
hyperpolymathclaude
andcommitted
fix(build): declare js_of_ocaml deps + install with-test in lint job
After PR #68 tracked the 23 codegen modules and resolved the "Module Wgsl_codegen doesn't exist" error, two pre-existing under-declared-dependency issues are now visible: 1. js/dune (the playground executable) requires `js_of_ocaml` and `js_of_ocaml-ppx` libraries plus the `js_of_ocaml` binary. None were in the dune-project depends or the generated .opam file. Added `(js_of_ocaml (>= 5.0))` and `(js_of_ocaml-ppx (>= 5.0))` to dune-project; mirrored into affinescript.opam (since CI's `opam install . --deps-only` reads the .opam directly, not dune-project). 2. test/dune requires `alcotest`, declared in opam as `with-test`. The CI build job installs with `--with-test --with-doc`, but the lint job installed with bare `--deps-only`. Both jobs run `dune build` which compiles test/ regardless. Added the same --with-test --with-doc flags to lint. Signed-off-by: Jonathan D.A. Jewell <6759885+hyperpolymath@users.noreply.github.com> Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Jonathan D.A. Jewell <6759885+hyperpolymath@users.noreply.github.com>
1 parent 03ce21b commit 947dc30

14 files changed

Lines changed: 950 additions & 24 deletions

.github/workflows/ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ jobs:
5959
ocaml-compiler: "5.1"
6060

6161
- name: Install dependencies
62-
run: opam install . --deps-only
62+
# Match the build job: `dune build` compiles everything including
63+
# test/ (which depends on alcotest, with-test) and the @doc target
64+
# below (which depends on odoc, with-doc). Without these flags, lint
65+
# fails on missing alcotest before it ever reaches the doc step.
66+
run: opam install . --deps-only --with-test --with-doc
6367

6468
- name: Build
6569
run: opam exec -- dune build

affinescript.opam

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ depends: [
3434
"yojson" {>= "2.1"}
3535
"alcotest" {>= "1.7" & with-test}
3636
"odoc" {>= "2.4" & with-doc}
37+
"js_of_ocaml" {>= "5.0"}
38+
"js_of_ocaml-ppx" {>= "5.0"}
3739
]
3840
build: [
3941
["dune" "subst"] {dev}

bin/main.ml

Lines changed: 174 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,24 @@ let compile_file face json wasm_gc path output =
507507
let is_js = Filename.check_suffix output ".js" in
508508
let is_c = Filename.check_suffix output ".c" in
509509
let is_wgsl = Filename.check_suffix output ".wgsl" in
510+
let is_faust = Filename.check_suffix output ".dsp" in
511+
let is_onnx = Filename.check_suffix output ".onnx" in
512+
let is_ocaml = Filename.check_suffix output ".ml" in
513+
let is_lua = Filename.check_suffix output ".lua" in
514+
let is_bash = Filename.check_suffix output ".sh" in
515+
let is_nickel = Filename.check_suffix output ".ncl" in
516+
let is_rescript = Filename.check_suffix output ".res" in
517+
let is_rust = Filename.check_suffix output ".rs" in
518+
let is_llvm = Filename.check_suffix output ".ll" in
519+
let is_verilog = Filename.check_suffix output ".v" in
520+
let is_gleam = Filename.check_suffix output ".gleam" in
521+
let is_cuda = Filename.check_suffix output ".cu" in
522+
let is_metal = Filename.check_suffix output ".metal" in
523+
let is_opencl = Filename.check_suffix output ".cl" in
524+
let is_mlir = Filename.check_suffix output ".mlir" in
525+
let is_why3 = Filename.check_suffix output ".mlw" in
526+
let is_lean = Filename.check_suffix output ".lean" in
527+
let is_spirv = Filename.check_suffix output ".spv" in
510528
if is_julia then begin
511529
match Affinescript.Julia_codegen.codegen_julia prog resolve_ctx.symbols with
512530
| Error msg ->
@@ -547,6 +565,73 @@ let compile_file face json wasm_gc path output =
547565
let oc = open_out output in
548566
output_string oc wgsl_code;
549567
close_out oc
568+
end else if is_faust then begin
569+
match Affinescript.Faust_codegen.codegen_faust prog resolve_ctx.symbols with
570+
| Error msg ->
571+
add { severity = Error; code = "E0806";
572+
message = Printf.sprintf "Faust codegen error: %s" msg;
573+
span = Affinescript.Span.dummy; help = None; labels = [] }
574+
| Ok faust_code ->
575+
let oc = open_out output in
576+
output_string oc faust_code;
577+
close_out oc
578+
end else if is_onnx then begin
579+
match Affinescript.Onnx_codegen.codegen_onnx prog resolve_ctx.symbols with
580+
| Error msg ->
581+
add { severity = Error; code = "E0807";
582+
message = Printf.sprintf "ONNX codegen error: %s" msg;
583+
span = Affinescript.Span.dummy; help = None; labels = [] }
584+
| Ok bytes ->
585+
let oc = open_out_bin output in
586+
output_string oc bytes;
587+
close_out oc
588+
end else if is_ocaml || is_lua || is_bash || is_nickel || is_rescript
589+
|| is_rust || is_llvm || is_verilog || is_gleam
590+
|| is_cuda || is_metal || is_opencl || is_mlir
591+
|| is_why3 || is_lean || is_spirv then begin
592+
let (label, code, result) =
593+
if is_ocaml then ("OCaml", "E0808",
594+
Affinescript.Ocaml_codegen.codegen_ocaml prog resolve_ctx.symbols)
595+
else if is_lua then ("Lua", "E0809",
596+
Affinescript.Lua_codegen.codegen_lua prog resolve_ctx.symbols)
597+
else if is_bash then ("Bash", "E0810",
598+
Affinescript.Bash_codegen.codegen_bash prog resolve_ctx.symbols)
599+
else if is_nickel then ("Nickel", "E0811",
600+
Affinescript.Nickel_codegen.codegen_nickel prog resolve_ctx.symbols)
601+
else if is_rescript then ("ReScript", "E0812",
602+
Affinescript.Rescript_codegen.codegen_rescript prog resolve_ctx.symbols)
603+
else if is_rust then ("Rust", "E0813",
604+
Affinescript.Rust_codegen.codegen_rust prog resolve_ctx.symbols)
605+
else if is_llvm then ("LLVM", "E0814",
606+
Affinescript.Llvm_codegen.codegen_llvm prog resolve_ctx.symbols)
607+
else if is_verilog then ("Verilog", "E0815",
608+
Affinescript.Verilog_codegen.codegen_verilog prog resolve_ctx.symbols)
609+
else if is_gleam then ("Gleam", "E0816",
610+
Affinescript.Gleam_codegen.codegen_gleam prog resolve_ctx.symbols)
611+
else if is_cuda then ("CUDA", "E0817",
612+
Affinescript.Cuda_codegen.codegen_cuda prog resolve_ctx.symbols)
613+
else if is_metal then ("Metal", "E0818",
614+
Affinescript.Metal_codegen.codegen_metal prog resolve_ctx.symbols)
615+
else if is_opencl then ("OpenCL", "E0819",
616+
Affinescript.Opencl_codegen.codegen_opencl prog resolve_ctx.symbols)
617+
else if is_mlir then ("MLIR", "E0820",
618+
Affinescript.Mlir_codegen.codegen_mlir prog resolve_ctx.symbols)
619+
else if is_why3 then ("Why3", "E0821",
620+
Affinescript.Why3_codegen.codegen_why3 prog resolve_ctx.symbols)
621+
else if is_lean then ("Lean", "E0822",
622+
Affinescript.Lean_codegen.codegen_lean prog resolve_ctx.symbols)
623+
else ("SPIR-V", "E0823",
624+
Affinescript.Spirv_codegen.codegen_spirv prog resolve_ctx.symbols)
625+
in
626+
match result with
627+
| Error msg ->
628+
add { severity = Error; code;
629+
message = Printf.sprintf "%s codegen error: %s" label msg;
630+
span = Affinescript.Span.dummy; help = None; labels = [] }
631+
| Ok src ->
632+
let oc = if is_spirv then open_out_bin output else open_out output in
633+
output_string oc src;
634+
close_out oc
550635
end else if wasm_gc then begin
551636
match Affinescript.Codegen_gc.generate_gc_module prog with
552637
| Error e ->
@@ -609,6 +694,24 @@ let compile_file face json wasm_gc path output =
609694
let is_js = Filename.check_suffix output ".js" in
610695
let is_c = Filename.check_suffix output ".c" in
611696
let is_wgsl = Filename.check_suffix output ".wgsl" in
697+
let is_faust = Filename.check_suffix output ".dsp" in
698+
let is_onnx = Filename.check_suffix output ".onnx" in
699+
let is_ocaml = Filename.check_suffix output ".ml" in
700+
let is_lua = Filename.check_suffix output ".lua" in
701+
let is_bash = Filename.check_suffix output ".sh" in
702+
let is_nickel = Filename.check_suffix output ".ncl" in
703+
let is_rescript = Filename.check_suffix output ".res" in
704+
let is_rust = Filename.check_suffix output ".rs" in
705+
let is_llvm = Filename.check_suffix output ".ll" in
706+
let is_verilog = Filename.check_suffix output ".v" in
707+
let is_gleam = Filename.check_suffix output ".gleam" in
708+
let is_cuda = Filename.check_suffix output ".cu" in
709+
let is_metal = Filename.check_suffix output ".metal" in
710+
let is_opencl = Filename.check_suffix output ".cl" in
711+
let is_mlir = Filename.check_suffix output ".mlir" in
712+
let is_why3 = Filename.check_suffix output ".mlw" in
713+
let is_lean = Filename.check_suffix output ".lean" in
714+
let is_spirv = Filename.check_suffix output ".spv" in
612715
if is_julia then
613716
(match Affinescript.Julia_codegen.codegen_julia prog resolve_ctx.symbols with
614717
| Error e ->
@@ -653,6 +756,76 @@ let compile_file face json wasm_gc path output =
653756
close_out oc;
654757
Format.printf "Compiled %s -> %s (WGSL)@." path output;
655758
`Ok ())
759+
else if is_faust then
760+
(match Affinescript.Faust_codegen.codegen_faust prog resolve_ctx.symbols with
761+
| Error e ->
762+
Format.eprintf "@[<v>Faust codegen error: %s@]@." e;
763+
`Error (false, "Faust codegen error")
764+
| Ok faust_code ->
765+
let oc = open_out output in
766+
output_string oc faust_code;
767+
close_out oc;
768+
Format.printf "Compiled %s -> %s (Faust)@." path output;
769+
`Ok ())
770+
else if is_onnx then
771+
(match Affinescript.Onnx_codegen.codegen_onnx prog resolve_ctx.symbols with
772+
| Error e ->
773+
Format.eprintf "@[<v>ONNX codegen error: %s@]@." e;
774+
`Error (false, "ONNX codegen error")
775+
| Ok bytes ->
776+
let oc = open_out_bin output in
777+
output_string oc bytes;
778+
close_out oc;
779+
Format.printf "Compiled %s -> %s (ONNX)@." path output;
780+
`Ok ())
781+
else if is_ocaml || is_lua || is_bash || is_nickel || is_rescript
782+
|| is_rust || is_llvm || is_verilog || is_gleam
783+
|| is_cuda || is_metal || is_opencl || is_mlir
784+
|| is_why3 || is_lean || is_spirv then
785+
let (label, result) =
786+
if is_ocaml then ("OCaml",
787+
Affinescript.Ocaml_codegen.codegen_ocaml prog resolve_ctx.symbols)
788+
else if is_lua then ("Lua",
789+
Affinescript.Lua_codegen.codegen_lua prog resolve_ctx.symbols)
790+
else if is_bash then ("Bash",
791+
Affinescript.Bash_codegen.codegen_bash prog resolve_ctx.symbols)
792+
else if is_nickel then ("Nickel",
793+
Affinescript.Nickel_codegen.codegen_nickel prog resolve_ctx.symbols)
794+
else if is_rescript then ("ReScript",
795+
Affinescript.Rescript_codegen.codegen_rescript prog resolve_ctx.symbols)
796+
else if is_rust then ("Rust",
797+
Affinescript.Rust_codegen.codegen_rust prog resolve_ctx.symbols)
798+
else if is_llvm then ("LLVM",
799+
Affinescript.Llvm_codegen.codegen_llvm prog resolve_ctx.symbols)
800+
else if is_verilog then ("Verilog",
801+
Affinescript.Verilog_codegen.codegen_verilog prog resolve_ctx.symbols)
802+
else if is_gleam then ("Gleam",
803+
Affinescript.Gleam_codegen.codegen_gleam prog resolve_ctx.symbols)
804+
else if is_cuda then ("CUDA",
805+
Affinescript.Cuda_codegen.codegen_cuda prog resolve_ctx.symbols)
806+
else if is_metal then ("Metal",
807+
Affinescript.Metal_codegen.codegen_metal prog resolve_ctx.symbols)
808+
else if is_opencl then ("OpenCL",
809+
Affinescript.Opencl_codegen.codegen_opencl prog resolve_ctx.symbols)
810+
else if is_mlir then ("MLIR",
811+
Affinescript.Mlir_codegen.codegen_mlir prog resolve_ctx.symbols)
812+
else if is_why3 then ("Why3",
813+
Affinescript.Why3_codegen.codegen_why3 prog resolve_ctx.symbols)
814+
else if is_lean then ("Lean",
815+
Affinescript.Lean_codegen.codegen_lean prog resolve_ctx.symbols)
816+
else ("SPIR-V",
817+
Affinescript.Spirv_codegen.codegen_spirv prog resolve_ctx.symbols)
818+
in
819+
(match result with
820+
| Error e ->
821+
Format.eprintf "@[<v>%s codegen error: %s@]@." label e;
822+
`Error (false, label ^ " codegen error")
823+
| Ok src ->
824+
let oc = if is_spirv then open_out_bin output else open_out output in
825+
output_string oc src;
826+
close_out oc;
827+
Format.printf "Compiled %s -> %s (%s)@." path output label;
828+
`Ok ())
656829
else if wasm_gc then
657830
(match Affinescript.Codegen_gc.generate_gc_module prog with
658831
| Error e ->
@@ -1264,7 +1437,7 @@ let repl_cmd =
12641437
Cmd.v info Term.(ret (const repl_cmd_fn $ const ()))
12651438

12661439
let compile_cmd =
1267-
let doc = "Compile a file to WebAssembly (1.0 or GC proposal), Julia (.jl), JavaScript (.js), C (.c), or a WGSL kernel (.wgsl)" in
1440+
let doc = "Compile a file to WebAssembly (1.0 or GC proposal), Julia (.jl), JavaScript (.js), C (.c), a WGSL compute kernel (.wgsl), a Faust DSP program (.dsp), or an ONNX model (.onnx)" in
12681441
let info = Cmd.info "compile" ~doc in
12691442
Cmd.v info Term.(ret (const compile_file $ face_arg $ json_arg $ wasm_gc_arg $ path_arg $ output_arg))
12701443

0 commit comments

Comments
 (0)