Skip to content

Commit

Permalink
Add docs to use with Visual Studio (and link to gtk4-rs book for Rust)
Browse files Browse the repository at this point in the history
It's unclear how to use `gvsbuild` with Visual Studio, especially for
users who aren't used to Windows-based development.

The most-relevant bug I could find was this one [2], but it recommended
using `ninja` and lost me :)

So, I think that having a "hand-off" part at the end of the build docs
that guide users to their language-specific next steps (C, Rust, etc)
could be helpful!

The Visual Studio steps are based off of this 10-year-old Stack Overflow
post [1].

I moved the `LIB` and `INCLUDE` recommendation down since they're
mostly needed for PyGObject.

Finally, I thought that it could be good to recommend setting the
environment variables in the Control Panel instead of
via `$env:Path = ...` so that:
* It would be persistent, and
* It would be system-wide (Command Prompt, Powershell, IDEs, etc)

[1] https://stackoverflow.com/questions/15906580/how-to-configure-gtk-on-visual-studio-2010
[2] #405
  • Loading branch information
mitchhentges committed Nov 21, 2023
1 parent 007c34e commit ebd5f8a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
55 changes: 51 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,62 @@ Grab a coffee, the build will take a few minutes to complete.

#### Add GTK to Your Environmental Variables

1. From the Start menu, go to the Control Panel entry for “Edit environment variables for your account”.
2. Double-click the `Path` row in the top list of variables. Click “New” to add a new item to the list.
3. Paste in `C:\gtk-build\gtk\x64\release\bin`
4. Click "OK" twice.

#### Using GTK with Visual Studio

1. Open Visual Studio and "Create a new project" using the "Empty Project" template
2. On the left, right click on "Source Files" and choose "Add", then "New Item..." and replace the name with `main.c`
3. Paste in the following contents, then save the file:

```
#include <gtk/gtk.h>
static void activate_cb(GtkApplication *app) {
GtkWidget *window = gtk_application_window_new(app);
gtk_widget_set_visible(window, true);
}
int main(int argc, char **argv) {
GtkApplication *app =
gtk_application_new("org.app", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect(app, "activate", G_CALLBACK(activate_cb), NULL);
return g_application_run(G_APPLICATION(app), argc, argv);
}
```

4. Go to your project's settings by right-clicking and choosing "Properties"

![screenshot showing the properties item is at the bottom of the context menu](doc/visual-studio-project-context-menu.png)

5. On the left, open "C/C++", then choose "Command Line".
1. Open "Powershell" and run the command `pkg-config --cflags gtk4 --msvc-syntax`
2. Paste the result into the "Additional Options" field at the bottom of the Visual Studio Properties window.

![screenshot showing the "Additional Options" field to modify](doc/visual-studio-properties-c-command-line.png)

6. Still in the Visual Studio window, click on "Linker" and choose "Command Line". Do the same thing as the last step, except use the output of `pkg-config --libs gtk4 --msvc-syntax`
7. Click "OK"
8. In the top menu bar, click "Debug" and "Start Without Debugging"

#### Using GTK with Rust

See [the fantastic `gtk-rs` book](https://gtk-rs.org/gtk4-rs/stable/latest/book).
You can skip the "Install GTK 4" step, as the above steps ^ covered that.

#### Use PyGObject

First, add GTK to your environment variables:

```PowerShell
$env:Path = "C:\gtk-build\gtk\x64\release\bin;" + $env:Path
$env:LIB = "C:\gtk-build\gtk\x64\release\lib;" + $env:LIB
$env:INCLUDE = "C:\gtk-build\gtk\x64\release\include;C:\gtk-build\gtk\x64\release\include\cairo;C:\gtk-build\gtk\x64\release\include\glib-2.0;C:\gtk-build\gtk\x64\release\include\gobject-introspection-1.0;C:\gtk-build\gtk\x64\release\lib\glib-2.0\include;" + $env:INCLUDE
```

#### Use PyGObject

Add the `--enable-gi` and `--py-wheel` options like:
Next, add the `--enable-gi` and `--py-wheel` options like:

```PowerShell
gvsbuild build --enable-gi --py-wheel gtk4 pygobject
Expand Down
Binary file added doc/visual-studio-project-context-menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/visual-studio-properties-c-command-line.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ebd5f8a

Please sign in to comment.