-
Notifications
You must be signed in to change notification settings - Fork 598
[OCaml] Add (cross-)compiler shards #11146
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
topolarity
wants to merge
16
commits into
JuliaPackaging:master
Choose a base branch
from
topolarity:ct/ocaml-shards
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+691
−5
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
501bc29
[OCaml] Add (cross-)compiler shards
topolarity 1307e99
[HelloWorldOCaml] Add example OCaml project
topolarity 07f80f0
Document platforms supported.
maleadt c5de47b
Bump to OCaml 5.4 alpha 1.
maleadt dec5745
Clean-ups.
maleadt f0ce12f
Install native OCaml in host_prefix.
maleadt 22932a4
Also build Dune/OCamlbuild/Opam.
maleadt cc90c0b
Add symlinks to Windows executables.
maleadt ccd5f1e
PPC also works.
maleadt 82cd19d
Special-case non-cross build.
maleadt 62e0d39
Not all of PPC is supported.
maleadt 81d7907
Try trusting the configure script's autodetection.
maleadt 5a8dbe8
Rename files instead of adding symlinks.
maleadt ac97138
Build for more platforms.
maleadt d531d0d
Bump dependencies for CI.
maleadt 2627052
Bump for Darwin fix.
maleadt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
### Instructions for adding a new version of the OCaml toolchain | ||
# | ||
# * update the `version` variable and `sources` | ||
# * To deploy the shard and automatically update your BinaryBuilderBase's | ||
# `Artifacts.toml`, use the `--deploy` flag to the `build_tarballs.jl` script. | ||
# You can build & deploy by running: | ||
# | ||
# julia build_tarballs.jl --debug --verbose --deploy TARGET | ||
# | ||
|
||
using BinaryBuilderBase, BinaryBuilder, Pkg.Artifacts | ||
|
||
include("../common.jl") | ||
|
||
name = "OCamlBase" | ||
version = v"5.4.0" | ||
|
||
sources = [ | ||
GitSource("https://github.com/ocaml/ocaml.git", | ||
"ff1ab416a5503c8bde9fa3fae5f2bb21c7ddc81e"), # 5.4.0~alpha1 | ||
GitSource("https://github.com/ocaml/dune", | ||
"76c0c3941798f81dcc13a305d7abb120c191f5fa"), # 3.19.1 | ||
GitSource("https://github.com/ocaml/ocamlbuild", | ||
"131ba63a1b96d00f3986c8187677c8af61d20a08"), # 0.16.1 | ||
GitSource("https://github.com/ocaml/opam", | ||
"e13109411952d4f723a165c2a24b8c03c4945041"), # 2.3.0 | ||
DirectorySource("./bundled"), | ||
] | ||
|
||
# Check if deploy flag is set | ||
deploy = "--deploy" in ARGS | ||
|
||
# These are the targets we support right now: | ||
# x86_64-w64-mingw32 | ||
# x86_64-apple-darwin14 | ||
# aarch64-apple-darwin20 | ||
# x86_64-linux-gnu | ||
# x86_64-linux-musl | ||
# aarch64-linux-gnu | ||
# aarch64-linux-musl | ||
# riscv64-linux-gnu | ||
# riscv64-linux-musl | ||
# powerpc64le-linux-gnu | ||
# | ||
# Not supported: | ||
# i686: OCaml 5.0 dropped support for 32-bit platforms | ||
# freebsd: `POSIX threads are required but not supported on this platform` | ||
|
||
# The first thing we're going to do is to install Rust for all targets into a single prefix | ||
script = raw""" | ||
cd ${WORKSPACE}/srcdir/ocaml | ||
git submodule update --init | ||
|
||
# Apply patches | ||
for f in ${WORKSPACE}/srcdir/patches/*.patch; do | ||
atomic_patch -p1 ${f} | ||
done | ||
|
||
# unset compiler env vars so that configure can detect them properly | ||
unset CC CXX LD STRIP AS | ||
|
||
if [[ "${target}" == "${MACHTYPE}" ]]; then | ||
# Build a native compiler in $prefix | ||
./configure --prefix=${prefix} | ||
make -j${nproc} | ||
make install | ||
else | ||
# Build a native compiler in $host_prefix (which takes PATH preference over $prefix) | ||
./configure --prefix=${host_prefix} --build=${MACHTYPE} --host=${MACHTYPE} | ||
make -j${nproc} | ||
make install | ||
git clean -fxd | ||
|
||
# Build a cross-compiler in $prefix | ||
./configure --prefix=${prefix} --build=${MACHTYPE} --host=${MACHTYPE} --target=${target} | ||
make crossopt -j${nproc} | ||
make installcross | ||
if [[ "${target}" == *-mingw* ]]; then | ||
# the OCaml configure script detects the executable extension by looking at the | ||
# target compiler. for host utilities, we don't want this symlink, so remove it. | ||
for bin in ${bindir}/*.exe; do | ||
# (links to) target binaries should retain their extension | ||
if file -L $bin | grep 'PE32' >/dev/null; then | ||
continue | ||
fi | ||
|
||
# if this is a symlink, update both the name of the link and the target | ||
if [[ -L $bin ]]; then | ||
target=$(readlink $bin) | ||
rm $bin | ||
ln -s $(basename ${target} .exe) ${bindir}/$(basename ${bin} .exe) | ||
|
||
# if this is a file, simply rename it | ||
elif [[ -f $bin ]]; then | ||
mv $bin ${bindir}/$(basename ${bin} .exe) | ||
fi | ||
done | ||
fi | ||
fi | ||
|
||
# Fix shebang of ocamlrun scripts to not hardcode a path of the build environment | ||
for bin in $(file ${bindir}/* | grep "a \S*/ocamlrun script" | cut -d: -f1); do | ||
abspath=$(file ${bin} | grep -oh "a \S*/ocamlrun script" | cut -d' ' -f2) | ||
sed -i "s?${abspath}?/usr/bin/env ocamlrun?" "${bin}" | ||
done | ||
|
||
# Dune | ||
cd ${WORKSPACE}/srcdir/dune | ||
./configure --prefix $prefix | ||
make release | ||
make install | ||
|
||
# OCamlbuild | ||
cd ${WORKSPACE}/srcdir/ocamlbuild | ||
make configure OCAMLBUILD_PREFIX=$prefix OCAMLBUILD_BINDIR=$bindir OCAMLBUILD_LIBDIR=$prefix/lib | ||
# XXX: can't use $libdir because on Windows it aliases with $bindir | ||
# while ocamlbuild wants to put files in $libdir/ocamlbuild | ||
make -j${nproc} | ||
make install | ||
|
||
# Opam | ||
cd ${WORKSPACE}/srcdir/opam | ||
./configure --prefix $prefix --host=${MACHTYPE} --with-vendored-deps | ||
make -j${nproc} | ||
make install | ||
""" | ||
|
||
platforms = Platform[ host_platform ] | ||
products = Product[ | ||
# build with no products since all of our products are for the host, not the target | ||
|
||
# ExecutableProduct("ocamlopt.opt", :ocamlopt), | ||
# ExecutableProduct("ocamlc.opt", :ocamlc), | ||
# ExecutableProduct("ocamlrun", :ocamlrun), | ||
] | ||
dependencies = Dependency[] | ||
|
||
name = "OCaml" | ||
compiler_target = try | ||
parse(Platform, ARGS[end]) | ||
catch | ||
error("This is not a typical build_tarballs.jl! Must provide exactly one platform as the last argument!") | ||
end | ||
Comment on lines
+139
to
+143
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I opted to go the GCC route and use the compiler target as the "target" for the build |
||
deleteat!(ARGS, length(ARGS)) | ||
|
||
# Build the tarballs | ||
ndARGS, deploy_target = find_deploy_arg(ARGS) | ||
build_info = build_tarballs(ndARGS, name, version, sources, script, Platform[compiler_target], products, dependencies; | ||
skip_audit=true, julia_compat="1.6", preferred_gcc_version=v"6") | ||
|
||
build_info = Dict(host_platform => first(values(build_info))) | ||
|
||
# Upload the artifacts (if requested) | ||
if deploy_target !== nothing | ||
upload_and_insert_shards(deploy_target, name, version, build_info; target=compiler_target) | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.