| 1 |
mlton for Debian |
| 2 |
---------------- |
| 3 |
|
| 4 |
1. Repacking upstream tarballs |
| 5 |
============================== |
| 6 |
|
| 7 |
The upstream mlton source tarball contains non-DFSG-free files. It also |
| 8 |
contains nested tarballs and patches for their extracted contents. We |
| 9 |
repack the original tarball to remove the non-DFSG-free files and to |
| 10 |
extract the nested tarballs. (Strictly speaking, we don't bother with |
| 11 |
sources, but just use the upstream VCS tags.) Here are the instructions |
| 12 |
for importing a new upstream release. |
| 13 |
|
| 14 |
First, make sure that upstream MLton's git repository is known to your |
| 15 |
local git clone of the Debian packaging: |
| 16 |
|
| 17 |
git remote add mlton https://github.com/MLton/mlton.git |
| 18 |
|
| 19 |
Next, fetch any known tags: |
| 20 |
|
| 21 |
git fetch mlton |
| 22 |
|
| 23 |
We now merge the desired tag into the upstream branch: |
| 24 |
|
| 25 |
export VERSION=202YMMDD |
| 26 |
git switch upstream |
| 27 |
git merge on-${VERSION}-release |
| 28 |
# Make sure we have any relevant upstream tarballs so that |
| 29 |
# we can reextract them: |
| 30 |
git checkout on-${VERSION}-release -- \ |
| 31 |
lib/mllpt-lib/ml-lpt.tgz lib/mllpt-lib/ml-lpt.patch \ |
| 32 |
lib/mlrisc-lib/MLRISC.tgz lib/mlrisc-lib/MLRISC.patch \ |
| 33 |
lib/smlnj-lib/smlnj-lib.tgz lib/smlnj-lib/smlnj-lib.patch \ |
| 34 |
runtime/gdtoa.tgz 'runtime/gdtoa.*.patch' |
| 35 |
# Delete previously extracted tarballs to make sure that |
| 36 |
# files deleted upstream are deleted in the repacked tarball: |
| 37 |
rm -fr \ |
| 38 |
lib/ckit-lib/ckit-lib \ |
| 39 |
lib/mllpt-lib/ml-lpt \ |
| 40 |
lib/mlrisc-lib/MLRISC \ |
| 41 |
lib/smlnj-lib/smlnj-lib \ |
| 42 |
runtime/gdtoa |
| 43 |
# Extract the nested tarballs and apply upstream's patches |
| 44 |
make -C lib/ckit-lib ckit-lpt/README |
| 45 |
make -C lib/mllpt-lib ml-lpt/README |
| 46 |
make -C lib/mlrisc-lib MLRISC/README.mlton |
| 47 |
make -C lib/smlnj-lib smlnj-lib/README.mlton |
| 48 |
# The Makefile in runtime has a bunch of eval lines that compile files |
| 49 |
# before ever getting around to extracting gdtoa.tgz. We extract just |
| 50 |
# the relevant Makefile target and run it ourselves with variables |
| 51 |
# substituted in: |
| 52 |
cd runtime && \ |
| 53 |
sed -n '/^gdtoa\/README/,${p;/^$/q}' Makefile | \ |
| 54 |
sed -e 's@$(PATCH)@patch@g;s@$(GZIP)@gzip@g;s@$(TAR)@tar@g' | \ |
| 55 |
make --file="-" && cd - |
| 56 |
# Delete the nested tarballs and patches |
| 57 |
rm lib/mllpt-lib/ml-lpt.tgz lib/mllpt-lib/ml-lpt.patch |
| 58 |
rm lib/mlrisc-lib/MLRISC.tgz lib/mlrisc-lib/MLRISC.patch |
| 59 |
rm lib/smlnj-lib/smlnj-lib.tgz lib/smlnj-lib/smlnj-lib.patch |
| 60 |
rm runtime/gdtoa.tgz runtime/gdtoa.*.patch |
| 61 |
# Delete non-DFSG-free files from unpacked tarballs |
| 62 |
rm -fr lib/smlnj-lib/smlnj-lib/HTML4/tests/ |
| 63 |
# We need to pass -f to git add because upstream ignores |
| 64 |
# extracted contents via .gitignore |
| 65 |
git add -f lib runtime |
| 66 |
git commit -m "Repacked new upstream release ${VERSION}" |
| 67 |
git tag -s "upstream/${VERSION}+dfsg" |
| 68 |
|
| 69 |
Now we can merge in back into the desired packaging branch, e.g.: |
| 70 |
|
| 71 |
git switch debian/unstable |
| 72 |
git merge upstream/${VERSION}+dfsg |
| 73 |
|
| 74 |
2. Rebootstrapping |
| 75 |
================== |
| 76 |
|
| 77 |
MLton, as with most SML compilers, requires a SML compiler to compile |
| 78 |
itself. If ever mlton becomes uninstallable, you will need to compile |
| 79 |
it with the last installable version. Unfortunately, |
| 80 |
|
| 81 |
Building the runtime system requires compiling and executing |
| 82 |
programs that determine characteristics of the platform, which is |
| 83 |
why it isn’t currently feasible to build the runtime system on the |
| 84 |
host machine using a cross-compiler toolchain. |
| 85 |
|
| 86 |
per doc/guide/src/CrossCompiling.adoc. This means that you cannot use |
| 87 |
sbuild to locally cross-compile for a different architecture, and that |
| 88 |
you will have to manually build the package on that architecture. |
| 89 |
Assuming you have access to a porterbox of that architecture, here are |
| 90 |
some instructions that you use to bootstrap mlton on that architecture: |
| 91 |
|
| 92 |
1. Create a clean build schroot on the porterbox |
| 93 |
------------------------------------------------ |
| 94 |
|
| 95 |
These instructions assume that you are porting mlton via one of |
| 96 |
Debian's porterboxes. In this case, it is not possible to |
| 97 |
directly install mlton's build dependencies on the host, and you |
| 98 |
must instead install them in a chroot. |
| 99 |
|
| 100 |
ARCH=i386 # Arch we are bootstrapping |
| 101 |
PORTERBOX=barriere.debian.org |
| 102 |
SCHROOT=$USER-sid-$ARCH |
| 103 |
REMOTE_TMP=tmp # temporary remote directory for building |
| 104 |
|
| 105 |
cat <<EOF | ssh $PORTERBOX |
| 106 |
schroot -b -c sid_$ARCH-dchroot -n $SCHROOT && |
| 107 |
dd-schroot-cmd -c $SCHROOT apt-get update && |
| 108 |
dd-schroot-cmd -c $SCHROOT apt-get dist-upgrade -y && |
| 109 |
dd-schroot-cmd -c $SCHROOT apt-get install -y eatmydata && |
| 110 |
dd-schroot-cmd -c $SCHROOT apt-get build-dep -y mlton && |
| 111 |
mkdir -p $REMOTE_TMP |
| 112 |
EOF |
| 113 |
|
| 114 |
If mlton does not already exist for your architecture, you will not be |
| 115 |
able to install all build dependencies for mlton (e.g., mlton-compiler |
| 116 |
will be missing). This is OK. |
| 117 |
|
| 118 |
2. Git clone a copy of mlton's sources |
| 119 |
-------------------------------------- |
| 120 |
|
| 121 |
Upstream's bootstrapping infrastructure relies on git-archive(1) to |
| 122 |
transfer sources between hosts. Thus, you need to make sure that you |
| 123 |
have a Git clone of the sources (either upstream's tree or the Debian |
| 124 |
source package). |
| 125 |
|
| 126 |
debcheckout https://salsa.debian.org/debian/mlton.git |
| 127 |
cd mlton |
| 128 |
|
| 129 |
3. Build mlton locally |
| 130 |
---------------------- |
| 131 |
|
| 132 |
Next, we weed a working copy of mlton in our local source tree. |
| 133 |
Install any build dependencies, as needed: |
| 134 |
|
| 135 |
apt-get build-dep mlton |
| 136 |
|
| 137 |
Next, the repacked sources pre-extract various embedded tarballs, and we |
| 138 |
patch upstream's Makefiles to not extract them. As a result, we must |
| 139 |
apply Debian's patches before we can build. We also need to commit these |
| 140 |
changes because git-archive only knows about commited changes. |
| 141 |
|
| 142 |
git switch -c local-only/mlton-bootstrap |
| 143 |
dpkg-source --before-build . |
| 144 |
git add . |
| 145 |
git commit -am "Commit applied patches" |
| 146 |
|
| 147 |
Finally, we build the sources in the local source tree: |
| 148 |
|
| 149 |
make |
| 150 |
|
| 151 |
4. Bootstrap the package on the remote architecture |
| 152 |
--------------------------------------------------- |
| 153 |
|
| 154 |
Upstream's Makefile provides a remote-bootstrap target that uses SSH to |
| 155 |
bootstrap mlton on the porterbox. It copies certain files over to |
| 156 |
generate binary files with the appropriate symbols, while also using the |
| 157 |
local mlton compiler to handle the remainder of the compilation. Please |
| 158 |
see the documentation in the Makefile for additional information. |
| 159 |
|
| 160 |
make SCHROOT=$SCHROOT REMOTE_MACHINE=ssh://$PORTERBOX \ |
| 161 |
REMOTE_TMP=$REMOTE_TMP remote-bootstrap |
| 162 |
|
| 163 |
5. Send the bootstrapped mlton binary to the porterbox |
| 164 |
------------------------------------------------------ |
| 165 |
|
| 166 |
If the previous step succeeds, you should have a compressed tarball |
| 167 |
whose name follows the pattern mlton-MLTON_VERSION.ARCH-OS.tgz in your |
| 168 |
local source directory. It contains a mlton binary and runtime that will |
| 169 |
run on the porterbox. |
| 170 |
|
| 171 |
scp mlton-*.tgz $PORTERBOX |
| 172 |
|
| 173 |
6. Send the mlton source package to the porterbox |
| 174 |
------------------------------------------------- |
| 175 |
|
| 176 |
Our goal is, after all, to build a Debian binary package on the |
| 177 |
porterbox. |
| 178 |
|
| 179 |
git reset --hard HEAD && git clean -qxdf # clean source tree |
| 180 |
dpkg-buildpackage -S --no-sign |
| 181 |
VERSION="$(dpkg-parsechangelog --show-field Version)" |
| 182 |
dcmd scp ../mlton_$VERSION.dsc $PORTERBOX: |
| 183 |
|
| 184 |
7. Build binary package on porterbox |
| 185 |
------------------------------------ |
| 186 |
|
| 187 |
We use the clean schroot that we generated plus the binary bootstrapping |
| 188 |
files that we just built to build our binary package. We ask |
| 189 |
dpkg-buildpackage not to check for build dependencies, because we will |
| 190 |
use our bootstrapping copy of mlton instead of the (potentially |
| 191 |
nonexistent) mlton binary package. |
| 192 |
|
| 193 |
export BOOTSTRAP=mlton-VERSION.ARCH-OS |
| 194 |
tar zxvf $BOOTSTRAP.tgz |
| 195 |
# preserve environment to access BOOTSTRAP: |
| 196 |
schroot -c $SCHROOT -r --preserve-environment |
| 197 |
export PATH=~/$BOOTSTRAP/bin/:$PATH |
| 198 |
dpkg-buildpackage -B --no-check-builddeps mlton_*.dsc |
| 199 |
|
| 200 |
-- Ryan Kavanagh <[email protected]> Fri, 07 Nov 2025 10:38:55 -0500 |