I actually already faced those same configure warnings last night after
my progress update. I just ignored them, $ gmake install worked fine for
me.

I never got a chance to test actual compilation. At the time, I was just
testing to see if I could install an amd64 bindist, so I could, as a
last resort, replace the amd64 binaries with arm64 binaries on a system
with a bindist installed, then I left it there and went to bed.

Today, I worked on getting the bindist building w/ arm64 binaries, and
I've finally succeeded there. I'm able to then $ gmake install, though
I get the same issues where I need to pass those flags (thanks to your
email, I was able to blast through that part when I got to it to test
compiling a hello world program like you were able to do just to make
sure the bindist built correctly).

Anyway, to detail the issue with the bindist, as I mentioned in my last
email, the ghc-pkg command cuts that short. It seemed the ghc-pkg call
was the only command called, and reading the --help for it, from what
I gathered, its side effect is simply to generate the .conf files in
package.conf.d directory when packages have been merely copied into the
libdir (instead of installed through Cabal or something, I suppose).

So I edited the Hadrian/Shake build steps for the bindist to use the
stage 1 binary for that purpose (in _build/stage0) when cross-compiling
(although I guess even when not cross-compiling, you can do so) to let
the bindist build run to completion.

Then, I took that tarball and tried to do $ ./configure
--prefix="$HOME/ghc" and $ gmake install on my OpenBSD/arm64 VM. The
result was the final error, which is that the ghc (and haddock) wrapper
script didn't have the required -B flag, instead simply using the
generic wrapper script recipe.

Of course, it didn't say it in those words, but while I'd been digging
through the bindist rules in hadrian/, I saw an interesting “Note
[Wrapper scripts and binary distributions]” as well as “Note [Two
Types of Wrappers]”.

If you look at the GHC wrapper script, it's basically:

ghcWrapper :: Action String
ghcWrapper = pure $ "exec \"$executablename\" -B\"$libdir\" ${1+\"$@\"}\n"

but when I looked at my one, it excluded the -B. It turns out that it
figures out the wrapper script template to use with a function called
wrapper which just takes a string like "ghc", "ghc-pkg", etc., but it
was comparing to the filenames prefixed with the target platform triple,
which presumably only happens when cross-compiling.

That was an easy fix of simply stripping out the target platform triple
prefix when doing the comparison, and I reran a fresh bindist build, and
finally had a working bindist which could simply be installed with $
./configure --prefix=… and $ gmake install.

I think a better solution is to not prefix the binaries like that, but
who knows what other downstream effects that may have on the build
process at this time.

I get help output, so it runs, but of course, this is where I get those
sysroot problems you talk about. I see some references to the sysroot
used during the build in the installed GHC's lib directory, so I assume
when building the bindist, there might be some way we can fix those
references up before creating the tarball.

I think we're really close to being able to test using it as a stage 0
to build the new compiler directly on arm64.

Before I forget, this is the patch (which should be split into two
commits when we merge it upstream) to make the changes I described
above:

diff --git a/hadrian/src/Rules/BinaryDist.hs b/hadrian/src/Rules/BinaryDist.hs
index 4f2b4220da..935fe8d1f1 100644
--- a/hadrian/src/Rules/BinaryDist.hs
+++ b/hadrian/src/Rules/BinaryDist.hs
@@ -152,10 +152,11 @@ bindistRules = do
         rtsDir         <- pkgUnitId Stage1 rts
         -- let rtsDir  = "rts"
 
-        let ghcBuildDir      = root -/- stageString Stage1
+        let stage1GhcBuildDir      = root -/- stageString Stage1
+            stage0GhcBuildDir      = root -/- stageString (Stage0 InTreeLibs)
             bindistFilesDir  = root -/- "bindist" -/- ghcVersionPretty
             ghcVersionPretty = "ghc-" ++ version ++ "-" ++ targetPlatform
-            rtsIncludeDir    = ghcBuildDir -/- "lib" -/- distDir -/- rtsDir
+            rtsIncludeDir    = stage1GhcBuildDir -/- "lib" -/- distDir -/- 
rtsDir
                                -/- "include"
 
         -- We 'need' all binaries and libraries
@@ -228,7 +229,7 @@ bindistRules = do
                   IO.removeFile versioned_runhaskell_path <|> return ()
                   IO.createFileLink version_prog versioned_runhaskell_path
 
-        copyDirectory (ghcBuildDir -/- "lib") bindistFilesDir
+        copyDirectory (stage1GhcBuildDir -/- "lib") bindistFilesDir
         copyDirectory (rtsIncludeDir)         bindistFilesDir
         when windowsHost $ createGhcii (bindistFilesDir -/- "bin")
 
@@ -239,7 +240,11 @@ bindistRules = do
         -- N.B. the ghc-pkg executable may be prefixed with a target triple
         -- (c.f. #20267).
         ghcPkgName <- programName (vanillaContext Stage1 ghcPkg)
-        cmd_ (bindistFilesDir -/- "bin" -/- ghcPkgName) ["recache"]
+        if cross then
+          cmd_ (stage0GhcBuildDir -/- "bin" -/- ghcPkgName) [
+            "recache", "--global-package-db=" <> stage1GhcBuildDir -/- "lib" 
-/- distDir -/- rtsDir
+          ]
+        else cmd_ (bindistFilesDir -/- "bin" -/- ghcPkgName) ["recache"]
 
 
 
@@ -269,7 +274,7 @@ bindistRules = do
         -- On Windows LICENSE files are in _build/lib/doc, which is
         -- already included above.
         unless windowsHost $ do
-          copyDirectory (ghcBuildDir -/- "share") bindistFilesDir
+          copyDirectory (stage1GhcBuildDir -/- "share") bindistFilesDir
 
         -- Include bash-completion script in binary distributions. We don't
         -- currently install this but merely include it for the user's
@@ -295,7 +300,11 @@ bindistRules = do
             let suffix = if useGhcPrefix pkg
                            then "ghc-" ++ version
                            else version
-            wrapper_content <- wrapper wrapper_name
+            let withoutPrefix p s = fromMaybe s (stripPrefix p s)
+            -- I guess the wrapper names match the binary normally, except
+            -- when cross-compiling, the binary names are prefixed with the
+            -- target platform triple.
+            wrapper_content <- wrapper (withoutPrefix (targetPlatform <> "-") 
wrapper_name)
             let unversioned_wrapper_path = bindistFilesDir -/- "wrappers" -/- 
wrapper_name
                 versioned_wrapper = wrapper_name ++ "-" ++ suffix
                 versioned_wrapper_path = bindistFilesDir -/- "wrappers" -/- 
versioned_wrapper

Cheers,
Habib

Reply via email to