Skip to content

Commit cd01325

Browse files
committed
Add OCaml compiler support
1 parent aa0df0e commit cd01325

File tree

8 files changed

+31
-8
lines changed

8 files changed

+31
-8
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ Building binary packages is a pain. `BinaryBuilder` follows a philosophy that i
3232

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

35-
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.
35+
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.

docs/src/build_tips.md

+6
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ Example of packages using Rust:
127127

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

130+
## OCaml builds
131+
132+
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).
133+
134+
The OCaml toolchain provided by BinaryBuilder automatically selects the appropriate target.
135+
130136
## Editing files in the wizard
131137

132138
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.

docs/src/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# BinaryBuilder.jl
22

3-
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.
3+
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.
44

55
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.
66

generate_precompile.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ using SnoopCompile
99
ExecutableProduct("hello_world_fortran", :hello_world_fortran),
1010
ExecutableProduct("hello_world_go", :hello_world_go),
1111
ExecutableProduct("hello_world_rust", :hello_world_rust),
12+
ExecutableProduct("hello_world_ocaml", :hello_world_ocaml),
1213
]
1314

1415
# First, do the build, but only output the meta json, since we definitely want that to be fast
@@ -55,7 +56,7 @@ using SnoopCompile
5556
Dependency[
5657
Dependency("Zlib_jll"),
5758
];
58-
compilers=[:c, :rust, :go],
59+
compilers=[:c, :rust, :go, :ocaml],
5960
)
6061

6162
rm("build"; recursive=true, force=true)

src/AutoBuild.jl

+15-1
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,12 @@ function get_compilers_versions(; compilers = [:c])
477477
go version
478478
"""
479479
end
480+
if :ocaml in compilers
481+
output *=
482+
"""
483+
ocamlc -v
484+
ocamlopt -v
485+
"""
480486
if :rust in compilers
481487
output *=
482488
"""
@@ -819,7 +825,15 @@ function autobuild(dir::AbstractString,
819825
build_path = joinpath(dir, "build", triplet(platform))
820826
mkpath(build_path)
821827

822-
shards = choose_shards(platform; extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version,:preferred_rust_version,:preferred_go_version,:bootstrap_list,:compilers))...)
828+
shards = choose_shards(platform; extract_kwargs(kwargs, (
829+
:preferred_gcc_version,
830+
:preferred_llvm_version,
831+
:preferred_rust_version,
832+
:preferred_go_version,
833+
:preferred_ocaml_version,
834+
:bootstrap_list,
835+
:compilers,
836+
))...)
823837
concrete_platform = get_concrete_platform(platform, shards)
824838

825839
prefix = setup_workspace(

src/wizard/obtain_source.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,11 @@ function get_name_and_version(state::WizardState)
334334
end
335335
end
336336

337-
@enum Compilers C=1 Go Rust
337+
@enum Compilers C=1 Go Rust OCaml
338338
function get_compilers(state::WizardState)
339339
while state.compilers === nothing
340-
compiler_descriptions = Dict(C => "C/C++/Fortran", Go => "Go", Rust => "Rust")
341-
compiler_symbols = Dict(Int(C) => :c, Int(Go) => :go, Int(Rust) => :rust)
340+
compiler_descriptions = Dict(C => "C/C++/Fortran", Go => "Go", Rust => "Rust", OCaml => "OCaml")
341+
compiler_symbols = Dict(Int(C) => :c, Int(Go) => :go, Int(Rust) => :rust, Int(OCaml) => :ocaml)
342342
terminal = TTYTerminal("xterm", state.ins, state.outs, state.outs)
343343
result = nothing
344344
while true

test/building.jl

+2
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,15 @@ shards_to_test = expand_cxxstring_abis(expand_gfortran_versions(shards_to_test))
118118
platforms_match(shard, Platform("riscv64", "linux")))
119119
# Rust is broken on 32-bit Windows and unavailable on FreeBSD AArch64 and Linux RISC-V, let's skip it
120120
push!(products, ExecutableProduct("hello_world_rust", :hello_world_rust))
121+
push!(products, ExecutableProduct("hello_world_ocaml", :hello_world_ocaml))
121122
end
122123

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

130132
build_output_meta = autobuild(

test/wizard.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ end
180180
# Check that the state is modified appropriately
181181
@test state.source_urls == ["http://127.0.0.1:$(port)/a/source.tar.gz"]
182182
@test getfield.(state.source_files, :hash) == [libfoo_tarball_hash]
183-
@test Set(state.compilers) == Set([:c, :rust, :go])
183+
@test Set(state.compilers) == Set([:c, :rust, :go, :ocaml])
184184
@test state.preferred_gcc_version == getversion(available_gcc_builds[1])
185185
# The default LLVM shard is the latest one, and above we pressed three times
186186
# arrow down in the reverse order list.

0 commit comments

Comments
 (0)