Skip to content

Package to automatically initialize and exit the GHC RTS for building Haskell shared libraries

License

Notifications You must be signed in to change notification settings

lambdadog/hs-auto-init

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

auto-init

Automatically initialize the GHC RTS by calling hs_init (and deinitialize it by calling hs_exit) when your library loads, using GCC constructors and destructors.

How to use

auto-init is not yet published on Hackage, but when it is, it will be as simple as adding auto-init to the build-depends field of your foreign-library stanza.

Limitations

Since there is no portable way to get the program's arguments list in a constructor, the RTS is simply initialized with a nulled out argc and argv. This means that the results of getProgName and getArgs are likely to be "<unknown>" and [], but importantly means that you must pass your RTS options in the GHCRTS environmental variable rather than in the args, which truthfully suits options for shared libraries much better. If you feel it's important to set the RTS options to something specific for your project, you may copy cbits/auto_init.c into your own project, modify it, and add it to extra-source-files and c-sources. Note that hs_init copies argc and argv, so they can be safely allocated on the stack and thus destroyed when init returns.

Though it should be noted that if hs_init has already been called by the running application that even if you set your own RTS opts via vendoring and modifying cbits/auto_init.c as described above, the first invocation's options will supersede yours. Subsequent inits are simply ignored.

About

Package to automatically initialize and exit the GHC RTS for building Haskell shared libraries

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published