Code Monkey home page Code Monkey logo

Comments (10)

templateK avatar templateK commented on May 30, 2024 1

It works. It may not be an ideal solution but I'm ok with it for now.
If you want to close issue, I'm totally fine. Thank you for your awesome work. 👍

from emacs-module.

sergv avatar sergv commented on May 30, 2024

It's interesting that it works without the TH. I've traced it to GHC trying to load object file for the C part and failing becuse it refers to the initialise function which will provided by Haskell part when the compilation will finish. But here compilation cannot proceed further.

I have found another workaround for this: make sure ho keep all Haskell sources in the library section of the cabal file. This way GHC will not try to load object file for the C part when running TH and the C part will successfully link against initialise later on, whe dll will be produced.

I'm not sure what to do with the issue now - I'm leaving it in case someone will puzzle about it again.

from emacs-module.

templateK avatar templateK commented on May 30, 2024

@sergv I can't successfully replicate your method. here's what I did. https://github.com/templateK/emacs-modules-th-test/tree/merge-flib-into-lib Is this correct? I am surely misunderstanding your method here.

While this successfully compiles, loading into emacs fails. So I look into the dll with
objdump -t .stack-work/dist/7d103d30/build/myflib/myflib.dll and it doesn't export symbol plugin_is_GPL_compatible or emacs_module_init

from emacs-module.

sergv avatar sergv commented on May 30, 2024

@templateK It looks like your project is alright - I've built it, can load myflib.dll and call foo-string. Perhaps it's an environmental issue? I managed to build on Windows 7 using ghc 8.4.3 x64, msys2 shell and cabal-install 2.4 (2.2 is likely to work too).

I noticed that you're using stack - would you mind giving cabal-install a try? That being said, I have tried building your project with stack and at least the dll contains plugin_is_GPL_compatible and initialise:

$ stack --version
Version 1.7.1, Git revision 681c800873816c022739ca7ed14755e85a579565 (5807 commits) x86_64 hpack-0.28.2

from emacs-module.

templateK avatar templateK commented on May 30, 2024

I got no luck with merge-flib-into-lib branch whereas master branch just works.

E:\work_hask\emacs-modules-th-test>git branch
  master
* merge-flib-into-lib

E:\work_hask\emacs-modules-th-test>cabal --version
cabal-install version 2.4.0.0
compiled using version 2.4.0.0 of the Cabal library

E:\work_hask\emacs-modules-th-test>where ghc gcc ld ar nm
e:\ghc\ghc-8.4.3\bin\ghc.exe
e:\ghc\ghc-8.4.3\mingw\bin\gcc.exe
e:\ghc\ghc-8.4.3\mingw\bin\ld.exe
e:\ghc\ghc-8.4.3\mingw\x86_64-w64-mingw32\bin\ld.exe
e:\ghc\ghc-8.4.3\mingw\bin\ar.exe
e:\ghc\ghc-8.4.3\mingw\x86_64-w64-mingw32\bin\ar.exe
e:\ghc\ghc-8.4.3\mingw\bin\nm.exe
e:\ghc\ghc-8.4.3\mingw\x86_64-w64-mingw32\bin\nm.exe

E:\work_hask\emacs-modules-th-test>cabal clean
Warning: The clean command is a part of the legacy v1 style of cabal usage.

Please switch to using either the new project style and the new-clean command
or the legacy v1-clean alias as new-style projects will become the default in
the next version of cabal-install. Please file a bug if you cannot replicate a
working v1- use case with the new-style commands.

For more information, see: https://wiki.haskell.org/Cabal/NewBuild

cleaning...

E:\work_hask\emacs-modules-th-test>cabal build
Warning: The build command is a part of the legacy v1 style of cabal usage.

Please switch to using either the new project style and the new-build command
or the legacy v1-build alias as new-style projects will become the default in
the next version of cabal-install. Please file a bug if you cannot replicate a
working v1- use case with the new-style commands.

For more information, see: https://wiki.haskell.org/Cabal/NewBuild

Resolving dependencies...
Configuring emacs-module-th-test-0.1.0.0...
Preprocessing library for emacs-module-th-test-0.1.0.0..
Building library for emacs-module-th-test-0.1.0.0..
[1 of 2] Compiling Flib             ( lib\Flib.hs, dist\build\Flib.o )
[2 of 2] Compiling Lib              ( lib\Lib.hs, dist\build\Lib.o )
Preprocessing foreign library 'myflib' for emacs-module-th-test-0.1.0.0..
Building foreign library 'myflib' for emacs-module-th-test-0.1.0.0..
[1 of 1] Compiling FFlib            ( flib\FFlib.hs, dist\build\myflib\myflib-tmp\FFlib.o )
[1 of 1] Compiling FFlib            ( flib\FFlib.hs, dist\build\myflib\myflib-tmp\FFlib.o ) [flags changed]
Linking dist\build\myflib\myflib.dll ...

E:\work_hask\emacs-modules-th-test>"c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\dumpbin.exe" /EXPORTS .\dist\build\myflib\myflib.dll | findstr GPL

E:\work_hask\emacs-modules-th-test>"c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\dumpbin.exe" /EXPORTS .\dist\build\myflib\myflib.dll | findstr initialise
E:\work_hask\emacs-modules-th-test>git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

E:\work_hask\emacs-modules-th-test>git branch
* master
  merge-flib-into-lib

E:\work_hask\emacs-modules-th-test>cabal build
Warning: The build command is a part of the legacy v1 style of cabal usage.

Please switch to using either the new project style and the new-build command
or the legacy v1-build alias as new-style projects will become the default in
the next version of cabal-install. Please file a bug if you cannot replicate a
working v1- use case with the new-style commands.

For more information, see: https://wiki.haskell.org/Cabal/NewBuild

Resolving dependencies...
Configuring emacs-module-th-test-0.1.0.0...
Preprocessing library for emacs-module-th-test-0.1.0.0..
Building library for emacs-module-th-test-0.1.0.0..
[1 of 1] Compiling Lib              ( lib\Lib.hs, dist\build\Lib.o )
Preprocessing foreign library 'myflib' for emacs-module-th-test-0.1.0.0..
Building foreign library 'myflib' for emacs-module-th-test-0.1.0.0..
[1 of 1] Compiling FLib             ( flib\FLib.hs, dist\build\myflib\myflib-tmp\FLib.o )
[1 of 1] Compiling FLib             ( flib\FLib.hs, dist\build\myflib\myflib-tmp\FLib.o ) [flags changed]
Linking dist\build\myflib\myflib.dll ...

E:\work_hask\emacs-modules-th-test>"c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\dumpbin.exe" /EXPORTS .\dist\build\myflib\myflib.dll | findstr GPL
       7534 1D6D 0044F210 plugin_is_GPL_compatible

E:\work_hask\emacs-modules-th-test>"c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\dumpbin.exe" /EXPORTS .\dist\build\myflib\myflib.dll | findstr initialize
       6918 1B05 0001B660 initializeTimer

from emacs-module.

templateK avatar templateK commented on May 30, 2024

sorry findstr initialize was mistake on master branch. correct output is following.

E:\work_hask\emacs-modules-th-test>"c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\dumpbin.exe" /EXPORTS .\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-module-th-test-0.1.0.0\f\myflib\build\myflib\myflib.dll | findstr initialise
         68   43 0044F1D8 FLib_initialise1_closure
         69   44 00002A40 FLib_initialise1_info
         70   45 0044F1E8 FLib_initialise_closure
         71   46 00002AB0 FLib_initialise_info
         72   47 0044F0F0 FLib_initialisezq_closure
         73   48 00002660 FLib_initialisezq_info = removeOcSymbols.part.1
         75   4A 0044F140 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise10_closure
         76   4B 0044F1A8 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise1_closure
         77   4C 000027C8 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise1_info
         78   4D 0044F170 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise2_closure
         79   4E 0044F090 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise3_closure
         80   4F 000018F0 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise3_info
         81   50 00488037 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise4_bytes
         82   51 0044F0B0 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise5_closure
         83   52 00001AC8 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise5_info
         84   53 0044F050 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise6_closure
         85   54 000017D0 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise6_info
         86   55 00488025 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise7_bytes
         87   56 0044F000 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise8_closure
         88   57 00001460 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise8_info
         89   58 0044F1A0 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise9_closure
         90   59 00002690 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise9_info
         91   5A 0044F1F8 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise_closure
         92   5B 00002AD8 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialise_info
         93   5C 00488000 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialisezuaddrzh1_bytes
         94   5D 00488013 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialisezuaddrzh2_bytes
         95   5E 00488050 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialisezuaddrzh_bytes
         96   5F 0044F030 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialisezudocs_closure
         97   60 000016D0 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialisezudocs_info
         98   61 0044F070 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialisezuerrMsg23_closure
         99   62 00001860 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialisezuerrMsg23_info
        100   63 0044F0D0 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialisezuimplementation_closure
        101   64 00002298 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialisezuimplementation_info
        102   65 0044F1C8 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialisezuzdsinitialise_closure
        103   66 000029D0 FLib_zdfstableZZC0ZZCmainZZCFLibZZCinitialisezuzdsinitialise_info
        111   6E 0044F0E0 FLib_zdwinitialisezq_closure
        112   6F 000025E8 FLib_zdwinitialisezq_info
        113   70 0044F1B8 FLib_zdwzdsinitialise_closure
        114   71 00002940 FLib_zdwzdsinitialise_info
       6917 1B04 00002AE0 initialise
      15319 3BD6 00461FE8 vectorzm0zi12zi0zi1zm7782e2d023d7fc7ea2ab7204955a75f1041eef39_DataziVectorziMutable_uninitialised_closure
      15320 3BD7 001A5450 vectorzm0zi12zi0zi1zm7782e2d023d7fc7ea2ab7204955a75f1041eef39_DataziVectorziMutable_uninitialised_info

from emacs-module.

sergv avatar sergv commented on May 30, 2024

@templateK Could you please try cabal new-build on merge-flib-into-lib? You'll need a cabal.project file, you can take mine at https://github.com/sergv/dotemacs/blob/master/native/emacs-native/cabal.project

from emacs-module.

templateK avatar templateK commented on May 30, 2024

there's no difference.

cabal.project file content

packages:
  emacs-module-th-test.cabal
optimization: 2

-- program-options
--   ghc-options: -g3

output

E:\work_hask\emacs-modules-th-test>cabal new-clean

E:\work_hask\emacs-modules-th-test>cabal new-build
Resolving dependencies...
Build profile: -w ghc-8.4.3 -O2
In order, the following will be built (use -v for more details):
 - emacs-module-th-test-0.1.0.0 (lib) (first run)
 - emacs-module-th-test-0.1.0.0 (flib:myflib) (first run)
Configuring library for emacs-module-th-test-0.1.0.0..
Preprocessing library for emacs-module-th-test-0.1.0.0..
Building library for emacs-module-th-test-0.1.0.0..
[1 of 2] Compiling Flib             ( lib\Flib.hs, E:\work_hask\emacs-modules-th-test\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-module-th-test-0.1.0.0\opt\build\Flib.o )
[2 of 2] Compiling Lib              ( lib\Lib.hs, E:\work_hask\emacs-modules-th-test\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-module-th-test-0.1.0.0\opt\build\Lib.o )
Configuring foreign library 'myflib' for emacs-module-th-test-0.1.0.0..
Preprocessing foreign library 'myflib' for emacs-module-th-test-0.1.0.0..
Building foreign library 'myflib' for emacs-module-th-test-0.1.0.0..
[1 of 1] Compiling FFlib            ( flib\FFlib.hs, E:\work_hask\emacs-modules-th-test\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-module-th-test-0.1.0.0\f\myflib\opt\build\myflib\myflib-tmp\FFlib.o )
[1 of 1] Compiling FFlib            ( flib\FFlib.hs, E:\work_hask\emacs-modules-th-test\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-module-th-test-0.1.0.0\f\myflib\opt\build\myflib\myflib-tmp\FFlib.o ) [flags changed]
Linking E:\work_hask\emacs-modules-th-test\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-module-th-test-0.1.0.0\f\myflib\opt\build\myflib\myflib.dll ...

E:\work_hask\emacs-modules-th-test>"c:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\dumpbin.exe" /EXPORTS^
More?  .\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-module-th-test-0.1.0.0\f\myflib\opt\build\myflib\myflib.dll | findstr GPL

E:\work_hask\emacs-modules-th-test>

from emacs-module.

sergv avatar sergv commented on May 30, 2024

Okay, I have reproduced the problem.

I believe you should omit any Haskell modules from the foreign-library block of a cabal file. Please take a look at my commit that made my project work on Windows and replicate it for your project: sergv/emacs-native@ac3cf1a.

Sergey@box MINGW64 ~/tmp/emacs-native
$ cabal new-build
Resolving dependencies...
Build profile: -w ghc-8.4.3 -O1
In order, the following will be built (use -v for more details):
 - radix-tree-0.1 (lib) (requires download & build)
 - emacs-native-0.1.0.0 (lib) (first run)
 - emacs-native-0.1.0.0 (flib:emacs-native) (first run)
Downloading  radix-tree-0.1
Downloaded   radix-tree-0.1
Starting     radix-tree-0.1 (lib)
Building     radix-tree-0.1 (lib)
Installing   radix-tree-0.1 (lib)
ignoring (possibly broken) abi-depends field for packages
Completed    radix-tree-0.1 (lib)
Configuring library for emacs-native-0.1.0.0..
Preprocessing library for emacs-native-0.1.0.0..
Building library for emacs-native-0.1.0.0..
[ 1 of 11] Compiling Data.ByteString.Char8.Ext ( src\Data\ByteString\Char8\Ext.hs, C:\home\tmp\emacs-native\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-native-0.1.0.0\build\Data\ByteString\Char8\Ext.o )
[ 2 of 11] Compiling Data.FuzzyMatch  ( src\Data\FuzzyMatch.hs, C:\home\tmp\emacs-native\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-native-0.1.0.0\build\Data\FuzzyMatch.o )
[ 3 of 11] Compiling Data.NBSem       ( src\Data\NBSem.hs, C:\home\tmp\emacs-native\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-native-0.1.0.0\build\Data\NBSem.o )
[ 4 of 11] Compiling Data.Filesystem  ( src\Data\Filesystem.hs, C:\home\tmp\emacs-native\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-native-0.1.0.0\build\Data\Filesystem.o )
[ 5 of 11] Compiling Data.Regex       ( src\Data\Regex.hs, C:\home\tmp\emacs-native\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-native-0.1.0.0\build\Data\Regex.o )
[ 6 of 11] Compiling Data.Eproj       ( src\Data\Eproj.hs, C:\home\tmp\emacs-native\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-native-0.1.0.0\build\Data\Eproj.o )
[ 7 of 11] Compiling Emacs.EprojTagIndex ( src\Emacs\EprojTagIndex.hs, C:\home\tmp\emacs-native\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-native-0.1.0.0\build\Emacs\EprojTagIndex.o )
[ 8 of 11] Compiling Emacs.FastFileSearch ( src\Emacs\FastFileSearch.hs, C:\home\tmp\emacs-native\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-native-0.1.0.0\build\Emacs\FastFileSearch.o )
[ 9 of 11] Compiling Emacs.FuzzyMatch ( src\Emacs\FuzzyMatch.hs, C:\home\tmp\emacs-native\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-native-0.1.0.0\build\Emacs\FuzzyMatch.o )
[10 of 11] Compiling Emacs.Grep       ( src\Emacs\Grep.hs, C:\home\tmp\emacs-native\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-native-0.1.0.0\build\Emacs\Grep.o )
[11 of 11] Compiling Emacs.Init       ( lib\Emacs\Init.hs, C:\home\tmp\emacs-native\dist-newstyle\build\x86_64-windows\ghc-8.4.3\emacs-native-0.1.0.0\build\Emacs\Init.o )
Configuring foreign library 'emacs-native' for emacs-native-0.1.0.0..
Preprocessing foreign library 'emacs-native' for emacs-native-0.1.0.0..
Building foreign library 'emacs-native' for emacs-native-0.1.0.0..

Sergey@box MINGW64 ~/tmp/emacs-native
$ find . -name '*.dll'
./dist-newstyle/build/x86_64-windows/ghc-8.4.3/emacs-native-0.1.0.0/f/emacs-native/build/emacs-native/emacs-native.dll

Sergey@box MINGW64 ~/tmp/emacs-native
$ objdump -t $(find . -name '*.dll') | grep GPL
(standard input):80516:[80511](sec  1)(fl 0x00)(ty   0)(scl   6) (nx 0) 0x00000000006c4468 s4GPL_info
(standard input):267347:[267342](sec  2)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x0000000000000000 plugin_is_GPL_compatible

Sergey@box MINGW64 ~/tmp/emacs-native
$ objdump -t $(find . -name '*.dll') | grep -E '\<initialise'
(standard input):4163:[4158](sec  1)(fl 0x00)(ty  20)(scl   2) (nx 1) 0x0000000000038d60 initialise

from emacs-module.

sergv avatar sergv commented on May 30, 2024

Since we have a solution I think the issue may be closed.

from emacs-module.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.