Opened 8 years ago

Last modified 3 months ago

#1407 new feature request

Add the ability to :set -l{foo} in .ghci files

Reported by: guest Owned by: archblob
Priority: normal Milestone: 7.10.1
Component: GHCi Version: 6.6.1
Keywords: Cc: hvr
Operating System: Windows Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions: Phab:D194

Description

Currently it appears that library flags like -lidn can only be passed on the command line of ghci, but it would be convenient (and more consistent) to be have to have them able to work from the .ghci file. Attempts to do so are silently ignored in both 6.4.2 and 6.6.

The only other place it would make sense to pass it would be as something like OPTIONS_GHC, but that results in "unknown flags in {-# OPTIONS #-} pragma: -lidn" in 6.4.2 and appears to be silently ignored in 6.6.

Attachments (2)

fix_1407.patch (5.1 KB) - added by archblob 15 months ago.
fix_T1407.patch (3.7 KB) - added by archblob 12 months ago.

Download all attachments as: .zip

Change History (24)

comment:1 Changed 8 years ago by igloo

  • Milestone set to 6.8

This is related to allowing -package flags in OPTIONS_GHC, which is talked about in http://hackage.haskell.org/trac/ghc/wiki/GhcPackages

comment:2 Changed 8 years ago by simonmar

  • difficulty changed from Unknown to Easy (1 hr)
  • Milestone changed from 6.8 branch to 6.10 branch

comment:3 Changed 7 years ago by igloo

See also #2365

comment:4 Changed 7 years ago by simonmar

  • Architecture changed from Unknown to Unknown/Multiple

comment:5 Changed 7 years ago by simonmar

  • Operating System changed from Unknown to Unknown/Multiple

comment:6 Changed 6 years ago by igloo

  • Milestone changed from 6.10 branch to _|_

comment:7 Changed 6 years ago by simonmar

  • difficulty changed from Easy (1 hr) to Easy (less than 1 hour)

comment:8 Changed 3 years ago by mf825

  • Type of failure set to None/Unknown

I would like to second this request. I use emacs as an IDE, and call ghci from emacs with all the command line parameter handling in .ghci. Of course I could write elisp functions to pluck -l parameters from :set statements in .ghci, but that seems a little insane.

Also, since both -L and -l are documented as dynamic, and all dynamic command line arguments are documented to work both on the command line and in .ghci, I suggest this is changed into a bug.

I reproduced this with ghc-7.6.1 on debian and with ghc-7.4.1 on ubuntu.

comment:9 Changed 3 years ago by simonpj

  • Owner set to igloo

Ian, could you investigate why this doesn't already work? Thanks.

comment:10 Changed 3 years ago by igloo

This works:

$ ghci -lz
GHCi, version 7.7.20130112: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading object (dynamic) /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/libz.so ... done
final link ... done
Prelude> import Foreign.C
Prelude Foreign.C> import Foreign.Ptr
Prelude Foreign.C Foreign.Ptr> foreign import ccall "zlibVersion" z :: IO CString
Prelude Foreign.C Foreign.Ptr> z >>= peekCString
"1.2.3.4"
Prelude Foreign.C Foreign.Ptr> 

This doesn't:

$ ghci    
GHCi, version 7.7.20130112: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :set -lz
Prelude> import Foreign.C
Prelude Foreign.C> import Foreign.Ptr
Prelude Foreign.C Foreign.Ptr> foreign import ccall "zlibVersion" z :: IO CString

ByteCodeLink: can't find label
During interactive linking, GHCi couldn't find the following symbol:
  zlibVersion
This may be due to you not asking GHCi to load extra object files,
archives or DLLs needed by your current session.  Restart GHCi, specifying
the missing library using the -L/path/to/object/dir and -lmissinglibname
flags, or simply by naming the relevant files on the GHCi command line.
Alternatively, this link failure might indicate a bug in GHCi.
If you suspect the latter, please send a bug report to:
  [email protected]

comment:11 Changed 2 years ago by igloo

  • Owner igloo deleted

comment:12 Changed 15 months ago by archblob

  • Cc hvr added
  • Status changed from new to patch

There may be some nuances in the whole linking stuff that I don't understand, so please review. As far as I can tell the patch works as expected.

comment:13 Changed 15 months ago by archblob

  • Owner set to archblob

Changed 15 months ago by archblob

comment:14 Changed 15 months ago by archblob

  • Milestone changed from to 7.10.1

comment:15 Changed 13 months ago by thoughtpolice

  • Status changed from patch to infoneeded

@archblob - it seems this doesn't correcly apply to HEAD anymore. Would you mind rebasing the changes?

Changed 12 months ago by archblob

comment:16 Changed 12 months ago by archblob

I have attached a fix based on HEAD. The fix has no test case because I'm not sure what libraries are guaranteed to be present on every system so that the test won't fail. If you can think of any, let me know and I'll add a test case or someone else can do it.

I'm sorry this took a week to rebase :-P.

comment:17 Changed 12 months ago by Austin Seipp <austin@…>

In 52eab67a99dd928204b730355245233fa96fa24d/ghc:

Add the ability to :set -l{foo} in ghci, fix #1407.

Summary:
The dynamic linking code was already there but it was not called
on flag changes in ghci.

Test Plan: validate

Reviewers: hvr, simonmar, austin

Reviewed By: austin

Subscribers: simonmar, ezyang, carter

Differential Revision: https://phabricator.haskell.org/D194

GHC Trac Issues: #1407

comment:18 Changed 12 months ago by thoughtpolice

  • Resolution set to fixed
  • Status changed from infoneeded to closed

Merged, thanks!

comment:19 Changed 12 months ago by thoughtpolice

  • Differential Revisions set to Phab:D194

comment:20 Changed 3 months ago by thomie

  • Operating System changed from Unknown/Multiple to Windows
  • Owner archblob deleted
  • Resolution fixed deleted
  • Status changed from closed to new

There are 2 problems with the above patch on Windows:

  • the test fails, because -ldl can not be found.
  • in ghci, I can type :set -lsomethingnonexistent and it doesn't complain

Note that running ghci -lsomethingnonexistent does fail on all platforms. Running :set -lsomethingnonexist in ghci on linux also fails.

comment:21 Changed 3 months ago by Thomas Miedema <thomasmiedema@…>

In a765f72c130111cdbd30f2a3e159186c6e625d2a/ghc:

Testsuite: mark tests as expect_broken on win64

Tickets: #1407, #9381, #9878.

Differential Revision: https://phabricator.haskell.org/D977

comment:22 Changed 3 months ago by archblob

  • Owner set to archblob

I'll do windows build and see what's wrong. The test case we should change to a library guaranteed to be on both plaforms, I thought libdl was, we need something better.

Last edited 3 months ago by archblob (previous) (diff)
Note: See TracTickets for help on using tickets.