Skip to content
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

Add better support for armv7a cross compilation #1874

Open
wants to merge 163 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
939365b
Support for armv7a-bionic (android)
angerman Feb 1, 2023
0ca227b
allow setupBuildFlags on components and packages
angerman Feb 18, 2023
c3c3ca4
android + ios: missing patches (#1884)
shumvgolove Mar 18, 2023
079fcba
Fix hadrian naming convenction
angerman Oct 7, 2023
676aab2
Fix format
angerman Oct 7, 2023
c1dfab0
newlines
angerman Oct 8, 2023
9b3230d
WIP tools
angerman Oct 10, 2023
26379ae
Add iserv logic
angerman Oct 11, 2023
44af1d4
WIP
angerman Oct 15, 2023
fc0989b
Fix 9.6.3 aarch64 outline atomics
angerman Oct 22, 2023
8c33c01
Better patch
angerman Oct 23, 2023
e8198e9
Better linux cross
angerman Oct 23, 2023
4009bb7
Fix ghc:-dynamic-system-linker for android
angerman Oct 23, 2023
0c9b2ac
Fixup arm
angerman Oct 26, 2023
90094fd
Patch only for aarch64
angerman Oct 30, 2023
79882ce
add aggregated ghc-9.6 patch
angerman Nov 1, 2023
6922b22
More android patches
angerman Nov 12, 2023
eb3d141
Adds genapply patch for 9.6
angerman Nov 13, 2023
315446d
Add [PATCH] AArch64: Fix broken conditional jumps for offsets >= 1MB
angerman Nov 12, 2023
cd404c4
Update default.nix
angerman Nov 14, 2023
72d622c
fix native musl
angerman Nov 14, 2023
2884b5f
add debug secno patch
angerman Nov 15, 2023
9ad088f
fix musl being considered stage2
angerman Nov 15, 2023
4e9820c
Allow undefined weak symbols.
angerman Nov 15, 2023
d1321de
Map missing symbols to 0xDEADBEEF.
angerman Nov 15, 2023
746a154
Set -dynamic-system-linker if musl and not x86_64
angerman Nov 15, 2023
3623f1b
proper parens
angerman Nov 15, 2023
74026f9
Add i686 cross
angerman Nov 16, 2023
b953554
more patches
angerman Nov 16, 2023
8ccbc65
:facepalm:
angerman Nov 16, 2023
12b7e01
patch interpreter also for windows.
angerman Nov 16, 2023
793163e
No dynamic loading on x86.
angerman Nov 16, 2023
8ec031e
:facepalm:
angerman Nov 16, 2023
2dfd858
Sigh
angerman Nov 16, 2023
22dae4d
Disable linux cross patch for now.
angerman Nov 16, 2023
a9035e4
Fix 32bit patch
angerman Nov 16, 2023
9b66410
No symbol loading on darwin.
angerman Nov 16, 2023
56ab95e
all ghc c files apple-a7
angerman Nov 28, 2023
8b72989
Drop duplicate patch
angerman Jan 20, 2024
d0c35e7
Fixup compilers
angerman Jan 21, 2024
ee32432
Update nixpkgs pins
hamishmack Sep 17, 2024
3d7f4c4
ifdLevel 0
hamishmack Sep 17, 2024
d7dac30
Simplify bootPkgs
hamishmack Sep 18, 2024
2ddccc0
Update materialized files
hamishmack Sep 18, 2024
aa83440
Bump nixpkgs-unstable and ghc911
hamishmack Sep 18, 2024
5ce8ded
Simplify bootPkgs
hamishmack Sep 18, 2024
f309e82
Simplify bootPkgs
hamishmack Sep 18, 2024
8c9fa55
Merge remote-tracking branch 'origin/master' into hkm/nixpkgs-update
hamishmack Sep 18, 2024
366a923
Update ghc911
hamishmack Sep 18, 2024
e76e589
Reduce the number of compilers tested
hamishmack Sep 19, 2024
915aaf4
Bump llvm for ghc >=9.10
hamishmack Sep 19, 2024
cac7369
Update patch upper bounds
hamishmack Sep 19, 2024
b9150b0
Include clang for useLLVM GHC
hamishmack Sep 19, 2024
a9e6f39
ifdLevel 1
hamishmack Sep 19, 2024
d8b5cc7
Add materialized files
hamishmack Sep 19, 2024
852d6c7
Disable haskell-gi-overloading (it's too slow to build)
hamishmack Sep 19, 2024
2a3d7f2
Update patch upper bound
hamishmack Sep 19, 2024
26e6735
ifdLevel 2
hamishmack Sep 20, 2024
663ae4f
Fixes for GHC HEAD
hamishmack Sep 20, 2024
2f22c31
ifdLevel 3
hamishmack Sep 20, 2024
7600b7f
Fixes for GHC HEAD
hamishmack Sep 21, 2024
caec44b
Fix supported-languages for GHC HEAD
hamishmack Sep 22, 2024
d55ec23
More fixes for GHC HEAD
hamishmack Sep 23, 2024
c20f0c0
Possible fix for plugin failure on aarch64-darwin
hamishmack Sep 23, 2024
7ac6c38
ifdLevel 0
hamishmack Sep 23, 2024
b0c2fb3
ifdLevel 3
hamishmack Sep 23, 2024
7a225bc
Add emar and emranlib to ghc js builds
hamishmack Sep 24, 2024
de5afd7
Fix `repo-tar` downloads
hamishmack Sep 24, 2024
4e41959
Fix `repo-tar` downloads
hamishmack Sep 24, 2024
431caa5
More fixes for ghc HEAD
hamishmack Sep 24, 2024
f474ff4
Merge remote-tracking branch 'origin/master' into hkm/nixpkgs-update
hamishmack Sep 24, 2024
6886c43
Fix for GHC 9.6 JS backend
hamishmack Sep 24, 2024
8956daa
Fix for GHC HEAD JS
hamishmack Sep 24, 2024
8b2a567
Merge branch 'hkm/nixpkgs-update' into armv7a
hamishmack Sep 25, 2024
00b830b
Merge remote-tracking branch 'origin/master' into armv7a
hamishmack Sep 25, 2024
209c2cd
fix syntax errors
hamishmack Sep 25, 2024
dd3ecbb
ifdLevel 0
hamishmack Sep 26, 2024
aec1d0b
Disable darwin on hydra for now.
hamishmack Sep 26, 2024
6b879fe
ifdLevel 1
hamishmack Sep 26, 2024
0395359
ifdLevel 2
hamishmack Sep 26, 2024
ff5049a
ifdLevel 3
hamishmack Sep 26, 2024
226e097
Fix eval
hamishmack Sep 27, 2024
bf96421
Fix patches
hamishmack Sep 27, 2024
4eaf4b5
Fix patches
hamishmack Sep 27, 2024
502db16
ifdLevel 0
hamishmack Sep 27, 2024
79350f9
ifdLevel 1
hamishmack Sep 27, 2024
48fae4a
ifdLevel 2
hamishmack Sep 27, 2024
885c207
ifdLevel 3
hamishmack Sep 27, 2024
79a0606
Add upper bound for patch
hamishmack Sep 27, 2024
d828c0b
Add ArchX86 and ArchRISCV64
hamishmack Sep 27, 2024
cac3cf7
Fix logic for iserv-syms.patch
hamishmack Sep 27, 2024
106a506
Fix logic for iserv-syms.patch
hamishmack Sep 27, 2024
6c31610
Remove old patch. Latest upstream GHC >9.6 have a better one.
hamishmack Sep 27, 2024
c8af6d6
Merge remote-tracking branch 'origin/master' into hkm/nixpkgs-update
hamishmack Sep 29, 2024
52ebca3
ifdLevel 0
hamishmack Sep 29, 2024
a70f5ad
ifdLevel 1
hamishmack Sep 29, 2024
b139433
Fix hadrian strip patch
hamishmack Sep 30, 2024
8f2754f
Fix hadrian strip patch
hamishmack Sep 30, 2024
b825a43
Merge remote-tracking branch 'origin/master' into hkm/nixpkgs-update
hamishmack Sep 30, 2024
a46fe4b
Merge branch 'hkm/nixpkgs-update' into armv7a
hamishmack Sep 30, 2024
4692b1a
Fix haddock (now that isNativeMusl works correctly)
hamishmack Sep 30, 2024
173edcc
Fix haddock (now that isNativeMusl works correctly)
hamishmack Sep 30, 2024
076782f
Avoid building source-pins on hackage (just make sure the components …
hamishmack Sep 30, 2024
321acd9
ifdLevel 2
hamishmack Sep 30, 2024
da3dd66
Merge branch 'hkm/nixpkgs-update' into armv7a
hamishmack Sep 30, 2024
ecabb6e
Fix for native musl builds
hamishmack Sep 30, 2024
922ec59
ifdLevel 3
hamishmack Sep 30, 2024
4b883cf
Add musl32 and android tests
hamishmack Sep 30, 2024
4f04b86
Add AArch32 to call-cabal-project-to-nix.nix
hamishmack Oct 1, 2024
df06075
Update iserv-proxy patches
hamishmack Oct 2, 2024
8e08834
Fix duplication of patch in overlays/bootstrap.nix
hamishmack Oct 2, 2024
e59fd8d
Merge remote-tracking branch 'origin/master' into hkm/nixpkgs-update
hamishmack Oct 2, 2024
a090d4e
Add missing materialized file
hamishmack Oct 3, 2024
06b9333
Merge remote-tracking branch 'origin/master' into hkm/nixpkgs-update
hamishmack Oct 3, 2024
e4b6e9b
Merge branch 'hkm/nixpkgs-update' into armv7a
hamishmack Oct 3, 2024
2145cdb
Remove patch already in 9.2.8
hamishmack Oct 3, 2024
159fb66
Build android compilers with nixpkgs 24.05
hamishmack Oct 3, 2024
a1e0b30
Fix gi-gtk test
hamishmack Oct 3, 2024
3e34303
Merge branch 'hkm/nixpkgs-update' into armv7a
hamishmack Oct 3, 2024
5fc3f08
Merge remote-tracking branch 'origin/master' into armv7a
hamishmack Oct 3, 2024
3521582
Merge remote-tracking branch 'origin/master' into armv7a
hamishmack Oct 7, 2024
49a2fb9
Merge remote-tracking branch 'origin/master' into armv7a
hamishmack Oct 10, 2024
057a33c
Fix eval
hamishmack Oct 14, 2024
ee588ac
Try aarch64-android-prebuilt
hamishmack Oct 14, 2024
089b3fd
Merge remote-tracking branch 'origin/master' into armv7a
hamishmack Nov 11, 2024
21ef26b
ifdLevel 1
hamishmack Nov 11, 2024
e7ea82c
Disable ncurses on android for now
hamishmack Nov 12, 2024
7a139cc
Fix patch
hamishmack Nov 13, 2024
4eae1c1
Use aarch64-android (not prebuilt)
hamishmack Nov 22, 2024
a6ad46d
Fixes for armv7a
hamishmack Nov 22, 2024
467f0ec
Fixes for armv7a
hamishmack Nov 22, 2024
646e64b
Fix ghc-9.6-32bit-cmm.patch bounds
hamishmack Nov 25, 2024
5928eca
Fix genapply patch bound
hamishmack Nov 25, 2024
770b95f
Try Android SDK version 26
hamishmack Nov 25, 2024
bc9ba01
Try Android SDK version 26
hamishmack Nov 26, 2024
9af775a
Try Android SDK version 26
hamishmack Nov 26, 2024
989066b
Use small address space
hamishmack Nov 26, 2024
821f72a
Use small address space
hamishmack Nov 26, 2024
fac5029
androidNdkVersion = "24"
hamishmack Nov 26, 2024
1d689df
Fix android sdk/ndk pins so they work for ci.nix
hamishmack Nov 27, 2024
f1309bb
Add missing casts
hamishmack Nov 28, 2024
821ad3b
Add preBuild to set CFLAGS
hamishmack Nov 29, 2024
689d5bc
Better fix?
hamishmack Nov 29, 2024
d6ad31d
Better fix?
hamishmack Nov 29, 2024
f666fdf
Support Cabal calling configure with "--host=arm-android"
hamishmack Dec 2, 2024
a158ea6
Fix ghc 9.8
hamishmack Dec 2, 2024
1293f27
Fix for ghc >9.10
hamishmack Dec 2, 2024
378ddb5
Fix patch error
hamishmack Dec 3, 2024
91dade0
Possible fix for aarch64 android
hamishmack Dec 3, 2024
5915b86
Fix patches for GHC 8.10
hamishmack Dec 4, 2024
9e161b9
Try aarch64-android-prebuilt
hamishmack Dec 4, 2024
f1b5442
Merge remote-tracking branch 'origin/master' into armv7a
hamishmack Dec 9, 2024
837523e
Include clang
hamishmack Dec 10, 2024
134d69a
Don't include clang for prebuilt android
hamishmack Dec 10, 2024
827008f
Merge remote-tracking branch 'origin/master' into armv7a
hamishmack Dec 18, 2024
87ac69d
Set `LLVMAS`
hamishmack Dec 19, 2024
6758658
Setting LLVMAS to `llvm-as` did not help
hamishmack Dec 19, 2024
09bc75d
Set `LLVMAS` the same as `CC`
hamishmack Dec 19, 2024
79c3370
Relax llvm max version
hamishmack Dec 19, 2024
ea25d0b
Try with llvm version bound relaxed, but without LLVMAS env var
hamishmack Dec 19, 2024
08efe5b
Define ELF64_ST_VISIBILITY and ELF32_ST_VISIBILITY for android
hamishmack Dec 20, 2024
e951f77
ifdLevel 2
hamishmack Dec 20, 2024
917ce14
ifdLevel 3
hamishmack Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion builder/comp-builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,15 @@ let
(enableFeature enableShared "shared")
(enableFeature enableExecutableDynamic "executable-dynamic")
(enableFeature doCoverage "coverage")
(enableFeature (enableLibraryForGhci && !stdenv.hostPlatform.isGhcjs) "library-for-ghci")
# For Android (or really anything that uses lld), -r will silently drop
# "lazy" symbols. Those are leaf symbols with no referenes. This however
# does not work when loading the objects into the linker, because then we
# occationally miss symbols when subsequent libraries depending on the one
# that dropped the symbol are loaded. bfd and lld support --whole-archive
# lld -r --whole-archive ... will _not_ drop lazy symbols. However the
# --whole-archive flag needs to come _before_ the objects, it's applied in
# sequence. The proper fix is thusly to add --while-archive to Cabal.
(enableFeature (enableLibraryForGhci && !stdenv.hostPlatform.isGhcjs && !stdenv.hostPlatform.isAndroid) "library-for-ghci")
] ++ lib.optionals (stdenv.hostPlatform.isMusl && (haskellLib.isExecutableType componentId)) [
# These flags will make sure the resulting executable is statically linked.
# If it uses other libraries it may be necessary for to add more
Expand Down
2 changes: 1 addition & 1 deletion builder/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ let
let
haskellPackages = {
# For musl we can use haddock from the buildGHC
ghc = if stdenv.hostPlatform.isLinux && stdenv.targetPlatform.isMusl && !haskellLib.isNativeMusl
ghc = if stdenv.targetPlatform.isMusl
then ghc.buildGHC
else ghc;
inherit packages hoogle;
Expand Down
2 changes: 1 addition & 1 deletion builder/ghc-for-component-wrapper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let
libDir = "$wrappedGhc/${configFiles.libDir}";
docDir = "$wrappedGhc/share/doc/ghc/html";
# For musl we can use haddock from the buildGHC
haddock = if stdenv.hostPlatform.isLinux && stdenv.targetPlatform.isMusl && !haskellLib.isNativeMusl
haddock = if stdenv.targetPlatform.isMusl
then ghc.buildGHC
else ghc;

Expand Down
7 changes: 5 additions & 2 deletions ci.nix
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
nixpkgs.lib.optionalAttrs (nixpkgsName == "R2405") {
ghc96 = false;
ghc98 = false;
ghc910 = true;
} // nixpkgs.lib.optionalAttrs (nixpkgsName == "unstable") {
ghc810 = true;
ghc92 = false;
Expand Down Expand Up @@ -101,8 +102,10 @@
} // lib.optionalAttrs (system == "x86_64-linux" && nixpkgsName == "unstable" && !builtins.elem compiler-nix-name ["ghc902" "ghc928" "ghc948"]) {
# Musl cross only works on linux
# aarch64 cross only works on linux
inherit (lib.systems.examples) musl64 aarch64-multiplatform;
} // lib.optionalAttrs (system == "x86_64-linux" && nixpkgsName == "unstable" && builtins.elem compiler-nix-name ["ghc927" "ghc928"]) {
inherit (lib.systems.examples) musl32 musl64 aarch64-multiplatform;
} // lib.optionalAttrs (system == "x86_64-linux" && nixpkgsName == "unstable" && !builtins.elem compiler-nix-name ["ghc902" "ghc928" "ghc948"]) {
inherit (lib.systems.examples) aarch64-android-prebuilt armv7a-android-prebuilt;
} // lib.optionalAttrs (system == "x86_64-linux" && nixpkgsName == "unstable" && !builtins.elem compiler-nix-name ["ghc8107" "ghc902"]) {
# TODO fix this for the compilers we build with hadrian (ghc >=9.4)
inherit (lib.systems.examples) aarch64-multiplatform-musl;
} // lib.optionalAttrs (system == "aarch64-linux" && nixpkgsName == "unstable" && !builtins.elem compiler-nix-name ["ghc8107" "ghc902"]) {
Expand Down
53 changes: 35 additions & 18 deletions compiler/ghc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ let self =

, enableDWARF ? false

, enableTerminfo ?
, enableTerminfo ? !stdenv.targetPlatform.isAndroid &&
# Terminfo does not work on older ghc cross arm and windows compilers
(!haskell-nix.haskellLib.isCrossTarget || !(stdenv.targetPlatform.isAarch64 || stdenv.targetPlatform.isWindows) || builtins.compareVersions ghc-version "8.10" >= 0)
(!haskell-nix.haskellLib.isCrossTarget || !(stdenv.targetPlatform.isAarch32 || stdenv.targetPlatform.isAarch64 || stdenv.targetPlatform.isWindows) || builtins.compareVersions ghc-version "8.10" >= 0)

, # Wheter to build in NUMA support
enableNUMA ? true
Expand All @@ -62,7 +62,7 @@ let self =

, # Whether to disable the large address space allocator
# necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
disableLargeAddressSpace ? stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64
disableLargeAddressSpace ? stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64 || stdenv.targetPlatform.isAndroid

, useLdGold ?
# might be better check to see if cc is clang/llvm?
Expand Down Expand Up @@ -169,8 +169,9 @@ let
WITH_TERMINFO=NO
''
# musl doesn't have a system-linker. Only on x86, and on x86 we need it, as
# our elf linker for x86_64 is broken.
+ lib.optionalString (targetPlatform.isAndroid || (targetPlatform.isMusl && !targetPlatform.isx86)) ''
# our elf linker for x86_64 is broken. The i686 one seems also to not exist.
# So it's really _just_ x86_64.
+ lib.optionalString (targetPlatform.isAndroid || (targetPlatform.isMusl && !targetPlatform.isx86_64)) ''
compiler_CONFIGURE_OPTS += --flags=-dynamic-system-linker
''
# While split sections are now enabled by default in ghc 8.8 for windows,
Expand All @@ -183,12 +184,14 @@ let
SplitSections = NO
'' + lib.optionalString (!enableLibraryProfiling) ''
BUILD_PROF_LIBS = NO
'' + lib.optionalString (disableLargeAddressSpace) ''
libraries/base_CONFIGURE_OPTS += --configure-option=--with-libcharset=no
'';

# `--with` flags for libraries needed for RTS linker
configureFlags = [
"--datadir=$doc/share/doc/ghc"
] ++ lib.optionals (!targetPlatform.isGhcjs) ["--with-curses-includes=${targetPackages.ncurses.dev}/include" "--with-curses-libraries=${targetPackages.ncurses.out}/lib"
] ++ lib.optionals (!targetPlatform.isGhcjs && !targetPlatform.isAndroid) ["--with-curses-includes=${targetPackages.ncurses.dev}/include" "--with-curses-libraries=${targetPackages.ncurses.out}/lib"
] ++ lib.optionals (targetLibffi != null && !targetPlatform.isGhcjs) ["--with-system-libffi" "--with-ffi-includes=${targetLibffi.dev}/include" "--with-ffi-libraries=${targetLibffi.out}/lib"
] ++ lib.optionals (!enableIntegerSimple && !targetPlatform.isGhcjs) [
"--with-gmp-includes=${targetGmp.dev}/include" "--with-gmp-libraries=${targetGmp.out}/lib"
Expand Down Expand Up @@ -216,23 +219,24 @@ let
# https://gitlab.haskell.org/ghc/ghc/-/issues/23188
# https://github.com/haskell/cabal/issues/8882
"fp_cv_prog_ar_supports_dash_l=no"
] ++ lib.optional (targetPlatform.isGhcjs) "--target=javascript-unknown-ghcjs"; # TODO use configurePlatforms once tripple is updated in nixpkgs
] ++ lib.optionals (targetPlatform.isDarwin) [
"--without-libcharset"
] ++ lib.optional (targetPlatform.isGhcjs) "--target=javascript-unknown-ghcjs" # TODO use configurePlatforms once tripple is updated in nixpkgs
;

# Splicer will pull out correct variations
libDeps = platform: lib.optional (enableTerminfo && !targetPlatform.isGhcjs) [ targetPackages.ncurses targetPackages.ncurses.dev ]
libDeps = platform: lib.optional (enableTerminfo && !targetPlatform.isGhcjs && !targetPlatform.isAndroid) [ targetPackages.ncurses targetPackages.ncurses.dev ]
++ lib.optional (!targetPlatform.isGhcjs) targetLibffi
++ lib.optional (!enableIntegerSimple && !targetPlatform.isGhcjs) gmp
++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv
++ lib.optional (enableNUMA && platform.isLinux && !platform.isAarch32 && !platform.isAndroid) numactl
# Even with terminfo disabled some older ghc cross arm and windows compilers do not build unless `ncurses` is found and they seem to want the buildPlatform version
++ lib.optional (!enableTerminfo && haskell-nix.haskellLib.isCrossTarget && (stdenv.targetPlatform.isAarch64 || stdenv.targetPlatform.isWindows) && builtins.compareVersions ghc-version "8.10" < 0) ncurses.dev
++ lib.optional enableDWARF (lib.getLib elfutils);

toolsForTarget =
if targetPlatform.isGhcjs
then [ buildPackages.emscripten ]
else if hostPlatform == buildPlatform
then [ targetPackages.stdenv.cc ] ++ lib.optionals useLLVM [llvmPackages.llvm llvmPackages.clang]
then [ targetPackages.stdenv.cc ] ++ lib.optionals useLLVM ([llvmPackages.llvm] ++ lib.optional (!targetPlatform.useAndroidPrebuilt) llvmPackages.clang)
else assert targetPlatform == hostPlatform; # build != host == target
[ stdenv.cc ] ++ lib.optional useLLVM buildLlvmPackages.llvm;

Expand All @@ -244,7 +248,7 @@ let
# for musl only; but I'd like to stay far away from the unnecessary
# bindist logic as we can. It's slow, and buggy, and doesn't provide any
# value for us.
installStage1 = useHadrian && (haskell-nix.haskellLib.isCrossTarget || stdenv.targetPlatform.isMusl);
installStage1 = useHadrian && (with haskell-nix.haskellLib; isCrossTarget || isNativeMusl);

hadrian =
let
Expand Down Expand Up @@ -339,7 +343,14 @@ let
" '*.ghc.cabal.configure.opts += --flags=-dynamic-system-linker'"
# The following is required if we build on aarch64-darwin for aarch64-iOS. Otherwise older
# iPhones/iPads/... won't understand the compiled code, as the compiler will emit LDSETALH
# + lib.optionalString (targetPlatform.???) "'*.rts.ghc.c.opts += -optc-mcpu=apple-a7 -optc-march=armv8-a+norcpc'"
# FIXME: we should have iOS as an argument to this derivation, and then make this, as well as
# disableLargeAddress space conditional on iOS = true.
+ lib.optionalString (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64)
" '*.*.ghc.c.opts += -optc-mcpu=apple-a7 -optc-march=armv8-a+norcpc'"
+ lib.optionalString (targetPlatform.isAndroid && targetPlatform.isAarch32)
" 'stage1.*.ghc.c.opts += -optc-march=armv7-a -optc-mfloat-abi=softfp -optc-mfpu=vfpv3-d16'"
+ lib.optionalString (targetPlatform.isAndroid && targetPlatform.isAarch64)
" 'stage1.*.ghc.c.opts += -optc-march=armv8-a'"
# For GHC versions in the 9.x range that don't support the +native_bignum flavour transformer yet
+ lib.optionalString ((enableNativeBignum && !hadrianHasNativeBignumFlavour))
" --bignum=native"
Expand Down Expand Up @@ -456,7 +467,10 @@ stdenv.mkDerivation (rec {
export NIX_LDFLAGS+=" -rpath $out/lib/${targetPrefix}ghc-${ghc-version}"
'' + lib.optionalString stdenv.isDarwin ''
export NIX_LDFLAGS+=" -no_dtrace_dof"
'' + lib.optionalString targetPlatform.useAndroidPrebuilt ''
'' +
# we really want "+armv7-a,+soft-float,+neon" as features, but llvm will
# fail with those :facepalm:
lib.optionalString targetPlatform.useAndroidPrebuilt ''
sed -i -e '5i ,("armv7a-unknown-linux-androideabi", ("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", "cortex-a8", ""))' llvm-targets
'' + lib.optionalString targetPlatform.isMusl ''
echo "patching llvm-targets for musl targets..."
Expand Down Expand Up @@ -531,7 +545,7 @@ stdenv.mkDerivation (rec {
++ lib.optional stdenv.targetPlatform.isMusl "pie"
++ lib.optional enableDWARF "fortify";

postInstall = lib.optionalString (enableNUMA && targetPlatform.isLinux) ''
postInstall = lib.optionalString (enableNUMA && targetPlatform.isLinux && !targetPlatform.isAarch32 && !targetPlatform.isAndroid) ''
# Patch rts.conf to ensure libnuma can be found

for file in $(find "$out/lib" -name "rts*.conf"); do
Expand Down Expand Up @@ -725,7 +739,7 @@ stdenv.mkDerivation (rec {
--replace 'dynamic-library-dirs:' 'dynamic-library-dirs: ${libcxx}/lib'
find . -name 'system*.conf*'
cat mk/system-cxx-std-lib-1.0.conf
'' + lib.optionalString (installStage1 && stdenv.targetPlatform.isMusl) ''
'' + lib.optionalString (installStage1 && haskell-nix.haskellLib.isNativeMusl) ''
substituteInPlace hadrian/cfg/system.config \
--replace 'cross-compiling = YES' \
'cross-compiling = NO'
Expand Down Expand Up @@ -775,7 +789,7 @@ stdenv.mkDerivation (rec {
dontStrip = true;
dontPatchELF = true;
noAuditTmpdir = true;
} // lib.optionalAttrs (stdenv.buildPlatform.isDarwin || stdenv.targetPlatform.isWindows) {
} // {
# ghc install on macOS wants to run `xattr -r -c`
# The macOS version fails because it wants python 2.
# The nix version of xattr does not support those args.
Expand Down Expand Up @@ -815,12 +829,13 @@ stdenv.mkDerivation (rec {
--replace 'dynamic-library-dirs:' 'dynamic-library-dirs: ${libcxx}/lib'
find . -name 'system*.conf*'
cat mk/system-cxx-std-lib-1.0.conf
'' + lib.optionalString (installStage1 && !haskell-nix.haskellLib.isCrossTarget && stdenv.targetPlatform.isMusl) ''
'' + lib.optionalString (installStage1 && haskell-nix.haskellLib.isNativeMusl) ''
substituteInPlace hadrian/cfg/system.config \
--replace 'cross-compiling = YES' \
'cross-compiling = NO'
'';
buildPhase = ''
runHook preBuild
${hadrian}/bin/hadrian ${hadrianArgs}
'' + lib.optionalString (installStage1 && !stdenv.targetPlatform.isGhcjs && builtins.compareVersions ghc-version "9.8" < 0) ''
${hadrian}/bin/hadrian ${hadrianArgs} stage1:lib:libiserv
Expand All @@ -835,6 +850,8 @@ stdenv.mkDerivation (rec {
mv $exe ${targetPrefix}$exe
done
popd
'' + ''
runHook postBuild
'';

# Hadrian's installation only works for native compilers, and is broken for cross compilers.
Expand Down
10 changes: 8 additions & 2 deletions lib/call-cabal-project-to-nix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,14 @@ let
echo ',("target arch","${
if pkgs.stdenv.targetPlatform.isx86_64
then "ArchX86_64"
else if pkgs.stdenv.targetPlatform.isx86
then "ArchX86"
else if pkgs.stdenv.targetPlatform.isRiscV64
then "ArchRISCV64"
else if pkgs.stdenv.targetPlatform.isAarch64
then "ArchAArch64"
else if pkgs.stdenv.targetPlatform.isAarch32
then "ArchAArch32"
else if pkgs.stdenv.targetPlatform.isJavaScript
then "ArchJavaScript"
else throw "Unknown target arch ${pkgs.stdenv.targetPlatform.config}"
Expand Down Expand Up @@ -681,8 +687,8 @@ let
cabal.project.freeze
chmod +w cabal.project.freeze
''}
export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
export GIT_SSL_CAINFO=${cacert}/etc/ssl/certs/ca-bundle.crt
export SSL_CERT_FILE=${evalPackages.cacert}/etc/ssl/certs/ca-bundle.crt
export GIT_SSL_CAINFO=${evalPackages.cacert}/etc/ssl/certs/ca-bundle.crt

export CABAL_DIR=${
# This creates `.cabal` directory that is as it would have
Expand Down
8 changes: 5 additions & 3 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@ in {
isCrossTarget = stdenv.targetPlatform != stdenv.hostPlatform
&& !(stdenv.hostPlatform.isLinux && stdenv.targetPlatform.isMusl && stdenv.hostPlatform.linuxArch == stdenv.targetPlatform.linuxArch);
# Native musl build-host-target combo
isNativeMusl = stdenv.hostPlatform.isMusl
&& stdenv.buildPlatform == stdenv.hostPlatform
&& stdenv.hostPlatform == stdenv.targetPlatform;
isNativeMusl = stdenv.targetPlatform.isMusl
&& stdenv.buildPlatform.linuxArch == stdenv.hostPlatform.linuxArch
&& stdenv.hostPlatform.linuxArch == stdenv.targetPlatform.linuxArch;

# Takes a version number, module or list of modules (for cabalProject)
# and converts it to an list of project modules. This allows
Expand Down Expand Up @@ -593,6 +593,8 @@ in {
then "arm"
else if hostPlatform.isAarch64
then "aarch64"
else if hostPlatform.isi686
then "i386"
else abort "Don't know which QEMU to use for hostPlatform ${hostPlatform.config}. Please provide qemuSuffix";

# How to run ldd when checking for static linking
Expand Down
40 changes: 35 additions & 5 deletions overlays/android.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
_final: prev: prev.lib.optionalAttrs prev.stdenv.hostPlatform.isAndroid ({
final: prev: {
# Use android SDK version 26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[diff] reported by reviewdog 🐶

Suggested change
final: prev: {
_final: prev: {

lib = prev.lib // {
systems = prev.lib.systems // {
examples = prev.lib.systems.examples // {
aarch64-android = prev.lib.systems.examples.aarch64-android // {
androidSdkVersion = "269";
androidNdkVersion = "24";
};
armv7a-android-prebuilt = prev.lib.systems.examples.armv7a-android-prebuilt // {
androidSdkVersion = "26";
androidNdkVersion = "24";
};
};
};
};
} // prev.lib.optionalAttrs prev.stdenv.hostPlatform.isAndroid ({

# we really only want the static one.
libiconv = (prev.libiconv.override { enableStatic = true; enableShared = false; }).overrideAttrs(_: {
hardeningDisable = [ "fortify" "stackprotector" "format" ];
Expand All @@ -11,18 +28,31 @@ _final: prev: prev.lib.optionalAttrs prev.stdenv.hostPlatform.isAndroid ({
'';
# my current thinking is that this is due to the android toolchain using r23, api30.
});
libffi = prev.libffi.overrideAttrs (_: {
libffi = prev.libffi.overrideAttrs ( old: {
dontDisableStatic = true;
configureFlags = old.configureFlags ++ [ "--disable-shared" ];

hardeningDisable = [ "fortify" "stackprotector" "format" ];
} // prev.lib.optionalAttrs (prev.stdenv.hostPlatform.isAarch32 || prev.stdenv.hostPlatform.isAarch64) {
# see libiconv. We want to target a lower minsdk
postConfigure = ''
echo "#undef HAVE_MEMFD_CREATE" >> aarch64-unknown-linux-android/fficonfig.h
echo "#undef HAVE_MEMFD_CREATE" >> ${prev.stdenv.hostPlatform.config}/fficonfig.h
'';
});
gmp6 = (prev.gmp6.override { withStatic = true; }).overrideAttrs(_: {
gmp6 = (prev.gmp6.override { withStatic = true; }).overrideAttrs(old: {
hardeningDisable = [ "fortify" "stackprotector" "format" ];
configureFlags = old.configureFlags ++ [ "--disable-shared" ];
});
zlib = prev.zlib.override { shared = false; static = true; };
# kernel tls (ktls) doesn't work with the android kernel. And will complain
# about lots of implicitly declared functions and undeclared identifiers,
# because the android (linux) kernel doesn't expose those.
openssl = prev.openssl.override { static = true; enableKTLS = false; };

}) // prev.lib.optionalAttrs (prev.stdenv.targetPlatform.isAndroid && (!prev.stdenv.hostPlatform.useAndroidPrebuilt)) ({
bionic = prev.bionic.override { enableStatic = true; };
# we still need the shared libraries to link against on the platform. GHC
# has been neutered to not even try loading shared libs and will use dynamic ones.
# We also link iserv against the static libs, so that we have a fully static
# android (bionic/linux) iserv we can execute on glibc/linux.
bionic = prev.bionic.override { enableStatic = true; enableShared = true; };
})
Loading
Loading