From 594a3819ada0d622e0afa3c55109870fee72d07d Mon Sep 17 00:00:00 2001 From: sunder Date: Mon, 17 Jul 2023 08:53:30 +0300 Subject: [PATCH] gi-crystal: init at 0.17.0 --- pkgs/development/tools/gi-crystal/default.nix | 42 ++++++++++++++ pkgs/development/tools/gi-crystal/src.patch | 57 +++++++++++++++++++ .../store-friendly-library-name.patch | 10 ++++ pkgs/top-level/all-packages.nix | 2 + 4 files changed, 111 insertions(+) create mode 100644 pkgs/development/tools/gi-crystal/default.nix create mode 100644 pkgs/development/tools/gi-crystal/src.patch create mode 100644 pkgs/development/tools/gi-crystal/store-friendly-library-name.patch diff --git a/pkgs/development/tools/gi-crystal/default.nix b/pkgs/development/tools/gi-crystal/default.nix new file mode 100644 index 000000000000..eee07206a2a1 --- /dev/null +++ b/pkgs/development/tools/gi-crystal/default.nix @@ -0,0 +1,42 @@ +{ lib +, fetchFromGitHub +, crystal +, gobject-introspection +}: +crystal.buildCrystalPackage rec { + pname = "gi-crystal"; + version = "0.17.0"; + + src = fetchFromGitHub { + owner = "hugopl"; + repo = "gi-crystal"; + rev = "v${version}"; + hash = "sha256-DIH8L8P8lkWzzVUj1Tbf9oTUvu9X7OT66APyUHiDkYk="; + }; + + # Make sure gi-crystal picks up the name of the so or dylib and not the leading nix store path + # when the package name happens to start with “lib”. + patches = [ ./src.patch ./store-friendly-library-name.patch ]; + + nativeBuildInputs = [ gobject-introspection ]; + buildTargets = [ "generator" ]; + + doCheck = false; + doInstallCheck = false; + + installPhase = '' + runHook preInstall + + mkdir $out + cp -r * $out + + runHook postInstall + ''; + + meta = with lib; { + description = "GI Crystal is a binding generator used to generate Crystal bindings for GObject based libraries using GObject Introspection."; + homepage = "https://github.com/hugopl/gi-crystal"; + mainProgram = "gi-crystal"; + maintainers = with maintainers; [ sund3RRR ]; + }; +} diff --git a/pkgs/development/tools/gi-crystal/src.patch b/pkgs/development/tools/gi-crystal/src.patch new file mode 100644 index 000000000000..eb18035f9941 --- /dev/null +++ b/pkgs/development/tools/gi-crystal/src.patch @@ -0,0 +1,57 @@ +--- a/src/generator/main.cr 2023-07-14 18:30:47.687581729 +0300 ++++ b/src/generator/main.cr 2023-07-17 07:55:24.177630085 +0300 +@@ -1,6 +1,8 @@ + require "colorize" + require "log" + require "option_parser" ++require "file" ++require "file_utils" + + require "./binding_config" + require "./error" +@@ -43,7 +45,7 @@ + end + end + +- output_dir = Path.new(project_dir, "lib/gi-crystal/src/auto").normalize if output_dir.nil? ++ output_dir = Path.new(Dir.current, "lib/gi-crystal/src/auto").normalize if output_dir.nil? + extra_bindings = argv.map { |path| Path.new(path).expand.to_s } + + {output_dir: output_dir, +@@ -74,11 +76,23 @@ + end + end + +-private def find_bindings : Array(String) +- find_pattern = Path.new(project_dir, "**/binding.yml").normalize ++private def find_bindings_yml(path) : Array(String) ++ find_pattern = File.join(path, "**/binding.yml") + Dir[find_pattern] + end + ++private def find_bindings : Array(String) ++ current_directory = Dir.current ++ ++ bindings = find_bindings_yml(current_directory) ++ Dir.glob(File.join(current_directory, "**/*")).each do |path| ++ if File.symlink?(path) ++ bindings += find_bindings_yml(path) ++ end ++ end ++ bindings ++end ++ + private def format_files(dir) + # We need to chdir into output dir since the formatter ignores everything under `lib` dir. + Dir.cd(dir) { `crystal tool format` } +@@ -102,7 +116,9 @@ + Log.info { "Generating bindings at #{options[:output_dir]}" } + + Generator::DocRepo.disable! unless options[:doc_gen] +- ++ ++ FileUtils.cp_r(project_dir, File.join(Dir.current, "lib/gi-crystal")) ++ + binding_yamls = find_bindings.concat(options[:extra_bindings]) + binding_yamls.each do |file| + Log.info { "Using binding config at #{file}" } diff --git a/pkgs/development/tools/gi-crystal/store-friendly-library-name.patch b/pkgs/development/tools/gi-crystal/store-friendly-library-name.patch new file mode 100644 index 000000000000..c6fd4e18c8db --- /dev/null +++ b/pkgs/development/tools/gi-crystal/store-friendly-library-name.patch @@ -0,0 +1,10 @@ +--- a/src/generator/lib_gen.cr 1969-12-31 17:00:01.000000000 -0700 ++++ b/src/generator/lib_gen.cr 2023-07-14 11:48:41.509397114 -0600 +@@ -10,7 +10,7 @@ + + private def libraries : Array(String) + namespace.shared_libraries.map do |library| +- library[/lib([^\/]+)\.(?:so|.+?\.dylib).*/, 1] ++ library[/(?:\/[^\/]*)+\/lib([^\/]+)\.(?:so|.+?\.dylib).*/, 1] + end + end \ No newline at end of file diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index ae7e3454538e..398f540dcd4e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -8117,6 +8117,8 @@ with pkgs; ghz = callPackage ../tools/networking/ghz { }; + gi-crystal = callPackage ../development/tools/gi-crystal { }; + gibberish-detector = with python3Packages; toPythonApplication gibberish-detector; gibo = callPackage ../tools/misc/gibo { };