nix-overlays
nix-overlays copied to clipboard
cross-compiling to aarch64 fails: ld: src/topkg.a: error adding symbols
Hello, thank you for the great overlay !
Following the suggestion in #620 and taking inspiration from doi2bib's flake and default.nix, I managed to build my current toy project to native (x86_64-linux-gnu) and musl targets.
Unfortunately, cross-compiling to aarch64-musl fails. I must admit I'm running nix over an Archlinux install, which of course complicates things a little. But since the x86_64 musl build succeeds, I hope I'm not too far from an expected setup. Here is the relevant error :
# nix build .#aarch64-musl
[...]
error: builder for '/nix/store/82gh18jj8i533w5rrghzx09bdgszd0cx-ocaml5.2.1-topkg-1.0.7.drv' failed with exit code 1;
[...]
> + ocamlfind ocamlopt -c -g -bin-annot -safe-string -I src -I test -I src-bin -I src-care -o src/topkg.cmx src/topkg.ml
> + ocamlfind ocamlopt -a -I src src/topkg_string.cmx src/topkg_fpath.cmx src/topkg_cmd.cmx src/topkg_result.cmx src/topkg_log.cmx src/topkg_os.cmx src/topkg_codec.cmx src/topkg_vcs.cmx src/topkg_conf.cmx src/topkg_build.cmx src/topkg_opam.cmx src/topkg_distrib.cmx src/topkg_fexts.cmx src/topkg_test.cmx src/topkg_install.cmx src/topkg_publish.cmx src/topkg_pkg.cmx src/topkg_ipc.cmx src/topkg_main.cmx src/topkg.cmx -o src/topkg.cmxa
> + ocamlfind ocamlopt -shared -linkall -I src src/topkg.cmxa -o src/topkg.cmxs
> + ocamlfind ocamlopt -shared -linkall -I src src/topkg.cmxa -o src/topkg.cmxs
> /nix/store/v63bxfiacw082c7ijshf60alvvrpfxsq-binutils-2.44/bin/ld: src/topkg.a: error adding symbols: archive has no index; run ranlib to add one
> collect2: error: ld returned 1 exit status
> File "caml_startup", line 1:
> Error: Error during linking (exit code 1)
> Command exited with code 2.
> pkg.ml: [ERROR] cmd ['ocamlbuild' '-use-ocamlfind' '-classic-display' '-j' '4' '-tag' 'debug'
> '-build-dir' '_build' 'CHANGES.md' 'LICENSE.md' 'README.md' 'pkg/META'
> 'topkg.opam' 'src/topkg.a' 'src/topkg.cmxs' 'src/topkg.cmxa'
> 'src/topkg.cma' 'src/topkg_vcs.cmx' 'src/topkg_test.cmx'
> 'src/topkg_string.cmx' 'src/topkg_result.cmx' 'src/topkg_publish.cmx'
> 'src/topkg_pkg.cmx' 'src/topkg_os.cmx' 'src/topkg_opam.cmx'
> 'src/topkg_main.cmx' 'src/topkg_log.cmx' 'src/topkg_ipc.cmx'
> 'src/topkg_install.cmx' 'src/topkg_fpath.cmx' 'src/topkg_fexts.cmx'
> 'src/topkg_distrib.cmx' 'src/topkg_conf.cmx' 'src/topkg_codec.cmx'
> 'src/topkg_cmd.cmx' 'src/topkg_build.cmx' 'src/topkg.cmx'
> 'src/topkg.cmi' 'src/topkg.mli' 'doc/index-topkg.mld']: exited with 10
I'm using the following setup :
flake.nix
{
description = "liminar Nix Flake";
nixConfig.extra-substituters = [
"https://anmonteiro.nix-cache.workers.dev"
];
inputs.nixpkgs.url = "github:nix-ocaml/nix-overlays";
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages."${system}";
in
{
packages = {
native = pkgs.callPackage ./nix { };
musl =
let
pkgs' = pkgs.pkgsCross.musl64;
in
pkgs'.lib.callPackageWith pkgs' ./nix {
static = true;
};
aarch64-musl =
let
pkgs' = pkgs.pkgsCross.aarch64-multiplatform-musl;
in
pkgs'.lib.callPackageWith pkgs' ./nix {
static = true;
crossName = "aarch64";
};
};
});
}
nix/default.nix
{
pkgs,
stdenv,
lib,
ocamlPackages,
static ? false,
crossName ? null,
}:
let
html_of_jsx = ocamlPackages.buildDunePackage {
pname = "html_of_jsx";
version = "0.0.4";
src = pkgs.fetchFromGitHub {
owner = "davesnx";
repo = "html_of_jsx";
rev = "0.0.4";
hash = "sha256-MOXV+yLlrzRaFVBuYyNhQoa1bw6/GPAY8vTvPCuv/2s=";
};
OCAMLFIND_TOOLCHAIN = crossName;
buildInputs = with ocamlPackages; [
ppxlib
];
doCheck = false;
};
in
ocamlPackages.buildDunePackage {
pname = "liminar";
version = "0.0.1";
src = ./..;
OCAMLFIND_TOOLCHAIN = crossName;
nativeBuildInputs = with ocamlPackages; [
mlx
];
buildInputs = with ocamlPackages; [
dream
dream-pure
jose
oidc
mlx
cohttp-lwt-unix
html_of_jsx
uri
yojson
logs
lwt_ppx
];
buildPhase = ''
pwd
dune build bin/Liminar.exe --profile=${if static then "static" else "release"}
'';
installPhase = ''
mkdir -p $out/bin
mv _build/default/bin/Liminar.exe $out/bin/liminar
'';
meta = {
homepage = "https://codeberg.org/lafleur/liminar";
description = "companion webapp for the Laminar CI";
};
}