Skip to content

Commit 26cc6c5

Browse files
committed
Implement OCaml compiler support
1 parent 45acaa5 commit 26cc6c5

File tree

5 files changed

+234
-0
lines changed

5 files changed

+234
-0
lines changed

Artifacts.toml

+154
Original file line numberDiff line numberDiff line change
@@ -3804,6 +3804,160 @@ os = "linux"
38043804
sha256 = "80c9869b8421b7efdba72f13ec2c24c7ef77b533ad75d8c72739a312adcaef75"
38053805
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/LLVMBootstrap-v9.0.1+0/LLVMBootstrap.v9.0.1.x86_64-linux-musl.unpacked.tar.gz"
38063806

3807+
[["OCaml-aarch64-apple-darwin.v5.4.0.x86_64-linux-musl.squashfs"]]
3808+
arch = "x86_64"
3809+
git-tree-sha1 = "1f9faa347127cf618ef813b387d721e8af22c276"
3810+
lazy = true
3811+
libc = "musl"
3812+
os = "linux"
3813+
3814+
[["OCaml-aarch64-apple-darwin.v5.4.0.x86_64-linux-musl.squashfs".download]]
3815+
sha256 = "ac11194f566997f6da4a86ef39e9e28e57d33884e8467b7a48555b84797e0ee2"
3816+
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-aarch64-apple-darwin.v5.4.0.x86_64-linux-musl.squashfs.tar.gz"
3817+
3818+
[["OCaml-aarch64-apple-darwin.v5.4.0.x86_64-linux-musl.unpacked"]]
3819+
arch = "x86_64"
3820+
git-tree-sha1 = "9f0d650ccbd8200284ec7bb8100cc4c6ce44ca2c"
3821+
lazy = true
3822+
libc = "musl"
3823+
os = "linux"
3824+
3825+
[["OCaml-aarch64-apple-darwin.v5.4.0.x86_64-linux-musl.unpacked".download]]
3826+
sha256 = "8d1c3c9fdb01159c22380ff8b0178813b9b26adf78873ac970e56580fbe11037"
3827+
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-aarch64-apple-darwin.v5.4.0.x86_64-linux-musl.unpacked.tar.gz"
3828+
3829+
[["OCaml-aarch64-linux-gnu.v5.4.0.x86_64-linux-musl.squashfs"]]
3830+
arch = "x86_64"
3831+
git-tree-sha1 = "43825a0f78b3cd4537bc7450e0b9d0ca9dab2468"
3832+
lazy = true
3833+
libc = "musl"
3834+
os = "linux"
3835+
3836+
[["OCaml-aarch64-linux-gnu.v5.4.0.x86_64-linux-musl.squashfs".download]]
3837+
sha256 = "cac028a1fec129df5ca919a1c978f5333a3673025c523ffb34e3b3a67c4208c6"
3838+
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-aarch64-linux-gnu.v5.4.0.x86_64-linux-musl.squashfs.tar.gz"
3839+
3840+
[["OCaml-aarch64-linux-gnu.v5.4.0.x86_64-linux-musl.unpacked"]]
3841+
arch = "x86_64"
3842+
git-tree-sha1 = "8e050f2038df590797f3f69f158534324f7ce2c9"
3843+
lazy = true
3844+
libc = "musl"
3845+
os = "linux"
3846+
3847+
[["OCaml-aarch64-linux-gnu.v5.4.0.x86_64-linux-musl.unpacked".download]]
3848+
sha256 = "2b15cde9b66c82e4da4ec336566fb162f6bfae9d0c5187e1d23e8335de549c30"
3849+
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-aarch64-linux-gnu.v5.4.0.x86_64-linux-musl.unpacked.tar.gz"
3850+
3851+
[["OCaml-aarch64-linux-musl.v5.4.0.x86_64-linux-musl.squashfs"]]
3852+
arch = "x86_64"
3853+
git-tree-sha1 = "c27e000b6061db267d69bb554142a6036b1a1883"
3854+
lazy = true
3855+
libc = "musl"
3856+
os = "linux"
3857+
3858+
[["OCaml-aarch64-linux-musl.v5.4.0.x86_64-linux-musl.squashfs".download]]
3859+
sha256 = "7352645dc52064131f9fc20d3c8db8708400bf1b9737701339cc4b3f7febf02b"
3860+
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-aarch64-linux-musl.v5.4.0.x86_64-linux-musl.squashfs.tar.gz"
3861+
3862+
[["OCaml-aarch64-linux-musl.v5.4.0.x86_64-linux-musl.unpacked"]]
3863+
arch = "x86_64"
3864+
git-tree-sha1 = "10b7c45f5cdc390b07ac18f6de7b773bc6303070"
3865+
lazy = true
3866+
libc = "musl"
3867+
os = "linux"
3868+
3869+
[["OCaml-aarch64-linux-musl.v5.4.0.x86_64-linux-musl.unpacked".download]]
3870+
sha256 = "b3327ffe3525604f2793ab07b823ca70fcd73e0b97af733d98ccda0e0fc8f680"
3871+
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-aarch64-linux-musl.v5.4.0.x86_64-linux-musl.unpacked.tar.gz"
3872+
3873+
[["OCaml-x86_64-apple-darwin.v5.4.0.x86_64-linux-musl.squashfs"]]
3874+
arch = "x86_64"
3875+
git-tree-sha1 = "ac1a2a8809bde935390af5d6e0681c68a00a4db1"
3876+
lazy = true
3877+
libc = "musl"
3878+
os = "linux"
3879+
3880+
[["OCaml-x86_64-apple-darwin.v5.4.0.x86_64-linux-musl.squashfs".download]]
3881+
sha256 = "2a4b7d421a203e217e99034f804f46c5e3c564671bafc172eecc711e4f382726"
3882+
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-x86_64-apple-darwin.v5.4.0.x86_64-linux-musl.squashfs.tar.gz"
3883+
3884+
[["OCaml-x86_64-apple-darwin.v5.4.0.x86_64-linux-musl.unpacked"]]
3885+
arch = "x86_64"
3886+
git-tree-sha1 = "1ba0493deaa6ec2b3d1b468ef1cdd633af6e9ab1"
3887+
lazy = true
3888+
libc = "musl"
3889+
os = "linux"
3890+
3891+
[["OCaml-x86_64-apple-darwin.v5.4.0.x86_64-linux-musl.unpacked".download]]
3892+
sha256 = "0d824d99193c18b1ff6380a128605bd0237d6ed5f771ca6948ac0c796d302bd2"
3893+
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-x86_64-apple-darwin.v5.4.0.x86_64-linux-musl.unpacked.tar.gz"
3894+
3895+
[["OCaml-x86_64-linux-gnu.v5.4.0.x86_64-linux-musl.squashfs"]]
3896+
arch = "x86_64"
3897+
git-tree-sha1 = "81ee49ddc2991943d42f5f958117b9a12e6d8542"
3898+
lazy = true
3899+
libc = "musl"
3900+
os = "linux"
3901+
3902+
[["OCaml-x86_64-linux-gnu.v5.4.0.x86_64-linux-musl.squashfs".download]]
3903+
sha256 = "f0e5b04a1beb69bcaab12289e5bc7237e14d8520c8b66edf0b8f90eda828b24e"
3904+
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-x86_64-linux-gnu.v5.4.0.x86_64-linux-musl.squashfs.tar.gz"
3905+
3906+
[["OCaml-x86_64-linux-gnu.v5.4.0.x86_64-linux-musl.unpacked"]]
3907+
arch = "x86_64"
3908+
git-tree-sha1 = "adfa663e0cf79e8fa40afb1dfa3d5f2b13c144ed"
3909+
lazy = true
3910+
libc = "musl"
3911+
os = "linux"
3912+
3913+
[["OCaml-x86_64-linux-gnu.v5.4.0.x86_64-linux-musl.unpacked".download]]
3914+
sha256 = "57f6bbe7af42ef089809fc50b5881f4c8c6c5216813c455b8319b753b60d1b40"
3915+
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-x86_64-linux-gnu.v5.4.0.x86_64-linux-musl.unpacked.tar.gz"
3916+
3917+
[["OCaml-x86_64-linux-musl.v5.4.0.x86_64-linux-musl.squashfs"]]
3918+
arch = "x86_64"
3919+
git-tree-sha1 = "e09f0e9d114794327a1d16f18fca33fbf9dac98b"
3920+
lazy = true
3921+
libc = "musl"
3922+
os = "linux"
3923+
3924+
[["OCaml-x86_64-linux-musl.v5.4.0.x86_64-linux-musl.squashfs".download]]
3925+
sha256 = "296cebca96f8e045292730426c5c3baab3a8785ad9a9c5d4c7638e63f556c71a"
3926+
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-x86_64-linux-musl.v5.4.0.x86_64-linux-musl.squashfs.tar.gz"
3927+
3928+
[["OCaml-x86_64-linux-musl.v5.4.0.x86_64-linux-musl.unpacked"]]
3929+
arch = "x86_64"
3930+
git-tree-sha1 = "3b6ebd3c7d07a6eb2980d559c17f94ff921fa510"
3931+
lazy = true
3932+
libc = "musl"
3933+
os = "linux"
3934+
3935+
[["OCaml-x86_64-linux-musl.v5.4.0.x86_64-linux-musl.unpacked".download]]
3936+
sha256 = "ebf316f8c81be0c74439be1ec45d0ebc4c42b8303487d6bb3136f6e64ecc2ee9"
3937+
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-x86_64-linux-musl.v5.4.0.x86_64-linux-musl.unpacked.tar.gz"
3938+
3939+
[["OCaml-x86_64-w64-mingw32.v5.4.0.x86_64-linux-musl.squashfs"]]
3940+
arch = "x86_64"
3941+
git-tree-sha1 = "85b2f93bedd5a49457a508522c9184221a85494b"
3942+
lazy = true
3943+
libc = "musl"
3944+
os = "linux"
3945+
3946+
[["OCaml-x86_64-w64-mingw32.v5.4.0.x86_64-linux-musl.squashfs".download]]
3947+
sha256 = "b7b4c0a802cd17a2f315186ac102318273fe044ae1c4a829ff01d7fa054d57fa"
3948+
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-x86_64-w64-mingw32.v5.4.0.x86_64-linux-musl.squashfs.tar.gz"
3949+
3950+
[["OCaml-x86_64-w64-mingw32.v5.4.0.x86_64-linux-musl.unpacked"]]
3951+
arch = "x86_64"
3952+
git-tree-sha1 = "d49567a0c987074f9d3509c63ca73cce5b3512a0"
3953+
lazy = true
3954+
libc = "musl"
3955+
os = "linux"
3956+
3957+
[["OCaml-x86_64-w64-mingw32.v5.4.0.x86_64-linux-musl.unpacked".download]]
3958+
sha256 = "c35291496ff5f9d17abbc7182d0a835857a9ee5012b2d1c08421469e7a0bb9ef"
3959+
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-x86_64-w64-mingw32.v5.4.0.x86_64-linux-musl.unpacked.tar.gz"
3960+
38073961
[["PlatformSupport-aarch64-apple-darwin20.v2021.8.10.x86_64-linux-musl.squashfs"]]
38083962
arch = "x86_64"
38093963
git-tree-sha1 = "e99cd089f71d5d9605621ba7dd6d32994bba3de8"

src/Rootfs.jl

+20
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

+29
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/$(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(platform)
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(

test/rootfs.jl

+10
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ end
138138
@test_throws ErrorException choose_shards(platform; preferred_go_version = v"1.14", (common_opts)...)
139139
end
140140

141+
@testset "OCaml toolchain selection" begin
142+
platform = Platform("x86_64", "linux")
143+
common_opts = (preferred_gcc_version=v"9", compilers=[:c, :ocaml])
144+
145+
shards = choose_shards(platform; preferred_ocaml_version = v"5.4", (common_opts)... )
146+
@test filter(s-> s.name == "OCaml", shards)[end].version == v"5.4"
147+
148+
@test_throws ErrorException choose_shards(platform; preferred_ocaml_version = v"4.1", (common_opts)...)
149+
end
150+
141151
@testset "GCC ABI matching" begin
142152
# Preferred libgfortran version and C++ string ABI
143153
platform = Platform("x86_64", "freebsd")

test/runners.jl

+21
Original file line numberDiff line numberDiff line change
@@ -579,4 +579,25 @@ end
579579
@test run(ur, `/bin/bash -c "$(test_script)"`, iobuff)
580580
end
581581
end
582+
@testset "basic program" begin
583+
mktempdir() do dir
584+
compilers = [:c, :ocaml]
585+
ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="glibc"), preferred_gcc_version=v"5", compilers)
586+
# Make sure the runner platform is concrete even if the requested platform isn't
587+
@test !isnothing(libgfortran_version(ur.platform))
588+
@test !isnothing(cxxstring_abi(ur.platform))
589+
iobuff = IOBuffer()
590+
test_script = raw"""
591+
set -e
592+
mkdir -p ${prefix}/bin
593+
echo 'let () = print_endline "hello world"' > hello.ml
594+
ocamlopt -o ${prefix}/bin/hello_world${exeext} hello.ml
595+
install_license /usr/share/licenses/MIT
596+
597+
# Make sure it runs
598+
${prefix}/bin/hello_world${exeext}
599+
"""
600+
@test run(ur, `/bin/bash -c "$(test_script)"`, iobuff)
601+
end
602+
end
582603
end

0 commit comments

Comments
 (0)