webui-dev / nim-webui

Use any web browser as GUI, with Nim in the backend and HTML5 in the frontend.
https://webui.me
MIT License
130 stars 9 forks source link

can't install with nimble (mongoose.h) #8

Closed konsumer closed 1 year ago

konsumer commented 1 year ago

Possibly related to #2

I am on OSX (M1) Ventura 13.3, nim 1.6.10, nimble 0.13.1

I can do nimble install webui without error, but not track it as a dependency in my project.

If I add this to my nimble file:

requires "https://github.com/neroist/webui.git"

or:

requires "webui >= 0.2.1"

I get this, when I try to nimble run:

/Users/konsumer/.nimble/pkgs/webui-0.2.1/webui/webui/src/mongoose.c:20:10: fatal error: 'mongoose.h' file not found
#include "mongoose.h"
         ^~~~~~~~~~~~
konsumer commented 1 year ago

I get the same error if I do this:

git clone --recursive https://github.com/neroist/webui.git
cd webui
nim c examples/minimal.nim
konsumer commented 1 year ago

I made some bindings for soloud, pntr, and physfs (see here) that use nim to do the compiling. Similar idea might make it work better:

{.passC: "-Ivendor/".}

{.emit: """
#define PNTR_IMPLEMENTATION
#define PNTR_PIXELFORMAT_ARGB
#define PNTR_ENABLE_DEFAULT_FONT
#define PNTR_ENABLE_TTF
#define PNTR_ENABLE_FILTER_SMOOTH

#include "pntr/pntr.h"
""".}

or

{.passC: "-Ivendor/soloud/src/ -Ivendor/soloud/include/ -DWITH_NULL -DWITH_MINIAUDIO -DWITH_NOSOUND".}
{.compile: "vendor/soloud/src/audiosource/openmpt/soloud_openmpt.cpp".}

Basically, I setup the compiler/linker flags in passC or passL and emit and compile to inline the C. Paths are all relative to the root of the project (where the nimble file is) so can simplify finding files and stuff. Nim likes compile calls to be .c or. cpp extensions (not .h) so you can inject an include for header-only things with emit.

hassandraga commented 1 year ago

I re-test it in Windows, using nim v1.6.12. It's working fine.

git clone --recursive https://github.com/neroist/webui.git cd webui\examples nim c minimal.nim

Hint: used config file 'C:\Nim\config\nim.cfg' [Conf]
Hint: used config file 'C:\Nim\config\config.nims' [Conf]
Hint: used config file 'C:\...\webui\examples\nim.cfg' [Conf]
............................................................................................
CC: mongoose
CC: webui
CC: C:/Nim/lib/std/private/digitsutils.nim
CC: C:/Nim/lib/system/dollars.nim
CC: C:/Nim/lib/system/io.nim
CC: C:/Nim/lib/system.nim
CC: C:/Nim/lib/pure/base64.nim
CC: C:/Nim/lib/pure/dynlib.nim
CC: C:/Nim/lib/windows/winlean.nim
CC: C:/Nim/lib/pure/times.nim
CC: C:/Nim/lib/std/private/win_setenv.nim
CC: C:/Nim/lib/pure/os.nim
CC: ../webui/bindings.nim
CC: ../webui.nim
CC: minimal.nim
Hint:  [Link]
Hint: gc: orc; opt: speed; options: -d:release
49113 lines; 4.128s; 75.457MiB peakmem; proj: C:\...\webui\examples\minimal.nim; out: C:\...\webui\examples\minimal.exe [SuccessX]

Something is missing in this line. I don't know.

konsumer commented 1 year ago

If I add this I can get it further:

{.passC: "-I../webui/webui/include".}

but then it fails again:

/Users/konsumer/Desktop/webui/webui/webui/src/webui.c:2539:39: error: use of undeclared identifier 'WEBUI_MAX_PATH'
    win->path = (char*) _webui_malloc(WEBUI_MAX_PATH);
                                      ^
/Users/konsumer/Desktop/webui/webui/webui/src/webui.c:2643:42: error: use of undeclared identifier 'WEBUI_MAX_PATH'
    if((path == NULL) || (strlen(path) > WEBUI_MAX_PATH))
                                         ^
/Users/konsumer/Desktop/webui/webui/webui/src/webui.c:3240:40: error: use of undeclared identifier 'WEBUI_MAX_PATH'
    char* path = (char*) _webui_malloc(WEBUI_MAX_PATH);
                                       ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
4 errors generated.
Error: execution of an external compiler program 'clang -c  -w -ferror-limit=3 -I../webui/webui/include -O3   -I/opt/homebrew/Cellar/nim/1.6.10/nim/lib -I/Users/konsumer/Desktop/webui/examples -o /Users/konsumer/.cache/nim/minimal_r/webui.c.o /Users/konsumer/Desktop/webui/webui/webui/src/webui.c' failed with exit code: 1

which seems to rely on MAX_PATH, which is a windows-only thing, as far as I can tell.

Adding a define for it, it still couldn't find the C files, so I did this:

{.passC: "-I../webui/webui/include -DWEBUI_MAX_PATH=256".}
{.compile: "../webui/webui/src/webui.c".}
{.compile: "../webui/webui/src/mongoose.c".}

And I am still getting undefined symbols:

Undefined symbols for architecture arm64:
  "_WEBUI_FILE_EXIST", referenced from:
      __webui_file_exist_mg in webui.c.o
      __webui_file_exist in webui.c.o
      __webui_interpret_file in webui.c.o
      __webui_server_event_handler in webui.c.o
      __webui_file_exist_mg in webui.c.o
      __webui_file_exist in webui.c.o
      __webui_interpret_file in webui.c.o
      ...
  "_WEBUI_GET_CURRENT_DIR", referenced from:
      _webui_script in webui.c.o
      _webui_new_window in webui.c.o
      _webui_close in webui.c.o
      _webui_is_any_window_running in webui.c.o
      _webui_new_server in webui.c.o
      _webui_set_timeout in webui.c.o
      _webui_show in webui.c.o
      ...
  "_WEBUI_PCLOSE", referenced from:
      __webui_interpret_command in webui.c.o
      __webui_interpret_command in webui.c.o
  "_WEBUI_POPEN", referenced from:
      __webui_interpret_command in webui.c.o
      __webui_interpret_command in webui.c.o
konsumer commented 1 year ago

I have no problems with building upstream lib:

git clone https://github.com/alifcommunity/webui.git
cd webui/build/MacOS/Clang
make
konsumer commented 1 year ago

Here is me having the trouble on mac.

I tried on docker (nimlang/nim) and arm64 linux in qemu, and it built and ran ok, so I think it's some mac-specific problem.

Screenshot 2023-03-30 at 3 51 13 PM
konsumer commented 1 year ago

I made my own simpler wrapper here and it pops up a window with nimble test and no error building. For some reason it doesn't insert the content (opens an empty window) and doesn't wait(), but it might be some hint as to why it's not working.

neroist commented 1 year ago

@konsumer do you think this can be closed due to #9?

konsumer commented 1 year ago

@neroist yep, I think it's as good as it gets for now, since there are some problems on mac on upstream. If those get resolved, we should update the upstream again, here, I think. The original problem of "won't build on mac" is resolved with #9, though, so I will close.