diff --git a/meson-tutorial-gtk/glade-example-main.c b/meson-tutorial-gtk/glade-example-main.c new file mode 100644 index 0000000..6cf30b3 --- /dev/null +++ b/meson-tutorial-gtk/glade-example-main.c @@ -0,0 +1,52 @@ +#include + +// Roughly following https://prognotes.net/2016/03/gtk-3-c-code-hello-world-tutorial-using-glade-3/ + +GtkWidget *g_label_hello; +GtkWidget *g_button_count; + +void on_button_hello_clicked() +{ + static unsigned int count = 0; + char str_count[30] = {0}; + + count++; + snprintf(str_count, 30, "%d", count); + gtk_label_set_text(GTK_LABEL(g_label_hello), str_count); +} + +// called when window is closed +void on_window_main_destroy() +{ + gtk_main_quit(); +} + +int main(int argc, char **argv) +{ + GtkBuilder *builder; + GtkWidget *window; + + gtk_init(&argc, &argv); + + builder = gtk_builder_new(); + GError *error = NULL; + if (0 == gtk_builder_add_from_file(builder, "glade-example.glade", &error)) + { + g_printerr("Error loading file: %s\n", error->message); + g_clear_error(&error); + return 1; + } + + window = GTK_WIDGET(gtk_builder_get_object(builder, "window_main")); + gtk_builder_connect_signals(builder, NULL); + + // get pointers to the two labels + g_label_hello = GTK_WIDGET(gtk_builder_get_object(builder, "label_hello")); + + g_object_unref(builder); + + gtk_widget_show(window); + gtk_main(); + + return 0; +} diff --git a/meson-tutorial-gtk/glade-example.glade b/meson-tutorial-gtk/glade-example.glade new file mode 100644 index 0000000..31debc4 --- /dev/null +++ b/meson-tutorial-gtk/glade-example.glade @@ -0,0 +1,63 @@ + + + + + + window_main + False + + + True + False + + + button + True + True + True + + + + 0 + 0 + + + + + True + False + label + + + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/meson-tutorial-gtk/gtkmain.c b/meson-tutorial-gtk/gtkmain.c new file mode 100644 index 0000000..22a78e3 --- /dev/null +++ b/meson-tutorial-gtk/gtkmain.c @@ -0,0 +1,22 @@ +#include + +void button_event(GtkWidget *widget, gpointer *data) { + g_print("Button clicked\n"); + gtk_button_set_label(GTK_BUTTON(widget), "It worked!"); +} + +int main(int argc, char **argv) { + GtkWidget *win; + gtk_init(&argc, &argv); + win = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(win), "Hello there"); + g_signal_connect(win, "destroy", G_CALLBACK(gtk_main_quit), NULL); + + GtkWidget *button = gtk_button_new_with_mnemonic("_Click me!"); + gtk_widget_show(button); + g_signal_connect(button, "pressed", G_CALLBACK(button_event), NULL); + gtk_container_add(GTK_CONTAINER(win), button); + + gtk_widget_show(win); + gtk_main(); +} diff --git a/meson-tutorial-gtk/main.c b/meson-tutorial-gtk/main.c new file mode 100644 index 0000000..0b590d1 --- /dev/null +++ b/meson-tutorial-gtk/main.c @@ -0,0 +1,6 @@ +#include + +int main(int argc, char **argv) { + printf("Hello there.\n"); + return 0; +} diff --git a/meson-tutorial-gtk/meson.build b/meson-tutorial-gtk/meson.build new file mode 100644 index 0000000..80b912b --- /dev/null +++ b/meson-tutorial-gtk/meson.build @@ -0,0 +1,11 @@ +project('tutorial', 'c') +# project('tutorial', 'c', default_options: ['c_link_args=-static']) + +# executable('demo', 'main.c') +executable('demo', 'main.c', link_args: '-static', install: true) + +gtkdep = dependency('gtk+-3.0', static: true) + +executable('demo-gtk', 'gtkmain.c', dependencies: gtkdep, install: true, link_args: '-static') + +executable('demo-glade', 'glade-example-main.c', dependencies: gtkdep, install: true, link_args: '-static') diff --git a/nixpkgs b/nixpkgs index 5e6603f..112769e 160000 --- a/nixpkgs +++ b/nixpkgs @@ -1 +1 @@ -Subproject commit 5e6603fbba334804beaad21c9859a7a4347c1242 +Subproject commit 112769e0c8ad9a39cb0385b8ca1676363de6ee4e diff --git a/nixpkgs.nix b/nixpkgs.nix index fa641d6..cfafb35 100644 --- a/nixpkgs.nix +++ b/nixpkgs.nix @@ -13,4 +13,4 @@ if builtins.getEnv "STATIC_HASKELL_NIX_CI_NIXPKGS_UNSTABLE_BUILD" == "1" if builtins.pathExists ./nixpkgs/pkgs then import ./nixpkgs {} # Pinned nixpkgs version; should be kept up-to-date with our submodule. - else import (fetchTarball https://github.com/nh2/nixpkgs/archive/5e6603fbba334804beaad21c9859a7a4347c1242.tar.gz) {} + else import (fetchTarball https://github.com/nh2/nixpkgs/archive/11aa987ea5b5a593c9ca7a38b391804959f905e5.tar.gz) {} diff --git a/survey/default.nix b/survey/default.nix index 15354e6..d899a05 100644 --- a/survey/default.nix +++ b/survey/default.nix @@ -614,10 +614,17 @@ let "--enable-static" ]; }); - cairo = previous.cairo.overrideAttrs (old: { dontDisableStatic = true; }); + cairo = (previous.cairo.overrideAttrs (old: { dontDisableStatic = true; })).override { + # Disabling OpenGL support for now because I don't know if statically + # linking it is possible (it may depend on the hardware). + libGLSupported = false; + glSupport = false; + }; libpng = previous.libpng.overrideAttrs (old: { dontDisableStatic = true; }); libpng_apng = previous.libpng_apng.overrideAttrs (old: { dontDisableStatic = true; }); libpng12 = previous.libpng12.overrideAttrs (old: { dontDisableStatic = true; }); + libtiff = previous.libtiff.overrideAttrs (old: { dontDisableStatic = true; }); + libwebp = previous.libwebp.overrideAttrs (old: { dontDisableStatic = true; }); expat = previous.expat.overrideAttrs (old: { dontDisableStatic = true; }); @@ -637,20 +644,65 @@ let keyutils = previous.keyutils.overrideAttrs (old: { dontDisableStatic = true; }); - libxcb = previous.xorg.libxcb.overrideAttrs (old: { dontDisableStatic = true; }); - libX11 = previous.xorg.libX11.overrideAttrs (old: { dontDisableStatic = true; }); - libXext = previous.xorg.libXext.overrideAttrs (old: { dontDisableStatic = true; }); - libXinerama = previous.xorg.libXinerama.overrideAttrs (old: { dontDisableStatic = true; }); - libXrandr = previous.xorg.libXrandr.overrideAttrs (old: { dontDisableStatic = true; }); - libXrender = previous.xorg.libXrender.overrideAttrs (old: { dontDisableStatic = true; }); - libXScrnSaver = previous.xorg.libXScrnSaver.overrideAttrs (old: { dontDisableStatic = true; }); - libXau = previous.xorg.libXau.overrideAttrs (old: { dontDisableStatic = true; }); - libXdmcp = previous.xorg.libXdmcp.overrideAttrs (old: { dontDisableStatic = true; }); + dbus = previous.dbus.overrideAttrs (old: { dontDisableStatic = true; }); + utillinuxMinimal = previous.utillinuxMinimal.overrideAttrs (old: { dontDisableStatic = true; }); + + # Note that the addition of `xorg.*` packages to the global + # package set available to derivation (`callPackage`) arguments + # is set up here: + # https://github.com/NixOS/nixpkgs/blob/9a2c7caa43f1cb83b3efd156de35aea85196f32f/pkgs/top-level/splice.nix#L125-L132 + # According to `clever`, the right place to override them should + # be inside `xorg` and then the top-level ones should be + # overridden automatically. + # + # Btw, creating overridable scopes works like this: + # https://github.com/cleverca22/nix-tests/blob/22a32a1c43162817dba0cd9dd6f2b35590582e63/kexec/simple-test.nix#L52 + xorg = previous.xorg.overrideScope' (final_xorg: previous_xorg: + lib.mapAttrs + (name: value: value.overrideAttrs (old: { dontDisableStatic = true; })) + previous_xorg + ); + epoxy = previous.epoxy.override { + enableStatic = true; + enableEgl = false; + }; + graphite2 = previous.graphite2.override { enableStatic = true; }; + harfbuzz = previous.harfbuzz.override { enableStatic = true; }; + wayland = previous.wayland.override { enableStatic = true; }; + + at-spi2-atk = previous.at-spi2-atk.overrideAttrs (old: { mesonFlags = (old.mesonFlags or []) ++ [ "-Ddefault_library=both" ]; }); + at-spi2-core = previous.at-spi2-core.overrideAttrs (old: { mesonFlags = (old.mesonFlags or []) ++ [ "-Ddefault_library=both" ]; }); + atk = previous.atk.overrideAttrs (old: { mesonFlags = (old.mesonFlags or []) ++ [ "-Ddefault_library=both" ]; }); + fribidi = previous.fribidi.overrideAttrs (old: { mesonFlags = (old.mesonFlags or []) ++ [ "-Ddefault_library=both" ]; }); + gdk-pixbuf = previous.gdk-pixbuf.overrideAttrs (old: { mesonFlags = (old.mesonFlags or []) ++ [ "-Ddefault_library=both" ]; }); + glib = previous.glib.overrideAttrs (old: { mesonFlags = (old.mesonFlags or []) ++ [ "-Ddefault_library=both" ]; }); + libxkbcommon = previous.libxkbcommon.overrideAttrs (old: { mesonFlags = (old.mesonFlags or []) ++ [ "-Ddefault_library=both" ]; }); + pango = previous.pango.overrideAttrs (old: { mesonFlags = (old.mesonFlags or []) ++ [ "-Ddefault_library=both" ]; }); + # mesa_glu = previous.mesa_glu.overrideAttrs (old: { mesonFlags = (old.mesonFlags or []) ++ [ "-Ddefault_library=both" ]; }); + libglvnd = previous.libglvnd.overrideAttrs (old: { mesonFlags = (old.mesonFlags or []) ++ [ "-Ddefault_library=both" ]; }); + + # Changing `shared_library` -> `library` and using `-Ddefault_library=both` + # in mesa did not work for me (still to investigate why), but doing the + # same with `-Ddefault_library=static` worked. + # mesa = previous.mesa.overrideAttrs (old: { mesonFlags = (old.mesonFlags or []) ++ [ "-Ddefault_library=both" ]; }); + mesa = previous.mesa.overrideAttrs (old: { mesonFlags = (old.mesonFlags or []) ++ [ "-Ddefault_library=static" ]; }); + + SDL2 = previous.SDL2.overrideAttrs (old: { dontDisableStatic = true; }); + SDL2_gfx = previous.SDL2_gfx.overrideAttrs (old: { dontDisableStatic = true; }); + SDL2_image = previous.SDL2_image.overrideAttrs (old: { dontDisableStatic = true; }); + SDL2_mixer = previous.SDL2_mixer.overrideAttrs (old: { dontDisableStatic = true; }); + + libjpeg = previous.libjpeg.override (old: { enableStatic = true; }); + libjpeg_turbo = previous.libjpeg_turbo.override (old: { enableStatic = true; }); openblas = previous.openblas.override { enableStatic = true; }; openssl = previous.openssl.override { static = true; }; + # Disabling kerberos support for now, as openssh's `./configure` fails to + # detect its functions due to linker error, so the build breaks, see #68. + openssh = previous.openssh.override { withKerberos = false; }; + krb5 = previous.krb5.override { # Note [krb5 can only be static XOR shared] # krb5 does not support building both static and shared at the same time. @@ -659,6 +711,14 @@ let staticOnly = true; }; + samba4 = previous.samba4.override { + # We haven't figured out how to build samba with Kerberos yet, + # getting the error: + # Checking for gss_display_status : not found + # ERROR: WAF build with MIT Krb5 requires working GSSAPI implementation + enableKerberos = false; + }; + # See comments on `statify_curl_including_exe` for the interaction with krb5! # As mentioned in [Packages that can't be overridden by overlays], we can't # override zlib to have static libs, so we have to pass in `zlib_both` explicitly @@ -692,6 +752,157 @@ let # https://git.alpinelinux.org/aports/tree/community/R/APKBUILD?id=e2bce14c748aacb867713cb81a91fad6e8e7f7f6#n56 doCheck = false; }); + + gtk3 = (previous.gtk3.overrideAttrs (old: { + mesonFlags = (old.mesonFlags or []) ++ [ + # Just `static` doesn't currently work, the `g-ir-scanner` fails during gtk's build then. + "-Ddefault_library=both" + #"-Dintrospection=false" + ]; + })).override (old_gtk3: { + # Wayland requires EGL support for which we have not figured out yet + # whether it can be statically linked. + waylandSupport = false; + }); + + gtk4 = (previous.gtk3.override { + pango = previous.pango.overrideAttrs (old: rec { + pname = "pango"; + version = "1.44.7"; + name = "${pname}-${version}"; + src = normalPkgs.fetchurl { + url = "mirror://gnome/sources/${pname}/${normalPkgs.lib.versions.majorMinor version}/${name}.tar.xz"; + sha256 = "07qvxa2sk90chp1l12han6vxvy098mc37sdqcznyywyv2g6bd9b6"; + }; + patches = []; # https://gitlab.gnome.org/GNOME/pango/merge_requests/38 was upstreamed + outputs = [ "bin" "dev" "out" ]; # "devdoc" fails to produce with newer pango for unknown reason + }); + }).overrideAttrs (old: rec { + # src = final.fetchgit { + src = normalPkgs.fetchgit { + url = "https://gitlab.gnome.org/GNOME/gtk.git"; + rev = "ad48bbb8496d2c3b57fcb4367fd85f7664def0c0"; + sha256 = "10ng8mmfrril1jf499cxmlvxvk46j7wk4d17i169mjw54fb2hv44"; + }; + patches = lib.lists.drop 1 old.patches; + + propagatedBuildInputs = (old.propagatedBuildInputs or []) ++ [ + final.harfbuzz + final.graphene + ]; + + postPatch = '' + files=( + build-aux/meson/post-install.py + demos/gtk-demo/geninclude.py + gdk/broadway/gen-c-array.py + gdk/gen-gdk-gresources-xml.py + gtk/gen-gtk-gresources-xml.py + gtk/gentypefuncs.py + ) + + chmod +x ''${files[@]} + patchShebangs ''${files[@]} + ''; + + preConfigure = '' + substituteInPlace gtk/meson.build --replace 'shared_library' 'library' + substituteInPlace testsuite/reftests/meson.build --replace 'shared_library' 'library' + ''; + + mesonFlags = (old.mesonFlags or []) ++ [ + "-Dmedia=none" + "-Dbuild-tests=false" # not needed, just for iteration performance + + "-Ddefault_library=both" + ]; + + # Fixes: + # ../demos/gtk-demo/font_features.c: In function ‘add_instance’: + # ../demos/gtk-demo/font_features.c:883:37: error: format not a string literal and no format arguments [-Werror=format-security] + # instance->name = g_strdup_printf (name); + # ^~~~ + hardeningDisable = [ "format" ]; + + preInstall = '' + export PATH="$PWD/gtk/tools:$PATH" + ''; + postInstall = lib.optionalString (!final.stdenv.isDarwin) '' + # The updater is needed for nixos env and it's tiny. + moveToOutput gtk/tools/gtk4-update-icon-cache "$out" + # Launcher + moveToOutput gtk/tools/gtk4-launch "$out" + + # TODO: patch glib directly + for f in $dev/bin/gtk4-encode-symbolic-svg; do + wrapProgram $f --prefix XDG_DATA_DIRS : "${final.shared-mime-info}/share" + done + ''; + + pname = "gtk4"; + version = "git-2019-11-11"; + postFixup = lib.optionalString (!final.stdenv.isDarwin) '' + demos=(gtk4-demo gtk4-demo-application gtk4-icon-browser gtk4-widget-factory) + + for program in ''${demos[@]}; do + wrapProgram $dev/bin/$program \ + --prefix XDG_DATA_DIRS : "$GSETTINGS_SCHEMAS_PATH:$out/share/gsettings-schemas/${pname}-${version}" + done + ''; + + }); + + meson-tutorial-gtk = final.callPackage ({ + meson, ninja, pkgconfig, gtk3, + pcre_static, + zlib_both, + bzip2_static, + harfbuzz, + libpthreadstubs, + libXdmcp, + utillinuxMinimal, + libselinux, + libsepol, + libxkbcommon, + epoxy, + at-spi2-core, + dbus, + libXtst, + libGL, + mesa, + binutils, + gvfs, # for loading glade files + }: final.stdenv.mkDerivation { + pname = "meson-tutorial-gtk"; + version = "0.0.1"; + src = ../meson-tutorial-gtk; + nativeBuildInputs = [ meson pkgconfig ninja ]; + buildInputs = [ + gtk3 + pcre_static + zlib_both + bzip2_static + harfbuzz + libpthreadstubs + libXdmcp + utillinuxMinimal # for libmount + libselinux + libsepol + libxkbcommon + epoxy + at-spi2-core + dbus + libXtst + libGL + mesa + gvfs + ]; + preConfigure = '' + echo + pkg-config --libs --static gtk+-3.0 + echo + ''; + }) {}; }; @@ -791,6 +1002,13 @@ let enableLibraryProfiling = false; enableExecutableProfiling = false; + # Skip tests on -O0 because some tests are extremely slow on -O0. + # This prevents us from finding upstream correctness issues that + # appear only with -O0, + # such as https://github.com/bos/double-conversion/issues/26 + # but that's OK for now as we want -O0 mainly for faster feedback. + # doCheck = !disableOptimization; + # If `disableOptimization` is on for fast iteration, pass `-O0` to GHC. # We use `buildFlags` instead of `configureFlags` so that it's # also in effect for packages which specify e.g. @@ -938,6 +1156,11 @@ let # focuslist-doctests: focuslist-doctests: unable to load package `ghc-prim-0.5.3' focuslist = dontCheck super.focuslist; + # Fails in doctests with: + # doctests: /nix/store/nda51m9gymbx9qvzmjpfd4393jqq0gdm-ghc-8.6.5/lib/ghc-8.6.5/ghc-prim-0.5.3/HSghc-prim-0.5.3.o: unknown symbol `exp' + # doctests: doctests: unable to load package `ghc-prim-0.5.3' + yesod-paginator = dontCheck super.yesod-paginator; + # Disabling test suite because it takes extremely long (> 30 minutes): # https://github.com/mrkkrp/zip/issues/55 zip = dontCheck super.zip; @@ -1038,6 +1261,63 @@ let [ final.nettle final.bzip2 ] "--libs nettle bz2"; + sdl2-gfx = + addStaticLinkerFlagsWithPkgconfig + super.sdl2-gfx + (with final; [ + nettle + SDL2 + SDL2_gfx + + libX11 + libXext + libXcursor + libXdmcp + libXinerama + libXi + libXrandr + libXxf86vm + libXScrnSaver + libXrender + libXfixes + libXau + libxcb + xorg.libpthreadstubs + ]) + "--libs nettle sdl2 SDL2_gfx xcursor"; + + sdl2-image = + addStaticLinkerFlagsWithPkgconfig + super.sdl2-image + (with final; [ + nettle + SDL2 + SDL2_image + + libX11 + libXext + libXcursor + libXdmcp + libXinerama + libXi + libXrandr + libXxf86vm + libXScrnSaver + libXrender + libXfixes + libXau + libxcb + xorg.libpthreadstubs + + libjpeg + libpng + libtiff + zlib_both + lzma + libwebp + ]) + "--libs nettle sdl2 SDL2_image xcursor libpng libjpeg libtiff-4 libwebp"; + # Added for #14 tttool = callCabal2nix "tttool" (final.fetchFromGitHub { owner = "entropia"; @@ -1068,6 +1348,7 @@ let libXScrnSaver = final.libXScrnSaver; }; + # Note that xmonad links, but it doesn't run, because it tries to open # `libgmp.so.3` at run time. xmonad = @@ -1223,37 +1504,26 @@ in builtins.removeAttrs allStackageExecutables [ # List of executables that don't work for reasons not yet investigated. # When changing this file, we should always check if this list grows or shrinks. - "Agda" - "Allure" - "ALUT" - "clash-ghc" - "csg" - "cuda" # transitively depends on `systemd`, which doesn't build with musl - "debug" - "diagrams-builder" - "ersatz" - "gloss-examples" # needs opengl - "gtk3" # problem compiling `glib` dependency with `Distribution.Simple.UserHooks.UserHooks` type mismatch across Cabal versions; should go away once we no longer have to patch Cabal + "Agda" # anonymous function at build-support/fetchurl/boot.nix:5:1 called with unexpected argument 'meta', at build-support/fetchpatch/default.nix:14:1 + "Allure" # marked as broken + "csg" # marked as broken + "cuda" # needs `allowUnfree = true`; enabling it gives `unsupported platform for the pure Linux stdenv` + "debug" # marked as broken + "diagrams-builder" # marked as broken + "ersatz" # marked as broken + "gloss-examples" # needs opengl: `cannot find -lGLU` `-lGL` + "gtk3" # problem compiling `glib` dependency: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a PIE object "H" # `zgemm_: symbol not found` when compiling Main; not clear how that can be provided "hamilton" # openmp linker error via openblas - "hquantlib" - "ihaskell" - "jack" # transitively depends on `systemd`, which doesn't build with musl - "LambdaHack" + "hquantlib" # marked as broken + "ihaskell" # marked as broken + "LambdaHack" # marked as broken "language-puppet" # dependency `hruby` does not build - "learn-physics" - "leveldb-haskell" - "odbc" # undeclared `` dependency - "OpenAL" # transitively depends on `systemd`, which doesn't build with musl + "learn-physics" # needs opengl: `cannot find -lGLU` `-lGL` + "odbc" # marked as broken "qchas" # openmp linker error via openblas - "rhine-gloss" # needs opengl - "sdl2" # transitively depends on `systemd`, which doesn't build with musl - "sdl2-gfx" # see `sdl2` - "sdl2-image" # see `sdl2` - "sdl2-mixer" # see `sdl2` - "sdl2-ttf" # see `sdl2` - "soxlib" # transitively depends on `systemd`, which doesn't build with musl - "yesod-paginator" # some `curl` build failure; seems to be in *fetching* the source .tar.gz in `fetchurl`, and gss is enabled there even though we tried to disable it + "rhine-gloss" # needs opengl: `cannot find -lGLU` `-lGL` + "soxlib" # dependency `sox` fails with: `formats.c:425:4: error: #error FIX NEEDED HERE` ]; inherit normalPkgs;