1- # Check if deploy flag is set
2- deploy = " --deploy" in ARGS
1+ name = " OCaml"
2+ version = v " 5.3"
3+
4+ compiler_target = try
5+ parse (Platform, ARGS [end ])
6+ catch
7+ error (" This is not a typical build_tarballs.jl! Must provide exactly one platform as the last argument!" )
8+ end
9+ deleteat! (ARGS , length (ARGS ))
310
411# These are the targets we support right now:
12+ # x86_64-linux-musl
13+ # x86_64-linux-gnu
514# x86_64-w64-mingw32
615# x86_64-apple-darwin14
716# aarch64-apple-darwin20
8- # x86_64-linux-gnu
9- # x86_64-linux-musl
1017# aarch64-linux-gnu
1118# aarch64-linux-musl
1219# riscv64-linux-gnu
1320# riscv64-linux-musl
1421# powerpc64le-linux-gnu
1522#
23+ # Always build x86_64-linux-musl first, since the other targets depend on it.
24+ #
1625# Not supported:
1726# i686: OCaml 5.0 dropped support for 32-bit platforms
1827# freebsd: `POSIX threads are required but not supported on this platform`
1928
20- # The first thing we're going to do is to install Rust for all targets into a single prefix
21- script = raw """
29+ script = " host=$(BinaryBuilder. aatriplet (host_platform)) \n " * raw """
2230cd ${WORKSPACE}/srcdir/ocaml
2331git submodule update --init
2432
@@ -27,13 +35,10 @@ for f in ${WORKSPACE}/srcdir/patches/*.patch; do
2735 atomic_patch -p1 ${f}
2836done
2937
30- # OCaml is not relocatable yet, meaning we have to configure it with actual directory it'll
31- # end up in as the prefix (`/opt/$target`). However, BB expects things in $prefix, so use
32- # some rsync shenanigans to figure out the changes made by the script here.
38+ # OCaml is not relocatable, so configure it with the prefix where the shards will end up.
3339# This should improve in the future: https://github.com/ocaml/RFCs/pull/53
34- # Alternatively, consider using the https://github.com/dra27/ocaml repository
35- # (currently not possibly due to the cross-compilation patches, but should work on 5.4).
36- runtime_prefix=/opt/$target
40+ # Alternatively, consider using the https://github.com/dra27/ocaml repository.
41+ runtime_prefix=$(echo /opt/${target}*)
3742rsync --archive $runtime_prefix/ ${WORKSPACE}/initial_prefix/
3843
3944# unset compiler env vars so that configure can detect them properly
@@ -42,45 +47,51 @@ unset CC CXX LD STRIP AS
4247
4348## host compiler & tools
4449
45- if [[ "${target }" == "${MACHTYPE }" ]]; then
50+ if [[ "${host }" == "${target }" ]]; then
4651 ./configure --prefix=${runtime_prefix}
4752 make -j${nproc}
4853 make install
49- else
50- ./configure --prefix=${runtime_prefix}/host --build=${MACHTYPE} --host=${MACHTYPE}
51- make -j${nproc}
54+
55+ # Dune
56+ cd ${WORKSPACE}/srcdir/dune
57+ ./configure --prefix $runtime_prefix
58+ make release
5259 make install
53- export PATH=${runtime_prefix}/host/bin:$PATH
54- fi
5560
56- # Dune
57- cd ${WORKSPACE}/srcdir/dune
58- ./configure --prefix $runtime_prefix
59- make release
60- make install
61+ # OCamlbuild
62+ # XXX: OCamlbuild takes its configuration values from ocamlc, so picks up host settings...
63+ cd ${WORKSPACE}/srcdir/ocamlbuild
64+ make configure OCAMLBUILD_PREFIX=$runtime_prefix OCAMLBUILD_BINDIR=$runtime_prefix/bin OCAMLBUILD_LIBDIR=$runtime_prefix/lib/ocaml
65+ make -j${nproc}
66+ make install PREFIX=$runtime_prefix BINDIR=$runtime_prefix/bin LIBDIR=$runtime_prefix/lib/ocaml
6167
62- # OCamlbuild
63- # XXX: OCamlbuild takes its configuration values from ocamlc, so picks up host settings...
64- cd ${WORKSPACE}/srcdir/ocamlbuild
65- make configure OCAMLBUILD_PREFIX=$runtime_prefix OCAMLBUILD_BINDIR=$runtime_prefix/bin OCAMLBUILD_LIBDIR=$runtime_prefix/lib/ocaml
66- make -j${nproc}
67- make install PREFIX=$runtime_prefix BINDIR=$runtime_prefix/bin LIBDIR=$runtime_prefix/lib/ocaml
68+ # ocamlfind
69+ cd ${WORKSPACE}/srcdir/ocamlfind
70+ ./configure -bindir $runtime_prefix/bin -mandir $runtime_prefix/man -sitelib $runtime_prefix/lib/ocaml -config $runtime_prefix/etc/findlib.conf -no-topfind
71+ make -j ${nproc}
72+ make install prefix=""
73+ else
74+ # Build a temporary host compiler for bootstrapping the cross-compiler.
75+ # We could re-use the host shard, but that complicates the rootfs selection logic.
76+ ./configure --prefix=${host_prefix} --build=${host} --host=${host}
77+ make -j${nproc}
78+ make install
6879
69- # ocamlfind
70- cd ${WORKSPACE}/srcdir/ocamlfind
71- ./configure -bindir $runtime_prefix/bin -mandir $runtime_prefix/man -sitelib $runtime_prefix/lib/ocaml -config $runtime_prefix/etc/findlib.conf -no-topfind
72- make -j ${nproc}
73- make install prefix=""
80+ # Make sure the host prefix takes precedence over the runtime prefix.
81+ # This matters when, during installation of the cross-compiler,
82+ # its `ocamlrun` would otherwise (fail to) execute instead.
83+ export PATH=${host_prefix}/bin:$PATH
84+ fi
7485
7586
7687## cross compiler
7788
78- if [[ "${target }" != "${MACHTYPE }" ]]; then
89+ if [[ "${host }" != "${target }" ]]; then
7990 cd ${WORKSPACE}/srcdir/ocaml
8091 make distclean
8192
8293 # Build a cross-compiler
83- ./configure --prefix=${runtime_prefix} --build=${MACHTYPE } --host=${MACHTYPE } --target=${target}
94+ ./configure --prefix=${runtime_prefix} --build=${host } --host=${host } --target=${target}
8495 make crossopt -j${nproc}
8596 make installcross
8697
@@ -100,28 +111,16 @@ if [[ "${target}" != "${MACHTYPE}" ]]; then
100111
101112 # if this is a symlink, update both the name of the link and the target
102113 if [[ -L $bin ]]; then
103- target =$(readlink $bin)
114+ path =$(readlink $bin)
104115 rm $bin
105- ln -s $(basename ${target } .exe) ${runtime_prefix}/bin/$(basename ${bin} .exe)
116+ ln -s $(basename ${path } .exe) ${runtime_prefix}/bin/$(basename ${bin} .exe)
106117
107118 # if this is a file, simply rename it
108119 elif [[ -f $bin ]]; then
109120 mv $bin ${runtime_prefix}/bin/$(basename ${bin} .exe)
110121 fi
111122 done
112123 fi
113-
114- # Replace target compiler binaries with host ones
115- # XXX: it isn't great to "pollute" a cross-compiled prefix with host binaries...
116- # can we not ship both, and have `dune -x` pick the appropriate binary?
117- for bin in ocamlrun ocamlrund ocamlruni ocamlyacc; do
118- rm -f $runtime_prefix/bin/$bin${exeext}
119- cp $runtime_prefix/host/bin/$bin $runtime_prefix/bin
120- done
121-
122- # Replace target compiler libraries (which the interpreter uses) with host ones
123- rm -rf $runtime_prefix/lib/ocaml/stublibs/*
124- cp $runtime_prefix/host/lib/ocaml/stublibs/* $runtime_prefix/lib/ocaml/stublibs
125124fi
126125
127126
@@ -144,18 +143,11 @@ products = Product[
144143]
145144dependencies = Dependency[]
146145
147- name = " OCaml"
148- compiler_target = try
149- parse (Platform, ARGS [end ])
150- catch
151- error (" This is not a typical build_tarballs.jl! Must provide exactly one platform as the last argument!" )
152- end
153- deleteat! (ARGS , length (ARGS ))
154-
155- # Build the tarballs
146+ # Build the tarballs. This needs to run in the target's environment, as the OCaml build
147+ # system needs a target compiler to assemble the runtime libraries.
156148ndARGS, deploy_target = find_deploy_arg (ARGS )
157- build_info = build_tarballs (ndARGS, name, version, sources, script, Platform [compiler_target], products, dependencies;
158- skip_audit= true , julia_compat= " 1.6" , preferred_gcc_version= v "5 " )
149+ build_info = build_tarballs (ndARGS, name, version, sources, script, [compiler_target], products, dependencies;
150+ skip_audit= true , julia_compat= " 1.6" , preferred_gcc_version= v "6 " )
159151
160152build_info = Dict (host_platform => first (values (build_info)))
161153
0 commit comments