rules_haskell icon indicating copy to clipboard operation
rules_haskell copied to clipboard

Cannot build a binary using c2hs

Open Lugendre opened this issue 3 years ago • 13 comments

I tried to build mpi-hs's binary using bazel and rules_haskell, but I got the following error and failed to build the haskell_binary.

Starting local Bazel server and connecting to it...
INFO: Analyzed 10 targets (36 packages loaded, 1000 targets configured).
INFO: Found 10 targets...
ERROR: /path/to/mpi-hs/BUILD.bazel:59:15: HaskellLinkBinary mpi-hs-version failed (Exit 1) ghc_wrapper failed: error executing command bazel-out/host/bin/external/rules_haskell/haskell/ghc_wrapper bazel-out/k8-fastbuild/bin/compile_flags_mpi-hs-version_HaskellLinkBinary ... (remaining 1 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0xd9b0): error: undefined reference to 'MPI_Wtime'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0xdb70): error: undefined reference to 'MPI_Wtick'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0xdd98): error: undefined reference to 'MPI_Finalize'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0xe220): error: undefined reference to 'mpihs_get_status_ignore'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0xe6bc): error: undefined reference to 'mpihs_get_request_null'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0xeaf0): error: undefined reference to 'MPI_Wait'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0xf180): error: undefined reference to 'MPI_Wait'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0xf724): error: undefined reference to 'mpihs_get_op_null'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0xfc04): error: undefined reference to 'mpihs_get_band'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x100e4): error: undefined reference to 'mpihs_get_bor'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x105c4): error: undefined reference to 'mpihs_get_bxor'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x10aa4): error: undefined reference to 'mpihs_get_land'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x10f84): error: undefined reference to 'mpihs_get_lor'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x11464): error: undefined reference to 'mpihs_get_lxor'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x11944): error: undefined reference to 'mpihs_get_max'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x11e24): error: undefined reference to 'mpihs_get_maxloc'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x12304): error: undefined reference to 'mpihs_get_min'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x127e4): error: undefined reference to 'mpihs_get_minloc'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x12cc4): error: undefined reference to 'mpihs_get_prod'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x131a4): error: undefined reference to 'mpihs_get_sum'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x137ac): error: undefined reference to 'mpihs_get_datatype_null'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x13c8c): error: undefined reference to 'mpihs_get_byte'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1434c): error: undefined reference to 'mpihs_get_char'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1482c): error: undefined reference to 'mpihs_get_double'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x14d0c): error: undefined reference to 'mpihs_get_float'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x151ec): error: undefined reference to 'mpihs_get_int'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x156cc): error: undefined reference to 'mpihs_get_long'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x15bac): error: undefined reference to 'mpihs_get_long_double'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1608c): error: undefined reference to 'mpihs_get_long_long'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1656c): error: undefined reference to 'mpihs_get_long_long_int'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x16a4c): error: undefined reference to 'mpihs_get_short'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x16f2c): error: undefined reference to 'mpihs_get_unsigned'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1740c): error: undefined reference to 'mpihs_get_unsigned_char'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x178ec): error: undefined reference to 'mpihs_get_unsigned_long'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x17dcc): error: undefined reference to 'mpihs_get_unsigned_long_long'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x182ac): error: undefined reference to 'mpihs_get_unsigned_short'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x187d0): error: undefined reference to 'mpihs_get_undefined'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x18c0c): error: undefined reference to 'mpihs_get_comm_null'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x190ec): error: undefined reference to 'mpihs_get_comm_self'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x195cc): error: undefined reference to 'mpihs_get_comm_world'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x19b58): error: undefined reference to '__c2hs_wrapped__MPI_Abort'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1a34c): error: undefined reference to '__c2hs_wrapped__MPI_Allgather'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1b240): error: undefined reference to '__c2hs_wrapped__MPI_Allreduce'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1c21c): error: undefined reference to '__c2hs_wrapped__MPI_Alltoall'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1cc34): error: undefined reference to '__c2hs_wrapped__MPI_Barrier'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1d578): error: undefined reference to '__c2hs_wrapped__MPI_Exscan'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1e630): error: undefined reference to '__c2hs_wrapped__MPI_Iallgather'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1f764): error: undefined reference to '__c2hs_wrapped__MPI_Iallreduce'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x20978): error: undefined reference to '__c2hs_wrapped__MPI_Ialltoall'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x215d0): error: undefined reference to '__c2hs_wrapped__MPI_Ibarrier'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2210c): error: undefined reference to '__c2hs_wrapped__MPI_Iexscan'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x234dc): error: undefined reference to '__c2hs_wrapped__MPI_Iscan'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x247d0): error: undefined reference to '__c2hs_wrapped__MPI_Scan'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x25584): error: undefined reference to '__c2hs_wrapped__MPI_Get_elements'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x25db8): error: undefined reference to 'MPI_Get_library_version'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x266b8): error: undefined reference to 'MPI_Get_processor_name'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x270a0): error: undefined reference to 'MPI_Get_version'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x277e8): error: undefined reference to '__c2hs_wrapped__MPI_Comm_rank'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x27e60): error: undefined reference to '__c2hs_wrapped__MPI_Comm_size'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x284dc): error: undefined reference to '__c2hs_wrapped__MPI_Get_count'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x28b6c): error: undefined reference to 'MPI_Finalized'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2910c): error: undefined reference to 'MPI_Initialized'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x29504): error: undefined reference to 'MPI_Request_get_status'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x29e54): error: undefined reference to 'MPI_Request_get_status'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2a44c): error: undefined reference to 'MPI_Test'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2ae34): error: undefined reference to 'MPI_Test'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2b57c): error: undefined reference to '__c2hs_wrapped__MPI_Comm_compare'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2bcec): error: undefined reference to '__c2hs_wrapped__MPI_Bcast'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2c7e0): error: undefined reference to '__c2hs_wrapped__MPI_Gather'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2d578): error: undefined reference to '__c2hs_wrapped__MPI_Ibcast'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2e28c): error: undefined reference to '__c2hs_wrapped__MPI_Igather'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2f4b0): error: undefined reference to '__c2hs_wrapped__MPI_Ireduce'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x307cc): error: undefined reference to '__c2hs_wrapped__MPI_Iscatter'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x31914): error: undefined reference to '__c2hs_wrapped__MPI_Reduce'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x329f0): error: undefined reference to '__c2hs_wrapped__MPI_Scatter'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x3350c): error: undefined reference to 'MPI_Iprobe'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x33da4): error: undefined reference to 'MPI_Iprobe'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x34764): error: undefined reference to '__c2hs_wrapped__MPI_Irecv'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x353f4): error: undefined reference to '__c2hs_wrapped__MPI_Isend'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x35d28): error: undefined reference to '__c2hs_wrapped__MPI_Probe'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x36578): error: undefined reference to '__c2hs_wrapped__MPI_Probe'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x36d14): error: undefined reference to '__c2hs_wrapped__MPI_Recv'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x379fc): error: undefined reference to '__c2hs_wrapped__MPI_Recv'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x38548): error: undefined reference to '__c2hs_wrapped__MPI_Send'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x39122): error: undefined reference to '__c2hs_wrapped__MPI_Sendrecv'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x3a672): error: undefined reference to '__c2hs_wrapped__MPI_Sendrecv'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x3b560): error: undefined reference to 'mpihs_get_any_source'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x3b938): error: undefined reference to 'mpihs_get_any_tag'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x3bd98): error: undefined reference to 'MPI_Init'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x3c798): error: undefined reference to 'MPI_Init_thread'
collect2: error: ld returned 1 exit status
`cc_wrapper-python' failed in phase `Linker'. (Exit code: 1)
INFO: Elapsed time: 24.467s, Critical Path: 7.06s
INFO: 20 processes: 20 linux-sandbox.
FAILED: Build did NOT complete successfully

On the other hand, I can build the library using haskell_library.

I don't have much knowledge of rules_haskell, so I'm struggling with this debugging. I need your wisdom.

Here are the commits I'm actually using for validation.

Lugendre avatar Sep 17 '20 14:09 Lugendre

@Lugendre are you using GHC 8.10? The errors look similiar to #1413 and issues linked therein.

mboes avatar Sep 20 '20 21:09 mboes

Hm, from your WORKSPACE file looks like you're using 8.8.3.

mboes avatar Sep 20 '20 21:09 mboes

@mboes I'm using GHC 8.8.3. I read #1413, #593 and #1388. I tried rules_haskell 0.13 with #1388 merged into it, and I get the same error. I think it's probably due to a misconfiguration of the directory associated with c2hs, but I can't debug it because of my lack of knowledge of bazel. I forgot to write this, I'm using NixOS 20.03.

Lugendre avatar Sep 21 '20 11:09 Lugendre

@mboes Is there any update on this? I'm also suffering from this issue (spoiler: I and @Lugendre are working at the same team).

konn avatar Sep 28 '20 01:09 konn

To look into this, I made some changes to rules_haskell to be able to see what commands are being run: https://github.com/tweag/rules_haskell/compare/master...Infinisil:command-logging

With this, the output is:

$ bazel build //:mpi-hs-version --override_repository=rules_haskell=/home/infinisil/src/rules_haskell
INFO: Analyzed target //:mpi-hs-version (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /home/infinisil/src/mpi-hs/BUILD.bazel:62:15: HaskellLinkBinary mpi-hs-version failed (Exit 1) ghc_wrapper failed: error executing command bazel-out/host/bin/external/rules_haskell/haskell/ghc_wrapper bazel-out/k8-fastbuild/bin/compile_flags_mpi-hs-version_HaskellLinkBinary ... (remaining 1 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
Action is compile
Executing cc command: /nix/store/mimzy2k99xq842k59zl3f2z2s34rcq5b-gcc-wrapper-9.3.0/bin/gcc -c /run/user/1000/ghc3_0/ghc_1.c -o /run/user/1000/ghc3_0/ghc_2.o -fno-PIC -I/nix/store/4wb6bw5xm3zrwb3qblfxapl416s4mqb8-ghc-8.8.3/lib/ghc-8.8.3/include -I/nix/store/aq3qysymn2kybi24p98ph5sc6q9jns3h-libffi-3.3-dev/include -fno-stack-protector -Wno-unused-command-line-argument

Action is compile
Executing cc command: /nix/store/mimzy2k99xq842k59zl3f2z2s34rcq5b-gcc-wrapper-9.3.0/bin/gcc -c /run/user/1000/ghc3_0/ghc_4.s -o /run/user/1000/ghc3_0/ghc_5.o -fno-stack-protector -Wno-unused-command-line-argument

Action is link
Executing cc command: /nix/store/mimzy2k99xq842k59zl3f2z2s34rcq5b-gcc-wrapper-9.3.0/bin/gcc -Wl,--no-as-needed -fuse-ld=gold -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/nix/store/mimzy2k99xq842k59zl3f2z2s34rcq5b-gcc-wrapper-9.3.0/bin -pass-exit-codes -lstdc++ -lm -no-pie -pthread -Wno-unused-command-line-argument -o bazel-out/k8-fastbuild/bin/mpi-hs-version -lm -fno-PIC -Wl,--gc-sections bazel-out/k8-fastbuild/bin/_obj/mpi-hs-version/Main.o -Lbazel-out/k8-fastbuild/bin -Lbazel-out/k8-fastbuild/bin/external/stackage/monad-loops-0.4.3/_install/lib -L/nix/store/4wb6bw5xm3zrwb3qblfxapl416s4mqb8-ghc-8.8.3/lib/ghc-8.8.3/bytestring-0.10.10.0 -L/nix/store/4wb6bw5xm3zrwb3qblfxapl416s4mqb8-ghc-8.8.3/lib/ghc-8.8.3/deepseq-1.4.4.0 -L/nix/store/4wb6bw5xm3zrwb3qblfxapl416s4mqb8-ghc-8.8.3/lib/ghc-8.8.3/array-0.5.4.0 -Lbazel-out/k8-fastbuild/bin/_solib_k8/_U_S_S_Copenmpi.h___Uexternal_Sopenmpi_Slib -Lbazel-out/k8-fastbuild/bin/_solib_k8/_U_S_S_Copenmpi.h___Uexternal_Sopenmpi_Slib_Sopenmpi -L/nix/store/4wb6bw5xm3zrwb3qblfxapl416s4mqb8-ghc-8.8.3/lib/ghc-8.8.3/base-4.13.0.0 -L/nix/store/4wb6bw5xm3zrwb3qblfxapl416s4mqb8-ghc-8.8.3/lib/ghc-8.8.3/integer-gmp-1.0.2.0 -L/nix/store/qn23d3c7ai96qp6grqfc8fk9dlrvk966-gmp-6.2.0/lib -L/nix/store/4wb6bw5xm3zrwb3qblfxapl416s4mqb8-ghc-8.8.3/lib/ghc-8.8.3/ghc-prim-0.5.3 -L/nix/store/4wb6bw5xm3zrwb3qblfxapl416s4mqb8-ghc-8.8.3/lib/ghc-8.8.3/rts -L/nix/store/jdybsxhflqabf2zsnhdjmlzfxchssp8j-libffi-3.3/lib /run/user/1000/ghc3_0/ghc_2.o /run/user/1000/ghc3_0/ghc_5.o -Wl,-u,base_GHCziTopHandler_runIO_closure -Wl,-u,base_GHCziTopHandler_runNonIO_closure -Wl,-u,ghczmprim_GHCziTuple_Z0T_closure -Wl,-u,ghczmprim_GHCziTypes_True_closure -Wl,-u,ghczmprim_GHCziTypes_False_closure -Wl,-u,base_GHCziPack_unpackCString_closure -Wl,-u,base_GHCziWeak_runFinalizzerBatch_closure -Wl,-u,base_GHCziIOziException_stackOverflow_closure -Wl,-u,base_GHCziIOziException_heapOverflow_closure -Wl,-u,base_GHCziIOziException_allocationLimitExceeded_closure -Wl,-u,base_GHCziIOziException_blockedIndefinitelyOnMVar_closure -Wl,-u,base_GHCziIOziException_blockedIndefinitelyOnSTM_closure -Wl,-u,base_GHCziIOziException_cannotCompactFunction_closure -Wl,-u,base_GHCziIOziException_cannotCompactPinned_closure -Wl,-u,base_GHCziIOziException_cannotCompactMutable_closure -Wl,-u,base_ControlziExceptionziBase_absentSumFieldError_closure -Wl,-u,base_ControlziExceptionziBase_nonTermination_closure -Wl,-u,base_ControlziExceptionziBase_nestedAtomically_closure -Wl,-u,base_GHCziEventziThread_blockedOnBadFD_closure -Wl,-u,base_GHCziConcziSync_runSparks_closure -Wl,-u,base_GHCziConcziIO_ensureIOManagerIsRunning_closure -Wl,-u,base_GHCziConcziIO_ioManagerCapabilitiesChanged_closure -Wl,-u,base_GHCziConcziSignal_runHandlersPtr_closure -Wl,-u,base_GHCziTopHandler_flushStdHandles_closure -Wl,-u,base_GHCziTopHandler_runMainIO_closure -Wl,-u,ghczmprim_GHCziTypes_Czh_con_info -Wl,-u,ghczmprim_GHCziTypes_Izh_con_info -Wl,-u,ghczmprim_GHCziTypes_Fzh_con_info -Wl,-u,ghczmprim_GHCziTypes_Dzh_con_info -Wl,-u,ghczmprim_GHCziTypes_Wzh_con_info -Wl,-u,base_GHCziPtr_Ptr_con_info -Wl,-u,base_GHCziPtr_FunPtr_con_info -Wl,-u,base_GHCziInt_I8zh_con_info -Wl,-u,base_GHCziInt_I16zh_con_info -Wl,-u,base_GHCziInt_I32zh_con_info -Wl,-u,base_GHCziInt_I64zh_con_info -Wl,-u,base_GHCziWord_W8zh_con_info -Wl,-u,base_GHCziWord_W16zh_con_info -Wl,-u,base_GHCziWord_W32zh_con_info -Wl,-u,base_GHCziWord_W64zh_con_info -Wl,-u,base_GHCziStable_StablePtr_con_info -Wl,-u,hs_atomic_add8 -Wl,-u,hs_atomic_add16 -Wl,-u,hs_atomic_add32 -Wl,-u,hs_atomic_add64 -Wl,-u,hs_atomic_sub8 -Wl,-u,hs_atomic_sub16 -Wl,-u,hs_atomic_sub32 -Wl,-u,hs_atomic_sub64 -Wl,-u,hs_atomic_and8 -Wl,-u,hs_atomic_and16 -Wl,-u,hs_atomic_and32 -Wl,-u,hs_atomic_and64 -Wl,-u,hs_atomic_nand8 -Wl,-u,hs_atomic_nand16 -Wl,-u,hs_atomic_nand32 -Wl,-u,hs_atomic_nand64 -Wl,-u,hs_atomic_or8 -Wl,-u,hs_atomic_or16 -Wl,-u,hs_atomic_or32 -Wl,-u,hs_atomic_or64 -Wl,-u,hs_atomic_xor8 -Wl,-u,hs_atomic_xor16 -Wl,-u,hs_atomic_xor32 -Wl,-u,hs_atomic_xor64 -Wl,-u,hs_cmpxchg8 -Wl,-u,hs_cmpxchg16 -Wl,-u,hs_cmpxchg32 -Wl,-u,hs_cmpxchg64 -Wl,-u,hs_atomicread8 -Wl,-u,hs_atomicread16 -Wl,-u,hs_atomicread32 -Wl,-u,hs_atomicread64 -Wl,-u,hs_atomicwrite8 -Wl,-u,hs_atomicwrite16 -Wl,-u,hs_atomicwrite32 -Wl,-u,hs_atomicwrite64 -lHSmpi-hs -lHSmonad-loops-0.4.3 -lHSbytestring-0.10.10.0 -lHSdeepseq-1.4.4.0 -lHSarray-0.5.4.0 -lHSbase-4.13.0.0 -lHSinteger-gmp-1.0.2.0 -lHSghc-prim-0.5.3 -lHSrts -lmpi -lmpi -lmpi -lmpi_cxx -lmpi_cxx -lmpi_cxx -lmpi_mpifh -lmpi_mpifh -lmpi_mpifh -lmpi_usempi_ignore_tkr -lmpi_usempi_ignore_tkr -lmpi_usempi_ignore_tkr -lmpi_usempif08 -lmpi_usempif08 -lmpi_usempif08 -lompitrace -lompitrace -lompitrace -lopen-pal -lopen-pal -lopen-pal -lopen-rte -lopen-rte -lopen-rte -loshmem -loshmem -loshmem -lompi_dbg_msgq -lgmp -lm -lrt -ldl -lffi -lpthread -Xlinker -rpath -Xlinker $ORIGIN/_solib_k8/_U_S_S_Copenmpi.h___Uexternal_Sopenmpi_Slib -Xlinker -rpath -Xlinker $ORIGIN/_solib_k8/_U_S_S_Copenmpi.h___Uexternal_Sopenmpi_Slib_Sopenmpi

bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0xe220): error: undefined reference to 'mpihs_get_status_ignore'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0xe6bc): error: undefined reference to 'mpihs_get_request_null'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0xf724): error: undefined reference to 'mpihs_get_op_null'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0xfc04): error: undefined reference to 'mpihs_get_band'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x100e4): error: undefined reference to 'mpihs_get_bor'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x105c4): error: undefined reference to 'mpihs_get_bxor'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x10aa4): error: undefined reference to 'mpihs_get_land'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x10f84): error: undefined reference to 'mpihs_get_lor'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x11464): error: undefined reference to 'mpihs_get_lxor'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x11944): error: undefined reference to 'mpihs_get_max'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x11e24): error: undefined reference to 'mpihs_get_maxloc'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x12304): error: undefined reference to 'mpihs_get_min'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x127e4): error: undefined reference to 'mpihs_get_minloc'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x12cc4): error: undefined reference to 'mpihs_get_prod'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x131a4): error: undefined reference to 'mpihs_get_sum'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x137ac): error: undefined reference to 'mpihs_get_datatype_null'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x13c8c): error: undefined reference to 'mpihs_get_byte'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1434c): error: undefined reference to 'mpihs_get_char'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1482c): error: undefined reference to 'mpihs_get_double'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x14d0c): error: undefined reference to 'mpihs_get_float'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x151ec): error: undefined reference to 'mpihs_get_int'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x156cc): error: undefined reference to 'mpihs_get_long'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x15bac): error: undefined reference to 'mpihs_get_long_double'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1608c): error: undefined reference to 'mpihs_get_long_long'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1656c): error: undefined reference to 'mpihs_get_long_long_int'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x16a4c): error: undefined reference to 'mpihs_get_short'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x16f2c): error: undefined reference to 'mpihs_get_unsigned'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1740c): error: undefined reference to 'mpihs_get_unsigned_char'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x178ec): error: undefined reference to 'mpihs_get_unsigned_long'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x17dcc): error: undefined reference to 'mpihs_get_unsigned_long_long'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x182ac): error: undefined reference to 'mpihs_get_unsigned_short'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x187d0): error: undefined reference to 'mpihs_get_undefined'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x18c0c): error: undefined reference to 'mpihs_get_comm_null'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x190ec): error: undefined reference to 'mpihs_get_comm_self'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x195cc): error: undefined reference to 'mpihs_get_comm_world'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x19b58): error: undefined reference to '__c2hs_wrapped__MPI_Abort'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1a34c): error: undefined reference to '__c2hs_wrapped__MPI_Allgather'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1b240): error: undefined reference to '__c2hs_wrapped__MPI_Allreduce'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1c21c): error: undefined reference to '__c2hs_wrapped__MPI_Alltoall'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1cc34): error: undefined reference to '__c2hs_wrapped__MPI_Barrier'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1d578): error: undefined reference to '__c2hs_wrapped__MPI_Exscan'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1e630): error: undefined reference to '__c2hs_wrapped__MPI_Iallgather'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1f764): error: undefined reference to '__c2hs_wrapped__MPI_Iallreduce'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x20978): error: undefined reference to '__c2hs_wrapped__MPI_Ialltoall'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x215d0): error: undefined reference to '__c2hs_wrapped__MPI_Ibarrier'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2210c): error: undefined reference to '__c2hs_wrapped__MPI_Iexscan'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x234dc): error: undefined reference to '__c2hs_wrapped__MPI_Iscan'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x247d0): error: undefined reference to '__c2hs_wrapped__MPI_Scan'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x25584): error: undefined reference to '__c2hs_wrapped__MPI_Get_elements'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x277e8): error: undefined reference to '__c2hs_wrapped__MPI_Comm_rank'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x27e60): error: undefined reference to '__c2hs_wrapped__MPI_Comm_size'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x284dc): error: undefined reference to '__c2hs_wrapped__MPI_Get_count'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2b57c): error: undefined reference to '__c2hs_wrapped__MPI_Comm_compare'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2bcec): error: undefined reference to '__c2hs_wrapped__MPI_Bcast'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2c7e0): error: undefined reference to '__c2hs_wrapped__MPI_Gather'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2d578): error: undefined reference to '__c2hs_wrapped__MPI_Ibcast'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2e28c): error: undefined reference to '__c2hs_wrapped__MPI_Igather'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2f4b0): error: undefined reference to '__c2hs_wrapped__MPI_Ireduce'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x307cc): error: undefined reference to '__c2hs_wrapped__MPI_Iscatter'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x31914): error: undefined reference to '__c2hs_wrapped__MPI_Reduce'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x329f0): error: undefined reference to '__c2hs_wrapped__MPI_Scatter'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x34764): error: undefined reference to '__c2hs_wrapped__MPI_Irecv'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x353f4): error: undefined reference to '__c2hs_wrapped__MPI_Isend'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x35d28): error: undefined reference to '__c2hs_wrapped__MPI_Probe'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x36578): error: undefined reference to '__c2hs_wrapped__MPI_Probe'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x36d14): error: undefined reference to '__c2hs_wrapped__MPI_Recv'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x379fc): error: undefined reference to '__c2hs_wrapped__MPI_Recv'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x38548): error: undefined reference to '__c2hs_wrapped__MPI_Send'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x39122): error: undefined reference to '__c2hs_wrapped__MPI_Sendrecv'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x3a672): error: undefined reference to '__c2hs_wrapped__MPI_Sendrecv'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x3b560): error: undefined reference to 'mpihs_get_any_source'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x3b938): error: undefined reference to 'mpihs_get_any_tag'
collect2: error: ld returned 1 exit status
`cc_wrapper-python' failed in phase `Linker'. (Exit code: 1)
Executing ghc command: external/rules_haskell_ghc_nixpkgs/bin/ghc -pgma bazel-out/host/bin/external/rules_haskell/haskell/cc_wrapper-python -pgmc bazel-out/host/bin/external/rules_haskell/haskell/cc_wrapper-python -pgml bazel-out/host/bin/external/rules_haskell/haskell/cc_wrapper-python -pgmP bazel-out/host/bin/external/rules_haskell/haskell/cc_wrapper-python -E -undef -traditional -optc-fno-stack-protector -optl-fuse-ld=gold -optl-Wl,-no-as-needed -optl-Wl,-z,relro,-z,now -optl-B/nix/store/mimzy2k99xq842k59zl3f2z2s34rcq5b-gcc-wrapper-9.3.0/bin -optl-pass-exit-codes -optl-lstdc++ -optl-lm -optl-no-pie -optl-pthread -o bazel-out/k8-fastbuild/bin/mpi-hs-version -hide-all-packages -package-env bazel-out/k8-fastbuild/bin/link-package_env-mpi-hs-version -package-db bazel-out/k8-fastbuild/bin/link-config-mpi-hs-version -package link-config-mpi-hs-version -optc-Wno-unused-command-line-argument -optl-Wno-unused-command-line-argument bazel-out/k8-fastbuild/bin/_obj/mpi-hs-version/Main.o

Target //:mpi-hs-version failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.120s, Critical Path: 0.98s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

(Note that there's a lot of arguments to the right). Haven't yet been able to figure anything out with this though.

And just to test whether c2hs binaries work at all, I extended the c2hs test with a binary build: https://github.com/tweag/rules_haskell/compare/master...Infinisil:c2hs-binary-test

But that seems to build and run just fine.

infinisil avatar Sep 28 '20 20:09 infinisil

@Infinisil Thank you for looking into this! One thing that stands out to me is that many of the missing symbols are defined in //:mpi-hs-c. However, that target is only a dependency of //:mpi-hs-c2hs but not //:mpi-hs. c2hs_library does not provide a CcInfo provider meaning it does not track C library dependencies (or really any kinds of dependencies). Maybe it's already enough to add //:mpi-hs-c as a dependency to //:mpi-hs.

aherrmann avatar Sep 29 '20 07:09 aherrmann

@Infinisil @aherrmann Thank you for commenting on this! I thought the same way as @aherrmann, so I added //:mpi-hs-c as a dependency to //:mpi-hs and built it (c.f. https://github.com/Lugendre/mpi-hs/commit/180452f594e0d320cb248ba3dd35e522795bfc60) , but I got the same error (this is also true for adding it to //:mpi-hs-version). I think we need some kind of workaround.

Lugendre avatar Sep 29 '20 09:09 Lugendre

The missing symbols are all about some wrapper functions generated by C2hs. I don't know in what cases C2hs generates wrapping functions, but if it does, then these wrappers end up in a .chs.c file, with a corresponding .chs.h header file. I don't believe that rules_haskell knows about this file yet, and is therefore not building a .o from it and not linking that in the final shared object.

mboes avatar Sep 29 '20 12:09 mboes

See the foreign import declarations in the output of C2hs for a manifestation of these wrapper functions: http://hackage.haskell.org/package/mpi-hs-0.5.1.2/docs/src/Control.Distributed.MPI.html.

mboes avatar Sep 29 '20 12:09 mboes

Thanks to the @aherrmann's pointer to CcInfo, I got some progress! With

diff --git a/haskell/c2hs.bzl b/haskell/c2hs.bzl
index b47fdf6a..ece33b15 100644
--- a/haskell/c2hs.bzl
+++ b/haskell/c2hs.bzl
@@ -113,6 +113,9 @@ def _c2hs_library_impl(ctx):
             chi_file = chi_file,
             import_dir = idir,
         ),
+        cc_common.merge_cc_infos(
+            cc_infos = [dep[CcInfo] for dep in ctx.attr.deps if CcInfo in dep],
+        ),
     ]
 
 c2hs_library = rule(

The error only shows symbols from c2hs:

bazel build //:mpi-hs-version --override_repository=rules_haskell=/home/infinisil/src/rules_haskell
INFO: Analyzed target //:mpi-hs-version (1 packages loaded, 13 targets configured).
INFO: Found 1 target...
ERROR: /home/infinisil/src/mpi-hs/BUILD.bazel:59:15: HaskellLinkBinary mpi-hs-version failed (Exit 1) ghc_wrapper failed: error executing command bazel-out/host/bin/external/rules_haskell/haskell/ghc_wrapper bazel-out/k8-fastbuild/bin/compile_flags_mpi-hs-version_HaskellLinkBinary ... (remaining 1 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x19b58): error: undefined reference to '__c2hs_wrapped__MPI_Abort'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1a34c): error: undefined reference to '__c2hs_wrapped__MPI_Allgather'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1b240): error: undefined reference to '__c2hs_wrapped__MPI_Allreduce'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1c21c): error: undefined reference to '__c2hs_wrapped__MPI_Alltoall'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1cc34): error: undefined reference to '__c2hs_wrapped__MPI_Barrier'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1d578): error: undefined reference to '__c2hs_wrapped__MPI_Exscan'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1e630): error: undefined reference to '__c2hs_wrapped__MPI_Iallgather'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x1f764): error: undefined reference to '__c2hs_wrapped__MPI_Iallreduce'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x20978): error: undefined reference to '__c2hs_wrapped__MPI_Ialltoall'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x215d0): error: undefined reference to '__c2hs_wrapped__MPI_Ibarrier'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2210c): error: undefined reference to '__c2hs_wrapped__MPI_Iexscan'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x234dc): error: undefined reference to '__c2hs_wrapped__MPI_Iscan'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x247d0): error: undefined reference to '__c2hs_wrapped__MPI_Scan'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x25584): error: undefined reference to '__c2hs_wrapped__MPI_Get_elements'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x277e8): error: undefined reference to '__c2hs_wrapped__MPI_Comm_rank'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x27e60): error: undefined reference to '__c2hs_wrapped__MPI_Comm_size'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x284dc): error: undefined reference to '__c2hs_wrapped__MPI_Get_count'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2b57c): error: undefined reference to '__c2hs_wrapped__MPI_Comm_compare'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2bcec): error: undefined reference to '__c2hs_wrapped__MPI_Bcast'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2c7e0): error: undefined reference to '__c2hs_wrapped__MPI_Gather'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2d578): error: undefined reference to '__c2hs_wrapped__MPI_Ibcast'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2e28c): error: undefined reference to '__c2hs_wrapped__MPI_Igather'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x2f4b0): error: undefined reference to '__c2hs_wrapped__MPI_Ireduce'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x307cc): error: undefined reference to '__c2hs_wrapped__MPI_Iscatter'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x31914): error: undefined reference to '__c2hs_wrapped__MPI_Reduce'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x329f0): error: undefined reference to '__c2hs_wrapped__MPI_Scatter'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x34764): error: undefined reference to '__c2hs_wrapped__MPI_Irecv'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x353f4): error: undefined reference to '__c2hs_wrapped__MPI_Isend'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x35d28): error: undefined reference to '__c2hs_wrapped__MPI_Probe'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x36578): error: undefined reference to '__c2hs_wrapped__MPI_Probe'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x36d14): error: undefined reference to '__c2hs_wrapped__MPI_Recv'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x379fc): error: undefined reference to '__c2hs_wrapped__MPI_Recv'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x38548): error: undefined reference to '__c2hs_wrapped__MPI_Send'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x39122): error: undefined reference to '__c2hs_wrapped__MPI_Sendrecv'
bazel-out/k8-fastbuild/bin/libHSmpi-hs.a(MPI.o)(.text+0x3a672): error: undefined reference to '__c2hs_wrapped__MPI_Sendrecv'
collect2: error: ld returned 1 exit status
`cc_wrapper-python' failed in phase `Linker'. (Exit code: 1)
Target //:mpi-hs-version failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.833s, Critical Path: 0.69s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

I copied that code pretty much from https://github.com/tweag/rules_haskell/blob/e8623a8c5ea502fbe6286d8ae5fb58f4915e92c5/haskell/private/haskell_impl.bzl#L564-L569. And I feel like the other errors should be resolved by also creating a new CcInfo from the c2hs invocation itself.

infinisil avatar Sep 29 '20 13:09 infinisil

Although no, I don't think my fix is correct. I think my fix links the symbols to the original openmpi library, and not the ones from c2hs. I believe the reason this gets rid of part of the warnings is that c2hs wraps all the symbols of the original library, but renames them when necessary: https://github.com/haskell/c2hs/blob/20d3c8dedde83af91c4ac06486bf346316e07285/src/C2HS/Gen/Bind.hs#L1150-L1152.

infinisil avatar Sep 29 '20 15:09 infinisil

Was able to make a minimal repro of the problem, extending the c2hs-binary-test branch from before: https://github.com/tweag/rules_haskell/compare/master...Infinisil:c2hs-binary-test

Trying to build it, the output is:

$ bazel build //tests/c2hs:c2hs-bin
WARNING: /home/infinisil/.cache/bazel/_bazel_infinisil/855dd477cdeab134dd737ac0f283327f/external/zlib.dev/BUILD:10:11: in linkstatic attribute of cc_library rule @zlib.dev//:zlib: setting 'linkstatic=1' is recommended if there are no object files. Since this rule was created by the macro 'cc_library', the error might have been caused by the macro implementation
INFO: Analyzed target //tests/c2hs:c2hs-bin (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /home/infinisil/src/rules_haskell/tests/c2hs/BUILD.bazel:55:15: HaskellLinkBinary tests/c2hs/c2hs-bin failed (Exit 1) ghc_wrapper failed: error executing command bazel-out/host/bin/haskell/ghc_wrapper bazel-out/k8-fastbuild/bin/tests/c2hs/compile_flags_c2hs-bin_HaskellLinkBinary ... (remaining 1 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
bazel-out/k8-fastbuild/bin/tests/c2hs/libHStestsZSc2hsZSc2hs.a(Code.o)(.text+0xfc): error: undefined reference to '__c2hs_wrapped__boolfun'
bazel-out/k8-fastbuild/bin/tests/c2hs/libHStestsZSc2hsZSc2hs.a(Code.o)(.text+0x47c): error: undefined reference to 'intfun'
collect2: error: ld returned 1 exit status
`cc_wrapper-python' failed in phase `Linker'. (Exit code: 1)
Target //tests/c2hs:c2hs-bin failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.762s, Critical Path: 0.70s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

Once fixed, this can be used as a test-case. I'll continue looking into it..

Edit: Updated to also test a __c2hs_wrapped case

infinisil avatar Sep 29 '20 18:09 infinisil

Unfortunately wasn't successful, but my attempt at fixing this now lives in https://github.com/tweag/rules_haskell/tree/c2hs-binary-test

infinisil avatar Oct 02 '20 16:10 infinisil