Skip to content

Add OCaml compiler support #1382

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 1 commit 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ Building binary packages is a pain. `BinaryBuilder` follows a philosophy that i

All packages are cross compiled. If a package does not support cross compilation, we patch the package or, in extreme cases, rebundle prebuilt executables.

The cross-compilation environment that we use is a homegrown Linux environment with many different compilers built for it, including various versions of `gcc`, `clang`, `gfortran`, `rustc` and `go`. You can read more about this in [the `RootFS.md` file](https://github.com/JuliaPackaging/Yggdrasil/blob/master/RootFS.md) within the Yggdrasil repository.
The cross-compilation environment that we use is a homegrown Linux environment with many different compilers built for it, including various versions of `gcc`, `clang`, `gfortran`, `rustc`, `go`, and `ocaml`. You can read more about this in [the `RootFS.md` file](https://github.com/JuliaPackaging/Yggdrasil/blob/master/RootFS.md) within the Yggdrasil repository.
6 changes: 6 additions & 0 deletions docs/src/build_tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ Example of packages using Rust:

The Rust toolchain currently used does not work with the `i686-w64-mingw32` (32-bit Windows) platform.

## OCaml builds

The OCaml toolchain provided by BinaryBuilder can be requested by adding `:ocaml` to the `compilers` keyword argument to [`build_tarballs`](@ref): `compilers=[:c, :ocaml]`, and a specific version of the toolchain can be selected by adding the `preferred_ocaml_version` keyword argument to [`build_tarballs`](@ref).

The OCaml toolchain provided by BinaryBuilder automatically selects the appropriate target.

## Editing files in the wizard

In the wizard, the `vim` editor is available for editing files. But, it doesn't leave any record in the build script. One generally needs to provide patch files or use something like `sed`. If a file needs patching, we suggest using `git` to add the entire worktree to a new repo, make the changes you need, then use `git diff -p` to output a patch that can be included alongside your build recipe.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BinaryBuilder.jl

The purpose of the [`BinaryBuilder.jl`](https://github.com/JuliaPackaging/BinaryBuilder.jl) Julia package is to provide a system for compiling 3rd-party binary dependencies that should work anywhere the [official Julia distribution](https://julialang.org/downloads) does. In particular, using this package you will be able to compile your large pre-existing codebases of C, C++, Fortran, Rust, Go, etc... software into binaries that can be downloaded and loaded/run on a very wide range of machines. As it is difficult (and often expensive) to natively compile software packages across the growing number of platforms that this package will need to support, we focus on providing a set of Linux-hosted cross-compilers. This package will therefore set up an environment to perform cross-compilation for all of the major platforms, and will do its best to make the compilation process as painless as possible.
The purpose of the [`BinaryBuilder.jl`](https://github.com/JuliaPackaging/BinaryBuilder.jl) Julia package is to provide a system for compiling 3rd-party binary dependencies that should work anywhere the [official Julia distribution](https://julialang.org/downloads) does. In particular, using this package you will be able to compile your large pre-existing codebases of C, C++, Fortran, Rust, Go, OCaml, etc... software into binaries that can be downloaded and loaded/run on a very wide range of machines. As it is difficult (and often expensive) to natively compile software packages across the growing number of platforms that this package will need to support, we focus on providing a set of Linux-hosted cross-compilers. This package will therefore set up an environment to perform cross-compilation for all of the major platforms, and will do its best to make the compilation process as painless as possible.

Note that at this time, BinaryBuilder itself runs on Linux `x86_64` and macOS `x86_64` systems only, with Windows support under active development. On macOS and Windows, you must have `docker` installed as the backing virtualization engine. Note that Docker Desktop is the recommended version; if you have Docker Machine installed it may not work correctly or may need additional configuration.

Expand Down
3 changes: 2 additions & 1 deletion generate_precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using SnoopCompile
ExecutableProduct("hello_world_fortran", :hello_world_fortran),
ExecutableProduct("hello_world_go", :hello_world_go),
ExecutableProduct("hello_world_rust", :hello_world_rust),
ExecutableProduct("hello_world_ocaml", :hello_world_ocaml),
]

# First, do the build, but only output the meta json, since we definitely want that to be fast
Expand Down Expand Up @@ -55,7 +56,7 @@ using SnoopCompile
Dependency[
Dependency("Zlib_jll"),
];
compilers=[:c, :rust, :go],
compilers=[:c, :rust, :go, :ocaml],
)

rm("build"; recursive=true, force=true)
Expand Down
17 changes: 16 additions & 1 deletion src/AutoBuild.jl
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,13 @@ function get_compilers_versions(; compilers = [:c])
go version
"""
end
if :ocaml in compilers
output *=
"""
ocamlc -v
ocamlopt -v
"""
end
if :rust in compilers
output *=
"""
Expand Down Expand Up @@ -819,7 +826,15 @@ function autobuild(dir::AbstractString,
build_path = joinpath(dir, "build", triplet(platform))
mkpath(build_path)

shards = choose_shards(platform; extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version,:preferred_rust_version,:preferred_go_version,:bootstrap_list,:compilers))...)
shards = choose_shards(platform; extract_kwargs(kwargs, (
:preferred_gcc_version,
:preferred_llvm_version,
:preferred_rust_version,
:preferred_go_version,
:preferred_ocaml_version,
:bootstrap_list,
:compilers,
))...)
concrete_platform = get_concrete_platform(platform, shards)

prefix = setup_workspace(
Expand Down
6 changes: 3 additions & 3 deletions src/wizard/obtain_source.jl
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,11 @@ function get_name_and_version(state::WizardState)
end
end

@enum Compilers C=1 Go Rust
@enum Compilers C=1 Go Rust OCaml
function get_compilers(state::WizardState)
while state.compilers === nothing
compiler_descriptions = Dict(C => "C/C++/Fortran", Go => "Go", Rust => "Rust")
compiler_symbols = Dict(Int(C) => :c, Int(Go) => :go, Int(Rust) => :rust)
compiler_descriptions = Dict(C => "C/C++/Fortran", Go => "Go", Rust => "Rust", OCaml => "OCaml")
compiler_symbols = Dict(Int(C) => :c, Int(Go) => :go, Int(Rust) => :rust, Int(OCaml) => :ocaml)
terminal = TTYTerminal("xterm", state.ins, state.outs, state.outs)
result = nothing
while true
Expand Down
2 changes: 2 additions & 0 deletions test/building.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,15 @@ shards_to_test = expand_cxxstring_abis(expand_gfortran_versions(shards_to_test))
platforms_match(shard, Platform("riscv64", "linux")))
# Rust is broken on 32-bit Windows and unavailable on FreeBSD AArch64 and Linux RISC-V, let's skip it
push!(products, ExecutableProduct("hello_world_rust", :hello_world_rust))
push!(products, ExecutableProduct("hello_world_ocaml", :hello_world_ocaml))
end

compilers = [:c, :go]
# Don't even ask for Rust on FreeBSD AArch64 and Linux RISC-V
if !(platforms_match(shard, Platform("aarch64", "freebsd")) ||
platforms_match(shard, Platform("riscv64", "linux")))
push!(compilers, :rust)
push!(compilers, :ocaml)
end

build_output_meta = autobuild(
Expand Down
2 changes: 1 addition & 1 deletion test/wizard.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ end
# Check that the state is modified appropriately
@test state.source_urls == ["http://127.0.0.1:$(port)/a/source.tar.gz"]
@test getfield.(state.source_files, :hash) == [libfoo_tarball_hash]
@test Set(state.compilers) == Set([:c, :rust, :go])
@test Set(state.compilers) == Set([:c, :rust, :go, :ocaml])
@test state.preferred_gcc_version == getversion(available_gcc_builds[1])
# The default LLVM shard is the latest one, and above we pressed three times
# arrow down in the reverse order list.
Expand Down
Loading