Skip to content

Doesn't build when using netbsd curses on Linux #8087

Closed

Description

@ericonr

fish 3.3.0

I wanted to build fish locally, but had forgotten I had https://github.com/sabotage-linux/netbsd-curses installed instead of ncurses. It failed to build because

/// Under curses, tputs expects an int (*func)(char) as its last parameter, but in ncurses, tputs
/// expects a int (*func)(int) as its last parameter. tputs_arg_t is defined to always be what tputs
/// expects. Hopefully.
#if !defined(NCURSES_VERSION) || defined(__NetBSD__)
typedef int tputs_arg_t;
#else
typedef char tputs_arg_t;
#endif

doesn't cover this specific use case. Ideally it would be possible to run a proper test in CMakeLists and use the result of that? Not urgent, it's easy to fix locally, but still a build bug.

Activity

  1. ericonr commented on Jun 28, 2021

    @ericonr
    ContributorAuthor

    Fixing this is not enough for it to build; this setup also confuses FindPackage(Curses) and fish's pkg_config fallback isn't 100% correct.

  2. faho commented on Jun 28, 2021

    @faho
    Member

    The FindPackage(Curses) bit would of course have to be improved in cmake (or whatever else provides that).

    Tbh this isn't something I would want to work on as it's not a use case I have. Patches welcome!

  3. added this to the fish-future milestone on Jun 28, 2021
  4. ericonr commented on Jun 28, 2021

    @ericonr
    ContributorAuthor

    No worries, this is mostly a documentation issue. If I can come up with a clean fix, I will open a PR; in the meantime I just ripped some stuff out.

  5. ericonr commented on Jun 28, 2021

    @ericonr
    ContributorAuthor

    The FindPackage(Curses) bit would of course have to be improved in cmake (or whatever else provides that).

    Using pkgconfig first instead of as a fallback would be almost enough, it's CMake's weird logic in FindCurses that gets things wrong.

  6. mqudsi commented on Aug 13, 2021

    @mqudsi
    Contributor

    CMake's weird FindCurses implementation has caused us lots of grief. We don't run on any platforms where pkgconfig isn't a thing; personally, if you want to open a PR that fixes the netbsd curses problem and happens to change FindCurses to a fallback for pkgconfig rather than the other way around, I would happy to review it.

  7. alarixnia commented on Sep 15, 2021

    @alarixnia

    NetBSD doesn't provide pkgconfig files for libcurses. That appears to be something the Linux port added... It should be easy to detect ncurses because it defines NCURSES_VERSION_MAJOR etc.

  8. faho commented on Sep 15, 2021

    @faho
    Member

    It should be easy to detect ncurses because it defines NCURSES_VERSION_MAJOR etc.

    @alarixnia I'm assuming you mean we should replace the curses-related __NetBSD__ checks with NCURSES_VERSION_MAJOR checks?

    I'm not sure if that would work, given we do

    #if !defined(NCURSES_VERSION) || defined(__NetBSD__)

    here. So unless my brain is refusing to logic again (not an impossibility, it does that sometimes), that should already be taken on NetBSD and on systems without ncurses.

    Or is this specifically about NCURSES_VERSION_MAJOR?

  9. alarixnia commented on Sep 15, 2021

    @alarixnia

    @faho Hm, honestly I just scanned ncurses.h to look for something that would uniquely identify it as ncurses. But now I realize the problem is more complicated...

    The problematic function is clearly a terminfo function, and I guess terminfo is usually provided by ncurses on non-NetBSD systems, but NetBSD libterminfo is still used on NetBSD if you're using ncurses (edit: actually, no, probably not?). Is the Linux port of NetBSD libcurses not using NetBSD libterminfo (that seems like a mistake), or is NCURSES_VERSION being defined somehow (also a mistake)?

  10. faho commented on Sep 15, 2021

    @faho
    Member

    This appears ŧo have its own tputs and I can't find an NCURSES_VERSION define anywhere.

    There is sabotage-linux/netbsd-curses#43, which explains that libterminfo is still separate, so it appears our curses-finding magic finds ncurses terminfo and NetBSD curses.

    Which, uh, yeah, that's... not gonna work, is it?

    Using pkg-config if possible and falling back to FindCurses would probably fix even that, tho.

  11. ericonr commented on Sep 16, 2021

    @ericonr
    ContributorAuthor

    There is sabotage-linux/netbsd-curses#43, which explains that libterminfo is still separate, so it appears our curses-finding magic finds ncurses terminfo and NetBSD curses.

    That isn't the case here. I have only netbsd-curses headers.

  12. faho commented on Sep 16, 2021

    @faho
    Member

    That isn't the case here. I have only netbsd-curses headers.

    Then where/why is NCURSES_VERSION defined?

  13. faho commented on Sep 21, 2021

    @faho
    Member

    Okay, I don't see how this fails to build.

    Either you have ncurses, and NCURSES_VERSION is defined, so it picks the datatype that's correct for ncurses,

    or you don't have ncurses, and NCURSES_VERSION is not defined, so it picks the datatype that's appropriate for NetBSD-curses - including the linux port.

    If NCURSES_VERSION is defined, then you probably also have ncurses installed and cmake picks it up partially (or you defined it yourself and that's the issue).

    Either way, I would quite like to have at the very least the actual compiler error, and ideally some reproduction steps.

  14. ericonr commented on Sep 23, 2021

    @ericonr
    ContributorAuthor

    The issue here is that NetBSD uses the same prototype as ncurses, but netbsd-curses on Linux doesn't define __NetBSD__. So we fallback to the char definition, which is wrong. Without applying my changes:

    /home/ericonr/mypro/fish-shell/src/output.cpp: In member function 'int outputter_t::term_puts(const char*, int)':
    /home/ericonr/mypro/fish-shell/src/output.cpp:308:54: error: invalid conversion from 'int (*)(tputs_arg_t)' {aka 'int (*)(char)'} to 'int (*)(int)' [-fpermissive]
      308 |     int res = tputs(const_cast<char *>(str), affcnt, tputs_writer);
          |                                                      ^~~~~~~~~~~~
          |                                                      |
          |                                                      int (*)(tputs_arg_t) {aka int (*)(char)}
    In file included from /usr/include/term.h:2002,
                     from /home/ericonr/mypro/fish-shell/src/output.cpp:16:
    /usr/include/termcap.h:40:31: note:   initializing argument 3 of 'int tputs(const char*, int, int (*)(int))'
       40 | int  tputs(const char *, int, int (*)(int));
          |                               ^~~~~~~~~~~~
    [42/105] Building CXX object CMakeFiles/fishlib.dir/src/parse_execution.cpp.o
    ninja: build stopped: subcommand failed.
    
  15. faho commented on Sep 23, 2021

    @faho
    Member

    The issue here is that NetBSD uses the same prototype as ncurses, but netbsd-curses on Linux doesn't define NetBSD.

    But the condition isn't just about __NetBSD__!

    What about the first half?

    #if !defined(NCURSES_VERSION) || defined(__NetBSD__)

    Unless I am grossly misunderstanding this, this branch should also be taken if NCURSES_VERSION isn't defined. Which, since you've been swearing that you don't have ncurses, should be the case here?

    Can you just check if you have NCURSES_VERSION defined?

  16. faho commented on Sep 23, 2021

    @faho
    Member

    Did you, uh, edit that code snippet? Because looking at the actual code it says:

    #if defined(NCURSES_VERSION) || defined(__NetBSD__)

    Without the !!

    So I have no idea who even uses char here?

  17. faho commented on Sep 23, 2021

    @faho
    Member

    Ah, our old friend, OpenIndiana/Solaris/Illumos uses char. Blergh, let's just try_compile the pain away.

  18. added a commit that references this issue on Sep 23, 2021
    82a809e
  19. modified the milestones: fish-future, fish 3.4.0 on Sep 23, 2021
  20. ericonr commented on Sep 25, 2021

    @ericonr
    ContributorAuthor

    Did you, uh, edit that code snippet? Because looking at the actual code it says:

    Shoot, sorry! I edited it like that to compile successfully locally for me, didn't realize I had pasted the edited version here. Thanks!

  21. added a commit that references this issue on Dec 12, 2021
  22. locked as resolved and limited conversation to collaborators on Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions