atilaneves / dpp

Directly include C headers in D source code
Boost Software License 1.0
230 stars 31 forks source link

Symbols missing for gtk #240

Closed andre2007 closed 4 years ago

andre2007 commented 4 years ago

I have this dockerfile

FROM dlang2/ldc-ubuntu:1.19.0 as base

RUN apt-get update && apt-get upgrade -y \
    && apt-get install -y clang-9 libclang-9-dev libgtk-3-dev libgtk-3-0 \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN ln -s /usr/bin/clang-9 /usr/bin/clang

COPY gtk.dpp /tmp/

RUN DFLAGS="-L=-L/usr/lib/llvm-9/lib/" dub run dpp -- /tmp/gtk.dpp \
    --include-path /usr/include/gtk-3.0 \
    --include-path /usr/include/glib-2.0 \
    --include-path /usr/include/pango-1.0 \
    --include-path /usr/include/cairo \
    --include-path /usr/include/gdk-pixbuf-2.0 \
    --include-path /usr/include/atk-1.0 \
    --include-path /usr/lib/x86_64-linux-gnu/glib-2.0/include \
    --preprocess-only

and this gtk.dpp file

#include <gtk/gtk.h>

The resulting file gtk.d is missing several symbols like

The C example is working fine and find all symbols:

#include <gtk/gtk.h>

static void
activate (GtkApplication* app,
          gpointer        user_data)
{
  GtkWidget *window;

  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
  gtk_widget_show_all (window);
}

int
main (int    argc,
      char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}
atilaneves commented 4 years ago

All 4 of your examples are macros, not symbols. They don't show up in the resulting D file, they get expanded before the D file is even generated. In fact, with your example I couldn't even get a D file, the C preprocessor failed before that on the translated file.

andre2007 commented 4 years ago

The Dockerfile was working fine on my side, DPP was able to translate this DPP file except the macros.

#include <gtk/gtk.h>

But it takes around 7 minutes to translate.

The C example I translated to D and replaced the Macros with symbols like GtkWindow, GApplication...

The GtkApplication was compiling and running fine and using Gtk Broadway it was even running within a browser using HTML5 rendering (therefore the docker example).

I will check again the example above wheter it is still running on my side or I can reproduce the C pre processor error.

andre2007 commented 4 years ago

Attached docker file I am able to build and run docker build -t t7 . docker run -p 8889:8889 t7

dpp.zip

I am not sure, should the macros be available in the generated D module?

atilaneves commented 4 years ago

I am not sure, should the macros be available in the generated D module?

No. They're available in the .dpp file itself, which gets fed to the C preprocessor, which then produces a valid D file. The flow is gtk.dpp -> gtk.d.tmp (includes get expanded and translated) -> cpp gtk.d.tmp -> gtk.d