Skip to content

Commit f0b86a5

Browse files
topolaritymaleadt
authored andcommitted
Add OCaml compiler support
1 parent 515bf75 commit f0b86a5

File tree

8 files changed

+33
-9
lines changed

8 files changed

+33
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 1 deletion
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
## C builds
131137

132138
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).
@@ -135,7 +141,7 @@ As a high-level example:
135141
```sh
136142
# this assumes you are operating out of a Git source named `hello`
137143
# adjust your `cd` appropriately
138-
cd $WORKSPACE/srcdir/hello
144+
cd $WORKSPACE/srcdir/hello
139145
mkdir -p ${libdir} # make sure the libdir is instantiated
140146
${CC} -shared -o ${libdir}/libhello.${dlext} -fPIC hello.c # compile the library, save to `libdir`
141147
```

docs/src/index.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,13 @@ function get_compilers_versions(; compilers = [:c])
488488
go version
489489
"""
490490
end
491+
if :ocaml in compilers
492+
output *=
493+
"""
494+
ocamlc -v
495+
ocamlopt -v
496+
"""
497+
end
491498
if :rust in compilers
492499
output *=
493500
"""
@@ -824,7 +831,15 @@ function autobuild(dir::AbstractString,
824831
build_path = joinpath(dir, "build", triplet(platform))
825832
mkpath(build_path)
826833

827-
shards = choose_shards(platform; extract_kwargs(kwargs, (:preferred_gcc_version,:preferred_llvm_version,:preferred_rust_version,:preferred_go_version,:bootstrap_list,:compilers))...)
834+
shards = choose_shards(platform; extract_kwargs(kwargs, (
835+
:preferred_gcc_version,
836+
:preferred_llvm_version,
837+
:preferred_rust_version,
838+
:preferred_go_version,
839+
:preferred_ocaml_version,
840+
:bootstrap_list,
841+
:compilers,
842+
))...)
828843
concrete_platform = get_concrete_platform(platform, shards)
829844

830845
prefix = setup_workspace(

src/wizard/obtain_source.jl

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,15 @@ shards_to_test = expand_cxxstring_abis(expand_gfortran_versions(shards_to_test))
147147
platforms_match(shard, Platform("riscv64", "linux")))
148148
# Rust is broken on 32-bit Windows and unavailable on FreeBSD AArch64 and Linux RISC-V, let's skip it
149149
push!(products, ExecutableProduct("hello_world_rust", :hello_world_rust))
150+
push!(products, ExecutableProduct("hello_world_ocaml", :hello_world_ocaml))
150151
end
151152

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

159161
build_output_meta = autobuild(

test/wizard.jl

Lines changed: 1 addition & 1 deletion
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)