guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help adding a python package: chia-blockchain


From: Leo Prikler
Subject: Re: Help adding a python package: chia-blockchain
Date: Sat, 17 Apr 2021 03:20:17 +0200
User-agent: Evolution 3.34.2

Hi Vladilen,

Am Freitag, den 16.04.2021, 09:57 +0100 schrieb Vladilen Kozin:
> Hi all.
> 
> Could a kind soul handhold me while I try to port a python package to
> guix please. I am not a python programmer, so not on first name basis
> with python ecosystem and new to guix - double trouble.
> 
> I've made some progress, but could use a bit of your help. Current
> state of affairs is tracked in this repo:
> https://github.com/vkz/ze-guix

Some comments on what you've written so far:

;; wtf? surely we don't need that on Linux
Probably not, yeah.  If you want to, you can substitute* references to
that package away.
;; can we just skip these since this is only for testing?
Yes, but you'll have to disable tests :)

Otherwise mostly LGTM.

> Repo and package I'm trying to import:
> https://github.com/Chia-Network/chia-blockchain
> 
> Both it and all of its dependencies are open source, most on pypi but
> sadly some are only available there as binary wheels. Building from
> source entirely maybe complicated since it very quickly escalates to
> multiple build systems e.g. chiapos (proof of space lib) and chiavdf
> are C++ and rely on cmake, clvm_rs (their homegrown lisp) is written
> in Rust etc.
They have thought about writing a Lisp implementation in Rust, but has
anyone thought about writing a Rust compiler in Lisp?  Perhaps it could
even output shared objects, that'd be nice.  Jokes aside, let's
continue.

> Conceptually, installation is very simple and basically relies on
> binary wheels and amounts to:
> - checkout repo,
> - init and update submodule(s) - really only mozilla-ca,
> - create virtual env and activate,
> - upgrade to the latest pip to use binary wheels,
> - install deps and the package with pip
> 
> You can see the steps I extracted from their install.sh here:
> https://github.com/vkz/ze-guix/blob/master/packages/manual-install.log
> 
> Now, guix obviously heads and shoulders above virtualenv or at least
> it should be, however trying to build from source escalates quickly
> as
> I've mentioned. So, first question is if I could define a package by
> "replicating" the above essentially binary-only steps but replace
> virtualenv with e.g. guix profile or smth. This should be possible to
> do in code - as a proper package with some rudimentary build system
> that amounts to building everything inside a separate profile or
> maybe
> just pulling binary wheels into a directory in store and then adding
> that to whatever Python or pip expect and use as their PATH
> equivalent. IMO doing something trivial like this should be easy. To
> be sure this approach has security and "freedom" implications, but
> this is orthogonal to having something that works installed quickly.
> Building from source is very often involved borderline crazy. Could
> someone kindly teach me how to do this "binary" only packaging.
We have copy-build-system and a tool called patchelf.  Some folks, who
don't care as much about freedom as we do might even go ahead and
implement a patchelf-build-system, but that's a little besides the
point.  If you feel like fiddling around in those binaries will be
quicker than mixing build systems, that's pretty much the approach you
would take, but it's not an easy one.

> Now, to building from source.
> 
> First step I tried was to `guix import pypi -r`. This fails because
> not all deps have source pushed to pypi and only offer binary wheels.
> IMO `guix import` has no business failing like this or even at all
> for
> whatever reason. It is best effort tool to begin with that should
> result in a template that I can fill in. If there are errors - skip
> the dependency, report it, but please continue.
I don't think this works as a general statement.  While UX probably
could be improved in certain scenarios, sometimes an error really is an
error and stopping is the right decision.

> Since, recursive `guix import` failed me I had to manually track deps
> and essentially call `guix import` for each one. Result you can see
> here:
> https://github.com/vkz/ze-guix/blob/master/packages/chia.scm
> 
> This won't build for several reasons. Not all deps are there, some
> probably shouldn't be like win32 something or other. Another reason,
> I'd have to figure out how to build the inputs that require cmake and
> rust and python (some all at once). And this is where I could really
> use help. Examples as mentioned earlier are these dependencies:
> https://github.com/Chia-Network/chiapos
> https://github.com/Chia-Network/clvm_rs
> maybe others - it is a fairly big project and I've not even touched
> NPM/node that they rely on for their GUI client. That's another scary
> can of worms I'm not prepared to peek inside at this time.
This indeed sounds like a very daunting project.  Rest assured, even
the most advanced packagers usually shy away from such beasts.  (And
those who don't typically sacrifice part of their sanity.)

Now in principle, mixing build systems is *easy*.  Starting from
(arguments), you add:
- #:modules, that list both build systems, usually prefixed (e.g. gnu:
and cmake:)
- #:imported-modules, that hold the module closure for both (this can
be achieved by listing ,@%gnu-build-system-modules ,@%cmake-build-
system-modules and some others, for example)
- #:phases, that call the right procedures in the correct order.

A fairly simple package, that uses two build systems, is emacs-howm. 
After wip-emacs is merged, you have even more examples of emacs
packages mixing build systems for trivial stuff, since that's how I
chose to implement ELPA directories.  I'm getting sidetracked again.

Once you start seeing this pattern, you'll notice it in other packages
as well.  To search for packages, that use cmake in combination with
something else, grepping for cmake: is a good idea.  Likewise with
cargo: for Rust packages.

> Ok, so really two questions:
> - how can I build a "binary" only python package that simply relies
> on
> binary wheels e.g. from pypi,
By using a clever mix of "cp" and "patchelf" or their lisp equivalents.

> - how to deal with multi-build systems e.g. python + cmake or python
> +
> rust, maybe someone could think of a good educational (so, not too
> convoluted) example of such package already in source tree.
You can't get much shorter than emacs-howm.

> Latter would probably go much faster and teach better if done as
> pair-programming exercise, but that maybe a lot to ask. If you're up
> for it, I'm game though.
I'm sorry, it's rather late and I should probably go to bed, but as far
as contributing packages with huge dependency chains goes, there seem
to be somewhat regular meetups done; perhaps someone else has more
appropriate info for you.  Lastly, if the dependencies themselves have
a use other than being a dependency for what you're trying to package,
you could garner some interest by sending one of them, that already
builds fine, to guix-patches.  Though perhaps that "if" is a little too
big to be applicable here.

In any case, have fun mixing build systems and don't get too
discouraged by the huge load of work that's ahead of you.

Regards,
Leo





reply via email to

[Prev in Thread] Current Thread [Next in Thread]