From mboxrd@z Thu Jan 1 00:00:00 1970 From: Danny Milosavljevic Subject: Binding generator, for Guile, to C libraries Date: Mon, 3 Jul 2017 01:30:35 +0200 Message-ID: <20170703013035.47d47177@scratchpost.org> References: <20170627221608.A23B52013B@smtp.hushmail.com> <20170628154943.36021286@scratchpost.org> <20170629132246.9E3F92013A@smtp.hushmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dRoKG-0003hB-13 for guix-devel@gnu.org; Sun, 02 Jul 2017 19:30:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dRoKA-0004ry-Sp for guix-devel@gnu.org; Sun, 02 Jul 2017 19:30:47 -0400 Received: from dd1012.kasserver.com ([85.13.128.8]:48242) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dRoKA-0004qi-LB for guix-devel@gnu.org; Sun, 02 Jul 2017 19:30:42 -0400 In-Reply-To: <20170629132246.9E3F92013A@smtp.hushmail.com> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: cinder88@hushmail.com Cc: guix-devel@gnu.org Hi, > >- Currently, the installer invokes the parted executable for > >partitioning which is quite jarring (it looks very different). It > >would be nice if it just used the parted library. But there's no > >good guile-parted yet. I've started hacking on one and it's > >starting to look OK but it's not done. If you are interested in > >that I can upload it somewhere (github, gitlab etc). > I would be happy to work on this. Okay, I've cleaned up what I have and put it on github, under: https://github.com/daym/guile-gcc-unit What this does is it allows you to read gcc output files which specify all the prototypes - in our case in order to extract the prototypes and generate Guile bindings (of parted, or whatever). The next steps: - Provide the actual binding generator (I started a version of it - I'll commit a cleaned-up version in a few days I guess). - Get it to work with non-toy examples (see file "tests/huge/input" for the parted non-toy example - the goal is to read this file, find all the record decls and all the function decls in it and generate the Guile pendants of them). If you happen to know LALR parsing theory, I have a question :) - Find out whether that can be integrated as a Guile "language". Just being able to do something like ',load "foo.h"' and have it register all the functions from it would be way cool. On the other hand, on non-Guix systems the header files aren't usually installed when the library is installed. So maybe an offline version would be good as well. Example Makefile: --------------------------------------------------- .PHONY: clean all distclean CC = gcc all: parted.lu guile -L . main.scm $^ a.c: echo "#include " > a.c.new && mv a.c.new a.c parted.lu: a.c $(CC) -fsyntax-only -fdump-tree-all-graph=$@ $^ clean: rm -f a.c distclean: clean rm -f parted.lu -------------------------------------------------- To test it, put this file into guile-gcc-unit (as "Makefile") and then invoke "guix package -i parted" and then invoke "make". (I didn't commit it to the repo yet because maybe we can put guile-parted into an extra repo? Or even just have a helper script that does it all without any extra repo?) For the bindings generator, if you want to play with it, what I already can share is: (use-modules (system foreign)) (define-public %parted-library (dynamic-link "/gnu/store/ddpg6rlr5f3xv8fjh8812ll9g584x51z-parted-3.2/lib/libparted")) (define-public enum-_PedPartitionType (make-enumeration '( PED_PARTITION_NORMAL ; 0 PED_PARTITION_LOGICAL ; 1 PED_PARTITION_EXTENDED ; 2 reserved3 ; 3 PED_PARTITION_FREESPACE ; 4 reserved5 ; 5 reserved6 ; 6 reserved7 ; 7 PED_PARTITION_METADATA ; 8 reserved9 reserved10 ; 10 reserved11 ; 11 reserved12 ; 12 reserved13 ; 13 reserved14 ; 14 reserved15 ; 15 PED_PARTITION_PROTECTED ; 16 ))) (define-public long-long uint64) (define-public PedSector long-long) (define ped_disk_set_partition_geom (pointer->procedure int (dynamic-func "ped_disk_set_partition_geom" %parted-library) '* '* '* PedSector PedSector)) So that's the kind of code that should be generated in the end (not sure whether in Tree-IL or whether to go via the Scheme intermediary). For the binding generator, I'm thinking of having a global hashtable containing what symbols are known from C header files - and what is known about them. So (hypothetical) usage would be like: ; Magically registers all the external function declarations in some global hashtable (only the declarations, no shared object) ,load "parted/parted.h" (define-public %parted-library (dynamic-link "/gnu/store/ddpg6rlr5f3xv8fjh8812ll9g584x51z-parted-3.2/lib/libparted")) (define ped_disk_set_partition_geom (dynamic-callable-func "ped_disk_set_partition_geom" %parted-library)) (ped_disk_set_partition_geom ...) Wouldn't that be cool? If that's too lowlevel, check out guix wip-installer and try using gurses, John's ncurses frontend. The installer is under "gnu/system/installer/" :) We eventually would like to have a nice partitioning interface in the installer. So if you'd like to you can also add some pages there. In order to do that, see gnu/system/installer/guixsd-installer.scm . It contains the list of pages that are used in the installer. You can add your own pages there. See gnu/system/installer/mount-point.scm for a simple page.