Skip to content

Implement preliminary OCaml support #425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions Artifacts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3804,6 +3804,160 @@ os = "linux"
sha256 = "80c9869b8421b7efdba72f13ec2c24c7ef77b533ad75d8c72739a312adcaef75"
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/LLVMBootstrap-v9.0.1+0/LLVMBootstrap.v9.0.1.x86_64-linux-musl.unpacked.tar.gz"

[["OCaml-aarch64-apple-darwin20.v5.4.0.x86_64-linux-musl.squashfs"]]
arch = "x86_64"
git-tree-sha1 = "c89112114146d405a3fa393913a6a81aaebd1c89"
lazy = true
libc = "musl"
os = "linux"

[["OCaml-aarch64-apple-darwin20.v5.4.0.x86_64-linux-musl.squashfs".download]]
sha256 = "ed44e69ff293ce2c222ca2cbdb4dd81ce7526a69c7c5ec9ab9e07211b56ea357"
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-aarch64-apple-darwin20.v5.4.0.x86_64-linux-musl.squashfs.tar.gz"

[["OCaml-aarch64-apple-darwin20.v5.4.0.x86_64-linux-musl.unpacked"]]
arch = "x86_64"
git-tree-sha1 = "9f0d650ccbd8200284ec7bb8100cc4c6ce44ca2c"
lazy = true
libc = "musl"
os = "linux"

[["OCaml-aarch64-apple-darwin20.v5.4.0.x86_64-linux-musl.unpacked".download]]
sha256 = "8d1c3c9fdb01159c22380ff8b0178813b9b26adf78873ac970e56580fbe11037"
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-aarch64-apple-darwin20.v5.4.0.x86_64-linux-musl.unpacked.tar.gz"

[["OCaml-aarch64-linux-gnu.v5.4.0.x86_64-linux-musl.squashfs"]]
arch = "x86_64"
git-tree-sha1 = "43825a0f78b3cd4537bc7450e0b9d0ca9dab2468"
lazy = true
libc = "musl"
os = "linux"

[["OCaml-aarch64-linux-gnu.v5.4.0.x86_64-linux-musl.squashfs".download]]
sha256 = "cac028a1fec129df5ca919a1c978f5333a3673025c523ffb34e3b3a67c4208c6"
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"

[["OCaml-aarch64-linux-gnu.v5.4.0.x86_64-linux-musl.unpacked"]]
arch = "x86_64"
git-tree-sha1 = "8e050f2038df590797f3f69f158534324f7ce2c9"
lazy = true
libc = "musl"
os = "linux"

[["OCaml-aarch64-linux-gnu.v5.4.0.x86_64-linux-musl.unpacked".download]]
sha256 = "2b15cde9b66c82e4da4ec336566fb162f6bfae9d0c5187e1d23e8335de549c30"
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"

[["OCaml-aarch64-linux-musl.v5.4.0.x86_64-linux-musl.squashfs"]]
arch = "x86_64"
git-tree-sha1 = "c27e000b6061db267d69bb554142a6036b1a1883"
lazy = true
libc = "musl"
os = "linux"

[["OCaml-aarch64-linux-musl.v5.4.0.x86_64-linux-musl.squashfs".download]]
sha256 = "7352645dc52064131f9fc20d3c8db8708400bf1b9737701339cc4b3f7febf02b"
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"

[["OCaml-aarch64-linux-musl.v5.4.0.x86_64-linux-musl.unpacked"]]
arch = "x86_64"
git-tree-sha1 = "10b7c45f5cdc390b07ac18f6de7b773bc6303070"
lazy = true
libc = "musl"
os = "linux"

[["OCaml-aarch64-linux-musl.v5.4.0.x86_64-linux-musl.unpacked".download]]
sha256 = "b3327ffe3525604f2793ab07b823ca70fcd73e0b97af733d98ccda0e0fc8f680"
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"

[["OCaml-x86_64-apple-darwin14.v5.4.0.x86_64-linux-musl.squashfs"]]
arch = "x86_64"
git-tree-sha1 = "cb559d35f820a3323742c58912c02c8bb2d87cc1"
lazy = true
libc = "musl"
os = "linux"

[["OCaml-x86_64-apple-darwin14.v5.4.0.x86_64-linux-musl.squashfs".download]]
sha256 = "4867ca2f6e21d7cf5589b2f1c8bf73e6055e9c417a0b92bf0d842ba8834e337a"
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-x86_64-apple-darwin14.v5.4.0.x86_64-linux-musl.squashfs.tar.gz"

[["OCaml-x86_64-apple-darwin14.v5.4.0.x86_64-linux-musl.unpacked"]]
arch = "x86_64"
git-tree-sha1 = "1ba0493deaa6ec2b3d1b468ef1cdd633af6e9ab1"
lazy = true
libc = "musl"
os = "linux"

[["OCaml-x86_64-apple-darwin14.v5.4.0.x86_64-linux-musl.unpacked".download]]
sha256 = "0d824d99193c18b1ff6380a128605bd0237d6ed5f771ca6948ac0c796d302bd2"
url = "https://github.com/JuliaPackaging/Yggdrasil/releases/download/OCaml-v5.4.0/OCaml-x86_64-apple-darwin14.v5.4.0.x86_64-linux-musl.unpacked.tar.gz"

[["OCaml-x86_64-linux-gnu.v5.4.0.x86_64-linux-musl.squashfs"]]
arch = "x86_64"
git-tree-sha1 = "81ee49ddc2991943d42f5f958117b9a12e6d8542"
lazy = true
libc = "musl"
os = "linux"

[["OCaml-x86_64-linux-gnu.v5.4.0.x86_64-linux-musl.squashfs".download]]
sha256 = "f0e5b04a1beb69bcaab12289e5bc7237e14d8520c8b66edf0b8f90eda828b24e"
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"

[["OCaml-x86_64-linux-gnu.v5.4.0.x86_64-linux-musl.unpacked"]]
arch = "x86_64"
git-tree-sha1 = "adfa663e0cf79e8fa40afb1dfa3d5f2b13c144ed"
lazy = true
libc = "musl"
os = "linux"

[["OCaml-x86_64-linux-gnu.v5.4.0.x86_64-linux-musl.unpacked".download]]
sha256 = "57f6bbe7af42ef089809fc50b5881f4c8c6c5216813c455b8319b753b60d1b40"
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"

[["OCaml-x86_64-linux-musl.v5.4.0.x86_64-linux-musl.squashfs"]]
arch = "x86_64"
git-tree-sha1 = "e09f0e9d114794327a1d16f18fca33fbf9dac98b"
lazy = true
libc = "musl"
os = "linux"

[["OCaml-x86_64-linux-musl.v5.4.0.x86_64-linux-musl.squashfs".download]]
sha256 = "296cebca96f8e045292730426c5c3baab3a8785ad9a9c5d4c7638e63f556c71a"
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"

[["OCaml-x86_64-linux-musl.v5.4.0.x86_64-linux-musl.unpacked"]]
arch = "x86_64"
git-tree-sha1 = "3b6ebd3c7d07a6eb2980d559c17f94ff921fa510"
lazy = true
libc = "musl"
os = "linux"

[["OCaml-x86_64-linux-musl.v5.4.0.x86_64-linux-musl.unpacked".download]]
sha256 = "ebf316f8c81be0c74439be1ec45d0ebc4c42b8303487d6bb3136f6e64ecc2ee9"
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"

[["OCaml-x86_64-w64-mingw32.v5.4.0.x86_64-linux-musl.squashfs"]]
arch = "x86_64"
git-tree-sha1 = "85b2f93bedd5a49457a508522c9184221a85494b"
lazy = true
libc = "musl"
os = "linux"

[["OCaml-x86_64-w64-mingw32.v5.4.0.x86_64-linux-musl.squashfs".download]]
sha256 = "b7b4c0a802cd17a2f315186ac102318273fe044ae1c4a829ff01d7fa054d57fa"
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"

[["OCaml-x86_64-w64-mingw32.v5.4.0.x86_64-linux-musl.unpacked"]]
arch = "x86_64"
git-tree-sha1 = "d49567a0c987074f9d3509c63ca73cce5b3512a0"
lazy = true
libc = "musl"
os = "linux"

[["OCaml-x86_64-w64-mingw32.v5.4.0.x86_64-linux-musl.unpacked".download]]
sha256 = "c35291496ff5f9d17abbc7182d0a835857a9ee5012b2d1c08421469e7a0bb9ef"
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"

[["PlatformSupport-aarch64-apple-darwin20.v2021.8.10.x86_64-linux-musl.squashfs"]]
arch = "x86_64"
git-tree-sha1 = "e99cd089f71d5d9605621ba7dd6d32994bba3de8"
Expand Down
21 changes: 21 additions & 0 deletions src/Rootfs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ struct RustBuild <: CompilerBuild
version::VersionNumber
end

struct OCamlBuild <: CompilerBuild
version::VersionNumber
end

getversion(c::CompilerBuild) = c.version
getabi(c::CompilerBuild) = c.abi

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

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

const available_ocaml_builds = OCamlBuild.(get_available_builds("OCaml-"))

"""
gcc_version(p::AbstractPlatform, GCC_builds::Vector{GCCBuild},
compilers::Vector{Symbol}=[:c];
Expand Down Expand Up @@ -581,6 +587,7 @@ function choose_shards(p::AbstractPlatform;
LLVM_builds::Vector{LLVMBuild}=available_llvm_builds,
Rust_builds::Vector{RustBuild}=available_rust_builds,
Go_builds::Vector{GoBuild}=available_go_builds,
OCaml_builds::Vector{OCamlBuild}=available_ocaml_builds,
archive_type::Symbol = (use_squashfs[] ? :squashfs : :unpacked),
bootstrap_list::Vector{Symbol} = bootstrap_list,
# Because GCC has lots of compatibility issues, we always default to
Expand All @@ -594,6 +601,8 @@ function choose_shards(p::AbstractPlatform;
preferred_rust_version::VersionNumber = maximum(getversion.(Rust_builds)),
# Always default to the latest Go version
preferred_go_version::VersionNumber = maximum(getversion.(Go_builds)),
# Always default to the latest OCaml version
preferred_ocaml_version::VersionNumber = maximum(getversion.(OCaml_builds)),
)

function find_shard(name, version, archive_type; target = nothing)
Expand Down Expand Up @@ -708,6 +717,18 @@ function choose_shards(p::AbstractPlatform;

push!(shards, find_shard("Go", Go_build, archive_type))
end

if :ocaml in compilers
# Make sure the selected OCaml toolchain version is available
if preferred_ocaml_version in getversion.(OCaml_builds)
OCaml_build = preferred_ocaml_version
else
error("Requested OCaml toolchain $(preferred_ocaml_version) not available in $(OCaml_builds)")
end

push!(shards, find_shard("OCaml", OCaml_build, archive_type;
target = isa(p, AnyPlatform) ? default_host_platform : p))
end
else
function find_latest_version(name)
versions = [cs.version for cs in all_compiler_shards()
Expand Down
29 changes: 29 additions & 0 deletions src/Runner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,14 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
end
gofmt(io::IO, p::AbstractPlatform) = wrapper(io, "/opt/$(host_target)/go/bin/gofmt"; allow_ccache=false)

# OCaml stuff
function ocaml_wrapper(io::IO, tool::String, p::AbstractPlatform)
return wrapper(io, "/opt/$(aatriplet(p))/bin/$(tool)")
end
ocamlc(io::IO, p::AbstractPlatform) = ocaml_wrapper(io, "ocamlc.opt", p)
ocamlopt(io::IO, p::AbstractPlatform) = ocaml_wrapper(io, "ocamlopt.opt", p)
flexlink(io::IO, p::AbstractPlatform) = ocaml_wrapper(io, "flexlink", p)

# Rust stuff
function rust_flags!(p::AbstractPlatform, flags::Vector{String} = String[])
if Sys.islinux(p)
Expand Down Expand Up @@ -958,6 +966,16 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
end
end

# Generate OCaml stuff
if :ocaml in compilers
write_wrapper(ocamlc, p, "$(t)-ocamlc.opt")
write_wrapper(ocamlopt, p, "$(t)-ocamlopt.opt")

if Sys.iswindows(p)
write_wrapper(flexlink, p, "$(t)-flexlink")
end
end

# Generate go stuff
if :go in compilers
write_wrapper(go, p, "$(t)-go")
Expand Down Expand Up @@ -1004,6 +1022,12 @@ function generate_compiler_wrappers!(platform::AbstractPlatform; bin_path::Abstr
if :rust in compilers
append!(default_tools, ("rustc","rustup","cargo"))
end
if :ocaml in compilers
append!(default_tools, ("ocamlc.opt", "ocamlopt.opt"))
if Sys.iswindows(platform)
push!(default_tools, "flexlink")
end
end
if :go in compilers
append!(default_tools, ("go", "gofmt"))
end
Expand Down Expand Up @@ -1261,6 +1285,11 @@ function platform_envs(platform::AbstractPlatform, src_name::AbstractString;
))
end

# OCaml stuff
if :ocaml in compilers
# no environment variables required (yet)
end

# Rust stuff
if :rust in compilers
merge!(mapping, Dict(
Expand Down
10 changes: 10 additions & 0 deletions test/rootfs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ end
@test_throws ErrorException choose_shards(platform; preferred_go_version = v"1.14", (common_opts)...)
end

@testset "OCaml toolchain selection" begin
platform = Platform("x86_64", "linux")
common_opts = (preferred_gcc_version=v"9", compilers=[:c, :ocaml])

shards = choose_shards(platform; preferred_ocaml_version = v"5.4", (common_opts)... )
@test filter(s-> s.name == "OCaml", shards)[end].version == v"5.4"

@test_throws ErrorException choose_shards(platform; preferred_ocaml_version = v"4.1", (common_opts)...)
end

@testset "GCC ABI matching" begin
# Preferred libgfortran version and C++ string ABI
platform = Platform("x86_64", "freebsd")
Expand Down
21 changes: 21 additions & 0 deletions test/runners.jl
Original file line number Diff line number Diff line change
Expand Up @@ -579,4 +579,25 @@ end
@test run(ur, `/bin/bash -c "$(test_script)"`, iobuff)
end
end
@testset "basic program" begin
mktempdir() do dir
compilers = [:c, :ocaml]
ur = preferred_runner()(dir; platform=Platform("x86_64", "linux"; libc="glibc"), preferred_gcc_version=v"5", compilers)
# Make sure the runner platform is concrete even if the requested platform isn't
@test !isnothing(libgfortran_version(ur.platform))
@test !isnothing(cxxstring_abi(ur.platform))
iobuff = IOBuffer()
test_script = raw"""
set -e
mkdir -p ${prefix}/bin
echo 'let () = print_endline "hello world"' > hello.ml
ocamlopt -o ${prefix}/bin/hello_world${exeext} hello.ml
install_license /usr/share/licenses/MIT

# Make sure it runs
${prefix}/bin/hello_world${exeext}
"""
@test run(ur, `/bin/bash -c "$(test_script)"`, iobuff)
end
end
end