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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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.
8 changes: 7 additions & 1 deletion 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.

## C builds

If your library has no build system like Make, CMake, Meson, or Autoconf, you may need to use the C compiler directly. The C compiler is stored in the `CC` environment variable, and you can direct output to `libdir` (shared libraries) and `bindir` (executables).
Expand All @@ -135,7 +141,7 @@ As a high-level example:
```sh
# this assumes you are operating out of a Git source named `hello`
# adjust your `cd` appropriately
cd $WORKSPACE/srcdir/hello
cd $WORKSPACE/srcdir/hello
mkdir -p ${libdir} # make sure the libdir is instantiated
${CC} -shared -o ${libdir}/libhello.${dlext} -fPIC hello.c # compile the library, save to `libdir`
```
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 @@ -488,6 +488,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 @@ -824,7 +831,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
10 changes: 10 additions & 0 deletions test/building.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ shards_to_test = expand_cxxstring_abis(expand_gfortran_versions(shards_to_test))
push!(compilers, :rust)
end

# OCaml is not available on 32-bit platforms, and our shards aren't for FreeBSD
if !(platforms_match(shard, Platform("i686", "windows")) ||
platforms_match(shard, Platform("i686", "linux")) ||
platforms_match(shard, Platform("armv6l", "linux")) ||
platforms_match(shard, Platform("armv7l", "linux")) ||
platforms_match(shard, Platform("aarch64", "freebsd")))
push!(products, ExecutableProduct("hello_world_ocaml", :hello_world_ocaml))
push!(compilers, :ocaml)
end

build_output_meta = autobuild(
build_path,
"testsuite",
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