snowleopard / hadrian

Hadrian: a new build system for the Glasgow Haskell Compiler. Now merged into the GHC tree!
https://gitlab.haskell.org/ghc/ghc/tree/master/hadrian
MIT License
208 stars 37 forks source link

ld: library not found for -lCffi #89

Closed angerman closed 8 years ago

angerman commented 8 years ago

Assuming #86 is fixed (e.g. with ln -s build stage1 in rts), I end up with

/----------
| Run Ghc Stage1 (package = hpc-bin)
|     input: utils/hpc/stage1/build/Main.o (and 11 more)
| => output: utils/hpc/stage1/build/tmp/hpc-bin
\----------
ld: library not found for -lCffi
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`clang' failed in phase `Linker'. (Exit code: 1)
shakeArgsWith         0.000s    0%                           
Function shake        0.020s    0%                           
Database read         0.349s    3%                           
Database compression  0.111s    0%                           
With database         0.013s    0%                           
Running rules        10.912s   95%  =========================
Total                11.405s  100%                           
Error when running Shake build system:
* utils/hpc/stage1/build/tmp/hpc-bin
user error (Development.Shake.cmd, system command failed
Command: inplace/bin/ghc-stage1 -hisuf hi -osuf o -hcsuf hc -static -hide-all-packages -no-user-package-db -package-id array-0.5.1.0 -package-id base-4.9.0.0 -package-id containers-0.5.7.1 -package-id directory-1.2.5.0 -package-id filepath-1.4.1.0 -package-id hpc-0.6.0.2 -i -iutils/hpc/stage1/build -iutils/hpc/stage1/build/autogen -iutils/hpc -Iutils/hpc/stage1/build -Iutils/hpc/stage1/build/autogen -I/Users/angerman/Projects/Haskell/ghc/libraries/directory/include -I/Users/angerman/Projects/Haskell/ghc/libraries/unix/include -I/Users/angerman/Projects/Haskell/ghc/libraries/time/lib/include -I/Users/angerman/Projects/Haskell/ghc/libraries/containers/include -I/Users/angerman/Projects/Haskell/ghc/libraries/bytestring/include -I/Users/angerman/Projects/Haskell/ghc/libraries/base/include -I/Users/angerman/Projects/Haskell/ghc/libraries/integer-gmp/include -I/Users/angerman/Projects/Haskell/ghc/rts/dist/build -I/Users/angerman/Projects/Haskell/ghc/includes -I/Users/angerman/Projects/Haskell/ghc/includes/dist-derivedconstants/header -optP-include -optPutils/hpc/stage1/build/autogen/cabal_macros.h -XHaskell2010 -odir utils/hpc/stage1/build -hidir utils/hpc/stage1/build -stubdir utils/hpc/stage1/build -rtsopts -H32m -O2 -Wall -fwarn-tabs -no-auto-link-packages -optl-liconv -optl-lm -optl-ldl -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/hpc/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/directory/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/unix/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/time/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/filepath/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/containers/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/bytestring/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/deepseq/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/array/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/base/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/integer-gmp/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/libraries/ghc-prim/stage1/build -optl-L/Users/angerman/Projects/Haskell/ghc/rts/dist/build utils/hpc/stage1/build/Main.o utils/hpc/stage1/build/HpcParser.o utils/hpc/stage1/build/HpcCombine.o utils/hpc/stage1/build/HpcDraft.o utils/hpc/stage1/build/HpcFlags.o utils/hpc/stage1/build/HpcLexer.o utils/hpc/stage1/build/HpcMarkup.o utils/hpc/stage1/build/HpcOverlay.o utils/hpc/stage1/build/HpcReport.o utils/hpc/stage1/build/HpcShowTix.o utils/hpc/stage1/build/HpcUtils.o utils/hpc/stage1/build/Paths_hpc_bin.o -o utils/hpc/stage1/build/tmp/hpc-bin
Exit code: 1
Stderr:
ld: library not found for -lCffi
clang: error: linker command failed with exit code 1 (use -v to see invocation)
`clang' failed in phase `Linker'. (Exit code: 1)
)

on os x.

angerman commented 8 years ago

With make I end up with

./rts/dist/build/libCffi.a
./rts/dist/build/libCffi_debug.a
./rts/dist/build/libCffi_l.a
./rts/dist/build/libCffi_thr.a
./rts/dist/build/libCffi_thr_debug.a
./rts/dist/build/libCffi_thr_l.a

The shake build system so far does not produce these.

angerman commented 8 years ago

From the make build log:

      Must remake target `rts/dist/build/AutoApply.o'.
"inplace/bin/ghc-stage1" -static  -O0 -H64m -Wall  -Iincludes -Iincludes/dist -Iincludes/dist-derivedconstants/header -Iincludes/dist-ghcconstants/header -Irts -Irts/dist/build -DCOMPILING_RTS -this-package-key rts -dcmm-lint  -DDTRACE     -i -irts -irts/dist/build -irts/dist/build/autogen -Irts/dist/build -Irts/dist/build/autogen           -O2     -c rts/dist/build/Auto
Apply.cmm -o rts/dist/build/AutoApply.o
      Successfully remade target file `rts/dist/build/AutoApply.o'.
       File `rts/dist/build/libCffi.a' does not exist.
      Must remake target `rts/dist/build/libCffi.a'.
cp libffi/build/inst/lib/libffi.a rts/dist/build/libCffi.a
      Successfully remade target file `rts/dist/build/libCffi.a'.
    Must remake target `rts/dist/build/libHSrts.a'.
"rm" -f rts/dist/build/libHSrts.a
echo rts/dist/build/Adjustor.o rts/dist/build/Arena.o rts/dist/build/Capability.o rts/dist/build/CheckUnload.o rts/dist/build/ClosureFlags.o rts/dist/build/Disassembler.o rts/dist/build/FileLock.o rts/dist/build/Globals.o rts/dist/build/Hash.o rts/dist/build/Hpc.o rts/dist/build/HsFFI.o rts/dist/build/Inlines.o rts/dist/build/Interpreter.o rts/dist/build/LdvProfile.o rts/dist/build/Libdw.o rts/dist/build/LibdwPool.o rts/dist/build/Linker.o rts/dist/build/Messages.o rts/dist/build/OldARMAtomic.o rts/dist/build/Pool.o rts/dist/build/Printer.o rts/dist/build/ProfHeap.o rts/dist/build/Profiling.o rts/dist/build/Proftimer.o rts/dist/build/RaiseAsync.o rts/dist/build/RetainerProfile.o rts/dist/build/RetainerSet.o rts/dist/build/RtsAPI.o rts/dist/build/RtsDllMain.o rts/dist/build/RtsFlags.o rts/dist/build/RtsMain.o rts/dist/build/RtsMessages.o rts/dist/build/RtsStartup.o rts/dist/build/RtsSymbols.o rts/dist/build/RtsUtils.o rts/dist/build/STM.o rts/dist/build/Schedule.o rts/dist/build/Sparks.o rts/dist/build/Stable.o rts/dist/build/StaticPtrTable.o rts/dist/build/Stats.o rts/dist/build/StgCRun.o rts/dist/build/StgPrimFloat.o rts/dist/build/Task.o rts/dist/build/ThreadLabels.o rts/dist/build/ThreadPaused.o rts/dist/build/Threads.o rts/dist/build/Ticky.o rts/dist/build/Timer.o rts/dist/build/Trace.o rts/dist/build/WSDeque.o rts/dist/build/Weak.o rts/dist/build/hooks/FlagDefaults.o rts/dist/build/hooks/MallocFail.o rts/dist/build/hooks/OnExit.o rts/dist/build/hooks/OutOfHeap.o rts/dist/build/hooks/StackOverflow.o rts/dist/build/sm/BlockAlloc.o rts/dist/build/sm/Compact.o rts/dist/build/sm/Evac.o rts/dist/build/sm/GC.o rts/dist/build/sm/GCAux.o rts/dist/build/sm/GCUtils.o rts/dist/build/sm/MBlock.o rts/dist/build/sm/MarkWeak.o rts/dist/build/sm/Sanity.o rts/dist/build/sm/Scav.o rts/dist/build/sm/Storage.o rts/dist/build/sm/Sweep.o rts/dist/build/eventlog/EventLog.o rts/dist/build/posix/GetEnv.o rts/dist/build/posix/GetTime.o rts/dist/build/posix/Itimer.o rts/dist/build/posix/OSMem.o rts/dist/build/posix/OSThreads.o rts/dist/build/posix/Select.o rts/dist/build/posix/Signals.o rts/dist/build/posix/TTY.o   rts/dist/build/Apply.o rts/dist/build/Exception.o rts/dist/build/HeapStackCheck.o rts/dist/build/PrimOps.o rts/dist/build/StgMiscClosures.o rts/dist/build/StgStartup.o rts/dist/build/StgStdThunks.o rts/dist/build/Updates.o rts/dist/build/AutoApply.o  | "xargs"  "/usr/bin/ar" clqs  rts/dist/build/libHSrts.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/dist/build/libHSrts.a(Disassembler.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/dist/build/libHSrts.a(LdvProfile.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/dist/build/libHSrts.a(OldARMAtomic.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/dist/build/libHSrts.a(Profiling.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/dist/build/libHSrts.a(RetainerProfile.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/dist/build/libHSrts.a(RetainerSet.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/dist/build/libHSrts.a(RtsDllMain.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/dist/build/libHSrts.a(Sanity.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: rts/dist/build/libHSrts.a(EventLog.o) has no symbols
    Successfully remade target file `rts/dist/build/libHSrts.a'.
angerman commented 8 years ago

Weirdly enough, the code that is supposed to do this, actually exists at https://github.com/snowleopard/shaking-up-ghc/blob/master/src/Settings/Packages/Rts.hs#L73-L77.

angerman commented 8 years ago

Upon further investigation, I fail to see where rts is built with HsCpp, to actually produce the libffi libs.

snowleopard commented 8 years ago

HsCpp is not responsible for building libCffi.a. It is used to create rts package configuration file.

We simply need to replicate the following step in the new build system:

cp libffi/build/inst/lib/libffi.a rts/dist/build/libCffi.a
angerman commented 8 years ago

Hmm, ok. I really need to understand the build system better.

angerman commented 8 years ago

I'll try to copy step by hand and see how far I get.

snowleopard commented 8 years ago

Great. Please make use of the new copyFile function. I guess the command will look something like this after renaming dist to stage1:

copyFile "libffi/build/inst/lib/libffi.a" "rts/stage1/build/libCffi.a"
snowleopard commented 8 years ago

I guess the above fix wasn't enough. I am now hit by the same issue.

Let me reopen this. I think we are missing a need somewhere.

snowleopard commented 8 years ago

The issue was that on Windows we have to use libCffi-6.a instead of libCffi.a. I have no idea why.