Bug 127179 - [GTK] WebKit2WebExtension GIR can't be used in vala
Summary: [GTK] WebKit2WebExtension GIR can't be used in vala
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Linux
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-17 10:49 PST by Marcel Tiede
Modified: 2014-03-14 10:06 PDT (History)
10 users (show)

See Also:


Attachments
Patch (4.93 KB, patch)
2014-03-01 07:46 PST, Carlos Garcia Campos
no flags Details | Formatted Diff | Diff
Rebased to apply on current git master (5.75 KB, patch)
2014-03-02 07:03 PST, Carlos Garcia Campos
no flags Details | Formatted Diff | Diff
Patch (2.84 KB, patch)
2014-03-10 04:17 PDT, Carlos Garcia Campos
mrobinson: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marcel Tiede 2014-01-17 10:49:19 PST
In Bug https://bugs.webkit.org/show_bug.cgi?id=122407 the GIR-File of WebkitGTK was split into two separate files: WebKit2-3.0.gir and WebKit2WebExtension-3.0.gir.

Compiling the following minimal vala program fails, because it can't read the symbols from the WebKit2WebExtension-3.0.gir:

---
public void Test() {
   WebKit.WebPage p;
}
---

If instead of a WebPage variable a WebView variable ("WebKit.WebView v;") is used in the code, the example compiles fine. The WebView symbol is located in the WebKit2-3.0.gir and the WebPage symbol is located in the WebKit2WebExtension-3.0.gir.

To compile the example as a library I used the following command:

---
valac --pkg WebKit2-3.0 --pkg WebKit2WebExtension-3.0 --pkg gtk+-3.0 --library=MyWebExtension MyWebExtension.vala -X -fPIC -X -shared -o myWebextension.so
---

If the WebKit2-3.0 and WebKit2WebExtension-3.0 packages in the compiler call are swapped, even the WebView is not found anymore. On IRC I got the hint, that the vala compiler can't handle multiple GIR files which use the same package. The compiler only interprets the first occurrence of the line "<package name="webkit2gtk-3.0"/>" in the GIR file. It interprets the occurrence in the second file as duplicate and ignores it: Resulting in missing symbols. This would also explain the behavior of missing WebView symbol if the arguments in the compiler call are swapped.

To solve this issue a second pkg-config file for the WebKit2WebExtension is needed. Alternatively both GIR files could be merged again.
Comment 1 Evan Nemerson 2014-02-10 10:55:33 PST
Just to make the issue a bit clearer:

Vala bindings, unlike G-I, are based on pkg-config packages—there is a 1:1 relationship between a bindings and a pkg-config files, and the name of the VAPI is the same as the pkg-config name.  This allows us to pull in the relevant libs and cflags when people pass --pkg WebKit2-3.0 to valac.

G-I, on the other hand, just dumps the path to the shared object into the GIR.  This is sufficient for them because all they do is dlopen (well, g_module_open) that file—they don't have to worry about additional flags for the CC or linker.

Mostly for us, G-I added the ability to specify the exported pkg-config name in a GIR.  When valac sees a GIR, the first thing it does is look at that pkg-config name to see if it has already parsed a VAPI or GIR for with that name to make sure we haven't already loaded bindings for that library.  If we haven't, we parse the remainder of the GIR.  So, when two GIRs share the same pkg-config name, we parse the first GIR, then see that the name is already taken and skip the second one.

The solutions Marcel mentions are correct.  Either pkg-config files (I guess you would need one each for -2.0 and -3.0) for WekKit2WebExtension, or merge the GIRs.  Personally, I think creating an artificial split in the GIR where none exists at the lower levels is a bit nonsensical, but assuming the backwards-compatibility break from the split isn't an issue for you it doesn't really matter from Vala's perspective which you choose since we didn't ship any bindings from before the split.
Comment 2 Carlos Garcia Campos 2014-03-01 07:46:46 PST
Created attachment 225550 [details]
Patch

Could you guys confirm this is enough for vala to work?
Comment 3 Carlos Garcia Campos 2014-03-02 07:03:24 PST
Created attachment 225593 [details]
Rebased to apply on current git master

I hope cmake changes are correct.
Comment 4 Martin Robinson 2014-03-02 08:49:33 PST
Comment on attachment 225593 [details]
Rebased to apply on current git master

Looks good to me.
Comment 5 Carlos Garcia Campos 2014-03-03 00:02:26 PST
Committed r164973: <http://trac.webkit.org/changeset/164973>
Comment 6 Marcel Tiede 2014-03-07 13:39:19 PST
It's still not working.

If I compile the minimal example I get the following error:

/usr/include/webkitgtk-3.0/webkit2/webkit2.h:22:2: Fehler: #error "Headers <webkit2/webkit2.h> and <webkit2/webkit-web-extension.h> cannot be included together."
 #error "Headers <webkit2/webkit2.h> and <webkit2/webkit-web-extension.h> cannot be included together."
  ^

The header files are not allowing the inclusion of each other. But in the webextension gir there is a dependency to webkit2, this is why vala is doing this exact thing:

"<include name="WebKit2" version="3.0"/>"

Probably this is needed for "WebKit2.URIRequest" in the signal "send-request" of a WebPage.
Comment 7 Evan Nemerson 2014-03-07 13:44:11 PST
We shouldn't need anything else from WebKit to get this working.  We just need to copy URIRequest into the WebExtension vapi so Vala doesn't have to include WebKit2 when it uses WebKit2WebExtension.  It's not going to happen for 0.24 since we're well into the freeze already, but I'll try to get it done early next cycle.
Comment 8 Carlos Garcia Campos 2014-03-10 04:17:22 PDT
Created attachment 226293 [details]
Patch

Could you guys try this patch?
Comment 9 Marcel Tiede 2014-03-12 08:45:26 PDT
Now it compiles fine, thank you.
Comment 10 Evan Nemerson 2014-03-12 09:20:53 PDT
I haven't been able to get WebKit to build from git to test, but doesn't this cause the WepPage::send-request signal to be marked as introspectable="0" in the GIR (and therefore not be exposed in the VAPI)?  I don't know the WebKit API, but I'm told that's a somewhat important signal...
Comment 11 Carlos Garcia Campos 2014-03-12 10:12:22 PDT
(In reply to comment #10)
> I haven't been able to get WebKit to build from git to test, but doesn't this cause the WepPage::send-request signal to be marked as introspectable="0" in the GIR (and therefore not be exposed in the VAPI)?  I don't know the WebKit API, but I'm told that's a somewhat important signal...

No it's not, but it's true that URIRequest and URIResponse parameters of that signal are as WebKit2.URIRequest and WebKit2.URIResponse, I'm not sure if that's a problem, though.
Comment 12 Evan Nemerson 2014-03-13 11:46:54 PDT
Okay, managed to get WebKit built from git.  The patch just creates a second URIRequest (in WebKit2WebExtension) like I was saying we would have to do in Vala, so I'm definitely in favor of it.  With the patch applied I only need one line of metadata to get bindings generated for web extension (and none for WebKit2).
Comment 13 Martin Robinson 2014-03-14 09:42:41 PDT
Comment on attachment 226293 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=226293&action=review

> Source/WebKit2/ChangeLog:9
> +        Do not include WebKit2 gir symbols from WebKit2WebExtension gir
> +        file.

Probably want to say Do not include *all* WebKit2 symbols. If I'm looking at this correctly, you are selectively including WebKitURIRequest.
Comment 14 Carlos Garcia Campos 2014-03-14 10:06:42 PDT
Committed r165625: <http://trac.webkit.org/changeset/165625>