Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error while comiling code using gtklayershell #204

Open
licoricee opened this issue Jul 7, 2022 · 16 comments
Open

error while comiling code using gtklayershell #204

licoricee opened this issue Jul 7, 2022 · 16 comments

Comments

@licoricee
Copy link

this is the code

import gintro/[gtklayershell]
echo getProtocolVersion()

and while compiling with nimble build i get this error

  Verifying dependencies for layershell_test@0.1.0
      Info: Dependency on gintro@#head already satisfied
  Verifying dependencies for gintro@#head
   Building layershell_test/layershell_test using c backend
/home/luke/.nimble/pkgs/gintro-#head/gintro/harfbuzz.nim(2232, 35) Error: expression cannot be cast to Face00=object
       Tip: 3 messages have been suppressed, use --verbose to show them.
     Error: Build failed for package: layershell_test
        ... Execution failed with exit code 1
        ... Command: /home/luke/.nimble/bin/nim c --colors:on --noNimblePath -d:NimblePkgVersion=0.1.0 --path:'/home/luke/.nimble/pkgs/gintro-#head' --hints:off -o:/home/luke/layershell_test/layershell_test /home/luke/layershell_test/src/layershell_test.nim
@licoricee
Copy link
Author

another thing, im on harfbuzz 4.4.1-1

@StefanSalewski
Copy link
Owner

Thanks for reporting. I have to admit that I can currently not remember what gtklayershell is, maybe we have not a single test for it. I guess someone requested it years ago, and then vanished soon. I am not sure if layershell is available for my Gentoo Linux as a package, maybe I have to install from git sources. But I will try to test soon.

My general recommendation for people new to GTK or people that do not intend to do some serious stuff: just use another GUI toolkit, Nim has 20 of them, and for toy apps these may be simpler to use then GTK.

@StefanSalewski
Copy link
Owner

It is available for Gentoo Linux now, at least in version 0.6: https://packages.gentoo.org/packages/gui-libs/gtk-layer-shell. That makes testings easier for me -- currently it is not installed on my box. I hope it is not an v0.7 only issue.

@StefanSalewski
Copy link
Owner

Seems that the Gentoo version supports only GTK3 still, and they ship only the GIR file for v0.1:

/usr/share/gir-1.0/GtkLayerShell-0.1.gir

  <include name="Gtk" version="3.0"/>
  <package name="gtk-layer-shell-0"/>
  <c:include name="gtk-layer-shell/gtk-layer-shell.h"/>
  <namespace name="GtkLayerShell"
             version="0.1"
             shared-library="libgtk-layer-shell.so.0"
             c:identifier-prefixes="GtkLayerShell"
             c:symbol-prefixes="gtk_layer">

Have you managed to install a version for GTK4? And do you really intent to do serious work with it?

@StefanSalewski
Copy link
Owner

The bad news is, that I can not reproduce your issue with v0.6:

$ cat t.nim 
import gintro/[gtklayershell]
echo getProtocolVersion()
salewski@hx90 /tmp/hhh $ nim c -f t.nim 
Hint: used config file '/home/salewski/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/salewski/Nim/config/config.nims' [Conf]
..................................................................................................
CC: ../../home/salewski/Nim/lib/std/private/digitsutils.nim
CC: ../../home/salewski/Nim/lib/system/formatfloat.nim
CC: ../../home/salewski/Nim/lib/system/dollars.nim
CC: ../../home/salewski/Nim/lib/std/syncio.nim
CC: ../../home/salewski/Nim/lib/system.nim
CC: ../../home/salewski/.nimble/pkgs/gintro-#head/gintro/glib.nim
CC: ../../home/salewski/Nim/lib/pure/times.nim
CC: ../../home/salewski/.nimble/pkgs/gintro-#head/gintro/gobject.nim
CC: ../../home/salewski/.nimble/pkgs/gintro-#head/gintro/cairo.nim
CC: ../../home/salewski/.nimble/pkgs/gintro-#head/gintro/gtklayershell.nim
CC: t.nim
Hint:  [Link]
Hint: gc: refc; opt: none (DEBUG BUILD, `-d:release` generates faster code)
194008 lines; 2.379s; 350.879MiB peakmem; proj: /tmp/hhh/t.nim; out: /tmp/hhh/t [SuccessX]
salewski@hx90 /tmp/hhh $ ls -lt
total 128
-rwxr-xr-x 1 salewski salewski 126624 Jul  8 08:23 t
-rw-r--r-- 1 salewski salewski     56 Jul  8 08:22 t.nim
salewski@hx90 /tmp/hhh $ ./t
0

So I may have to install latest v0.7 from git. For the case that you are just playing around with things, having fun finding stuff that fails, I would suggest that we wait with the fix til end of this year. I have just migrated to a new box, as my old one did some random reboots in the last weeks, and I have to prepare the box to allow installation of additional stuff in /opt from git.

@licoricee
Copy link
Author

ok i can always try downgrading layershell, but i dont think its a layershell issue tho it seems to be with harfbuzz

@StefanSalewski
Copy link
Owner

Interesting. I have currently harfbuzz 4.3, but Gentoo provides unstable 4.4.1. I can try to install that this evening and then try again.

@StefanSalewski
Copy link
Owner

compiling with nimble build

Well I never do that, I always use "nim c myprog.nim". I have no idea for the error message "expression cannot be cast to Face00=object". What is your Nim compiler version? And are you using Linux or Windows/Mac?

@StefanSalewski
Copy link
Owner

Yes, you were right:

nim c t.nim 
Hint: used config file '/home/salewski/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/salewski/Nim/config/config.nims' [Conf]
..........................................................................................
/home/salewski/.nimble/pkgs/gintro-#head/gintro/harfbuzz.nim(2232, 35) Error: expression cannot be cast to Face00=object

I was not aware that we have a harfbuzz package for gintro at all. Will investigate this evening.

@StefanSalewski
Copy link
Owner

The whole harfbuzz.nim looks strange. Why start all the type names in lower case?

@StefanSalewski
Copy link
Owner

My current guess is, that the defined types in harfbuzz and freetype are very different from the other GTK modules. For example

https://freetype.org/freetype2/docs/reference/ft2-base_interface.html#ft_face

typedef struct FT_FaceRec_* FT_Face;

So here the defined type is already a pointer! That is very different from the ordinary GTK modules as in

https://gitlab.gnome.org/GNOME/gtk/-/blob/main/gtk/gtkbutton.h

typedef struct _GtkButton GtkButton;

Fixing that in the generator script gen.nim may be a lot of work, maybe more than 100 hours? I have no idea, and I wonder if that makes sense at all, as we have no real users for gintro. The basic working shape of gen.nim was created 6 years ago, initially only for the GTK core modules. I can currently absolutely not remember which changes would be needed to fix these freetype and hardbuzz issues.

@StefanSalewski
Copy link
Owner

I just noticed that with latest harfbuzz all my gintro apps fail to compile. Well we can fix that manually, that it make the other modules compile and work with:

cat /home/salewski/.nimble/pkgs/gintro-#head/gintro/freetype2.nim 
# dependencies:
# immediate dependencies:
# libraries:
# 
{.warning[UnusedImport]: off.}

const Lib = ""
{.pragma: libprag, cdecl, dynlib: Lib.}

type
  Bitmap00* {.pure.} = object
  Bitmap* = ref object
    impl*: ptr Bitmap00
    ignoreFinalizer*: bool

type
  Face00* {.pure.} = ptr object
  Face* = ref object
    impl*: Face00
    ignoreFinalizer*: bool

type
  Library00* {.pure.} = object
  Library* = ref object
    impl*: ptr Library00
    ignoreFinalizer*: bool

proc libraryVersion*() {.
    importc: "FT_Library_Version", libprag.}

As long as you do not explicitly use freetype and harfbuzz, with that fix layershell may work for you?

@licoricee
Copy link
Author

Oh thanks I'll try it out as soon as I get a chance! Thanks for your help with this

@StefanSalewski
Copy link
Owner

I think I will start by asking at the Gnome forum, maybe Mr Bassi or Mr Droege can give us some hints:

https://discourse.gnome.org/t/the-gintro-nim-bindings-do-not-compile-with-latest-harfbuzz-4-4-1/10408

@StefanSalewski
Copy link
Owner

OK, should be fixed now. At least my own apps seems to compile and run again.

You can try with

nimble uninstall gintro
nimble install gintro@#head

As you may have noticed, there was no reaction at Gnome forum -- maybe Mr. Bassi and Mr. Droege are in vacation or have retired. So I applied this ugly fix:

$ diff ~/gintrotest/test/gen.nim gen.nim 
3c3
< # v 0.9.9 2022-JUL-10
---
> # v 0.9.9 2022-MAY-17
917,925c917
<   var p = gTypeInfoIsPointer(t)
< 
<   if not p:
<     let tag = gTypeInfoGetTag(t)
<     if tag == GITypeTag.INTERFACE:
<       let iface = gTypeInfoGetInterface(t)
<       if gBaseInfoGetNamespace(iface) == "freetype2" and gBaseInfoGetName(iface) == "Face":
<         p = true # see issue https://discourse.gnome.org/t/the-gintro-nim-bindings-do-not-compile-with-latest-harfbuzz-4-4-1/10408
< 
---
>   let p = gTypeInfoIsPointer(t)

With this patch, we get now

diff nim_gi/harfbuzz.nim /home/salewski/.nimble/pkgs/gintro-#head/gintro/harfbuzz.nim
2227c2227
< proc hb_ft_face_create(ftFace: ptr freetype2.Face00; destroy: proc(userData: pointer) {.cdecl.}): ptr faceT00 {.
---
> proc hb_ft_face_create(ftFace: freetype2.Face00; destroy: proc(userData: pointer) {.cdecl.}): ptr faceT00 {.
2232c2232
<   result.impl = hb_ft_face_create(cast[ptr freetype2.Face00](ftFace.impl), destroy)
---
>   result.impl = hb_ft_face_create(cast[freetype2.Face00](ftFace.impl), destroy)
2234c2234
< proc hb_ft_face_create_cached(ftFace: ptr freetype2.Face00): ptr faceT00 {.
---
> proc hb_ft_face_create_cached(ftFace: freetype2.Face00): ptr faceT00 {.
2239c2239
<   result.impl = hb_ft_face_create_cached(cast[ptr freetype2.Face00](ftFace.impl))
---
>   result.impl = hb_ft_face_create_cached(cast[freetype2.Face00](ftFace.impl))
2241c2241
< proc hb_ft_face_create_referenced(ftFace: ptr freetype2.Face00): ptr faceT00 {.
---
> proc hb_ft_face_create_referenced(ftFace: freetype2.Face00): ptr faceT00 {.
2246c2246
<   result.impl = hb_ft_face_create_referenced(cast[ptr freetype2.Face00](ftFace.impl))
---
>   result.impl = hb_ft_face_create_referenced(cast[freetype2.Face00](ftFace.impl))
2254c2254
< proc hb_ft_font_create(ftFace: ptr freetype2.Face00; destroy: proc(userData: pointer) {.cdecl.}): ptr fontT00 {.
---
> proc hb_ft_font_create(ftFace: freetype2.Face00; destroy: proc(userData: pointer) {.cdecl.}): ptr fontT00 {.
2259c2259
<   result.impl = hb_ft_font_create(cast[ptr freetype2.Face00](ftFace.impl), destroy)
---
>   result.impl = hb_ft_font_create(cast[freetype2.Face00](ftFace.impl), destroy)
2261c2261
< proc hb_ft_font_create_referenced(ftFace: ptr freetype2.Face00): ptr fontT00 {.
---
> proc hb_ft_font_create_referenced(ftFace: freetype2.Face00): ptr fontT00 {.
2266c2266
<   result.impl = hb_ft_font_create_referenced(cast[ptr freetype2.Face00](ftFace.impl))
---
>   result.impl = hb_ft_font_create_referenced(cast[freetype2.Face00](ftFace.impl))

The other modules remain unchanged, so I have not done further testings.

Another question is, if we should try to make all the harfbuzz data types starting with upper case. But I think I will not try that this year, maybe next. You may try that your own, should be not difficult. maybe some work. And may result in new trouble of course.

I think I will tag this latest release as v0.99 soon, before other do a plain "nimble install gintro" and get the same trouble. Problem is, that then next tag is already 1.0, and I hesitate to call it already a 1.0 version.

@licoricee
Copy link
Author

Oh ok I'm on vacation now so I can't test it :/ but thanks for your help! As soon as I get back I'll be sure to test it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants