Skip to content

Commit a954d6f

Browse files
committed
Streamline shard generator.
1 parent d6cb1a1 commit a954d6f

File tree

2 files changed

+57
-65
lines changed

2 files changed

+57
-65
lines changed

0_RootFS/[email protected]/build_tarballs.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ name = "OCamlBase"
1616
version = v"5.3.0"
1717

1818
sources = [
19-
GitSource("https://github.com/ocaml/ocaml.git",
20-
"1ccb919e35f8378834060c503ae953897fe0fb7f"), # 5.3.0
19+
GitSource("https://github.com/ocaml/ocaml",
20+
"1ccb919e35f8378834060c503ae953897fe0fb7f"), # 5.3.0
2121
GitSource("https://github.com/ocaml/dune",
2222
"76c0c3941798f81dcc13a305d7abb120c191f5fa"), # 3.19.1
2323
GitSource("https://github.com/ocaml/ocamlbuild",
2424
"131ba63a1b96d00f3986c8187677c8af61d20a08"), # 0.16.1
25-
GitSource("https://github.com/ocaml/opam",
26-
"e13109411952d4f723a165c2a24b8c03c4945041"), # 2.3.0
25+
GitSource("https://github.com/ocaml/ocamlfind",
26+
"bd9aad183f0d1c2caf3ec29e4f52bc69361f266d"), # 1.9.8
2727
DirectorySource("./bundled"),
2828
]
2929

0_RootFS/ocaml_common.jl

Lines changed: 53 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
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"""
2230
cd ${WORKSPACE}/srcdir/ocaml
2331
git submodule update --init
2432
@@ -27,13 +35,10 @@ for f in ${WORKSPACE}/srcdir/patches/*.patch; do
2735
atomic_patch -p1 ${f}
2836
done
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}*)
3742
rsync --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
125124
fi
126125
127126
@@ -144,18 +143,11 @@ products = Product[
144143
]
145144
dependencies = 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.
156148
ndARGS, 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

160152
build_info = Dict(host_platform => first(values(build_info)))
161153

0 commit comments

Comments
 (0)