Skip to content

Commit 991dd60

Browse files
committed
Implement OCaml compiler support
1 parent 45acaa5 commit 991dd60

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/Rootfs.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ struct RustBuild <: CompilerBuild
383383
version::VersionNumber
384384
end
385385

386+
struct OCamlBuild <: CompilerBuild
387+
version::VersionNumber
388+
end
389+
386390
getversion(c::CompilerBuild) = c.version
387391
getabi(c::CompilerBuild) = c.abi
388392

@@ -413,6 +417,8 @@ const available_go_builds = GoBuild.(get_available_builds("Go."))
413417

414418
const available_rust_builds = RustBuild.(get_available_builds("RustBase."))
415419

420+
const available_ocaml_builds = OCamlBuild.(get_available_builds("OCaml."))
421+
416422
"""
417423
gcc_version(p::AbstractPlatform, GCC_builds::Vector{GCCBuild},
418424
compilers::Vector{Symbol}=[:c];
@@ -581,6 +587,7 @@ function choose_shards(p::AbstractPlatform;
581587
LLVM_builds::Vector{LLVMBuild}=available_llvm_builds,
582588
Rust_builds::Vector{RustBuild}=available_rust_builds,
583589
Go_builds::Vector{GoBuild}=available_go_builds,
590+
OCaml_builds::Vector{OCamlBuild}=available_ocaml_builds,
584591
archive_type::Symbol = (use_squashfs[] ? :squashfs : :unpacked),
585592
bootstrap_list::Vector{Symbol} = bootstrap_list,
586593
# Because GCC has lots of compatibility issues, we always default to
@@ -594,6 +601,8 @@ function choose_shards(p::AbstractPlatform;
594601
preferred_rust_version::VersionNumber = maximum(getversion.(Rust_builds)),
595602
# Always default to the latest Go version
596603
preferred_go_version::VersionNumber = maximum(getversion.(Go_builds)),
604+
# Always default to the latest OCaml version
605+
preferred_ocaml_version::VersionNumber = maximum(getversion.(OCaml_builds)),
597606
)
598607

599608
function find_shard(name, version, archive_type; target = nothing)
@@ -708,6 +717,17 @@ function choose_shards(p::AbstractPlatform;
708717

709718
push!(shards, find_shard("Go", Go_build, archive_type))
710719
end
720+
721+
if :ocaml in compilers
722+
# Make sure the selected Go toolchain version is available
723+
if preferred_ocaml_version in getversion.(OCaml_builds)
724+
OCaml_build = preferred_ocaml_version
725+
else
726+
error("Requested OCaml toolchain $(preferred_ocaml_version) not available in $(OCaml_builds)")
727+
end
728+
729+
push!(shards, find_shard("OCaml", OCaml_build, archive_type))
730+
end
711731
else
712732
function find_latest_version(name)
713733
versions = [cs.version for cs in all_compiler_shards()

src/Runner.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,14 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
722722
end
723723
gofmt(io::IO, p::AbstractPlatform) = wrapper(io, "/opt/$(host_target)/go/bin/gofmt"; allow_ccache=false)
724724

725+
# OCaml stuff
726+
function ocaml_wrapper(io::IO, tool::String, p::AbstractPlatform)
727+
return wrapper(io, "/opt/$(aatriplet(p))/bin/$(aatriplet(p))-$(tool)")
728+
end
729+
ocamlc(io::IO, p::AbstractPlatform) = ocaml_wrapper(io, "ocamlc.opt", p)
730+
ocamlopt(io::IO, p::AbstractPlatform) = ocaml_wrapper(io, "ocamlopt.opt", p)
731+
flexlink(io::IO, p::AbstractPlatform) = ocaml_wrapper(io, "flexlink", p)
732+
725733
# Rust stuff
726734
function rust_flags!(p::AbstractPlatform, flags::Vector{String} = String[])
727735
if Sys.islinux(p)
@@ -958,6 +966,16 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
958966
end
959967
end
960968

969+
# Generate OCaml stuff
970+
if :ocaml in compilers
971+
write_wrapper(ocamlc, p, "$(t)-ocamlc.opt")
972+
write_wrapper(ocamlopt, p, "$(t)-ocamlopt.opt")
973+
974+
if Sys.iswindows(p)
975+
write_wrapper(flexlink, p, "$(t)-flexlink")
976+
end
977+
end
978+
961979
# Generate go stuff
962980
if :go in compilers
963981
write_wrapper(go, p, "$(t)-go")
@@ -1004,6 +1022,12 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
10041022
if :rust in compilers
10051023
append!(default_tools, ("rustc","rustup","cargo"))
10061024
end
1025+
if :ocaml in compilers
1026+
append!(default_tools, ("ocamlc.opt", "ocamlopt.opt"))
1027+
if Sys.iswindows(p)
1028+
push!(default_tools, "flexlink")
1029+
end
1030+
end
10071031
if :go in compilers
10081032
append!(default_tools, ("go", "gofmt"))
10091033
end
@@ -1261,6 +1285,11 @@ function platform_envs(platform::AbstractPlatform, src_name::AbstractString;
12611285
))
12621286
end
12631287

1288+
# OCaml stuff
1289+
if :ocaml in compilers
1290+
# no environment variables required (yet)
1291+
end
1292+
12641293
# Rust stuff
12651294
if :rust in compilers
12661295
merge!(mapping, Dict(

0 commit comments

Comments
 (0)