-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
rustPlatform: improve composability when the other builder defines a phase #334476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,34 +1,116 @@ | ||||||
| { | ||||||
| lib, | ||||||
| callPackage, | ||||||
| f, | ||||||
| markdown-mode, | ||||||
| melpaBuild, | ||||||
| nix-update-script, | ||||||
| yasnippet, | ||||||
| fetchFromGitHub, | ||||||
| rustPlatform, | ||||||
| }: | ||||||
|
|
||||||
| let | ||||||
| lspce-module = callPackage ./module.nix { }; | ||||||
| src = fetchFromGitHub { | ||||||
| owner = "zbelial"; | ||||||
| repo = "lspce"; | ||||||
| rev = "fd320476df89cfd5d10f1b70303c891d3b1e3c81"; | ||||||
| hash = "sha256-KnERYq/CvJhJIdQkpH/m82t9KFMapPl+CyZkYyujslU="; | ||||||
| }; | ||||||
| in | ||||||
| melpaBuild { | ||||||
| pname = "lspce"; | ||||||
| inherit (lspce-module) version src meta; | ||||||
| version = "1.1.0-unstable-2024-07-14"; | ||||||
|
|
||||||
| inherit src; | ||||||
|
|
||||||
| packageRequires = [ | ||||||
| f | ||||||
| markdown-mode | ||||||
| yasnippet | ||||||
| ]; | ||||||
|
|
||||||
| # to compile lspce.el, it needs lspce-module.so | ||||||
| files = ''(:defaults "${lib.getLib lspce-module}/lib/lspce-module.*")''; | ||||||
| cargoDeps = rustPlatform.fetchCargoTarball { | ||||||
| inherit src; | ||||||
| hash = "sha256-BMbkdWsVSXRNt8kqOs05376cGnGnivHGvEugX0p3bVc="; | ||||||
| }; | ||||||
|
|
||||||
| nativeBuildInputs = [ | ||||||
| rustPlatform.cargoSetupHook | ||||||
| rustPlatform.cargoBuildHook | ||||||
| rustPlatform.cargoInstallHook | ||||||
| rustPlatform.cargoCheckHook | ||||||
| ]; | ||||||
|
|
||||||
| cargoBuildType = "release"; | ||||||
|
|
||||||
| # Copy the default buildPhase here and switch cd to pushd/popd in | ||||||
| # order to not cause rebuild of other Emacs lisp packages. | ||||||
| buildPhase = '' | ||||||
| runHook preBuild | ||||||
|
|
||||||
| pushd "$NIX_BUILD_TOP" | ||||||
|
|
||||||
| emacs --batch -Q \ | ||||||
| -L "$NIX_BUILD_TOP/package-build" \ | ||||||
| -l "$melpa2nix" \ | ||||||
| -f melpa2nix-build-package \ | ||||||
| $ename $melpaVersion $commit | ||||||
|
|
||||||
| popd | ||||||
|
|
||||||
| runHook postBuild | ||||||
| ''; | ||||||
|
|
||||||
| # Copy the default installPhase here because adding the dynamic | ||||||
| # module to the package tarball needs to be done at a specific time, | ||||||
| # i.e., between cargoInstallHook and elpa2nix-install-package. | ||||||
| # It cannot be done in preInstall because preInstall, as an implicit | ||||||
| # string hook, runs before cargoInstallHook, as a hook in | ||||||
| # preInstallHooks. | ||||||
| installPhase = '' | ||||||
| runHook preInstall | ||||||
|
|
||||||
| archive="$NIX_BUILD_TOP/packages/$ename-$melpaVersion.el" | ||||||
| if [ ! -f "$archive" ]; then | ||||||
| archive="$NIX_BUILD_TOP/packages/$ename-$melpaVersion.tar" | ||||||
| fi | ||||||
|
|
||||||
| echo "add the dynamic module to the package tarball because it is needed for compilation" | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I can't see a reason to echo this info by default.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I slightly prefer logging this info because it is a bit "unusual".
You mean things like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| # rename module without changing suffix | ||||||
| # use for loop because there seem to be two modules on darwin systems | ||||||
| # https://github.com/zbelial/lspce/issues/7#issue-1783708570 | ||||||
| tmp_content_directory=$ename-$melpaVersion | ||||||
| mkdir $tmp_content_directory | ||||||
| for f in $out/lib/*; do | ||||||
| mv --verbose $f $tmp_content_directory/lspce-module.''${f##*.} | ||||||
| tar --verbose --append --file=$archive $tmp_content_directory/lspce-module.''${f##*.} | ||||||
| done | ||||||
| rmdir --verbose $out/lib | ||||||
| unset tmp_content_directory | ||||||
|
|
||||||
| emacs --batch -Q \ | ||||||
| -l "$elpa2nix" \ | ||||||
| -f elpa2nix-install-package \ | ||||||
| "$archive" "$out/share/emacs/site-lisp/elpa" | ||||||
|
|
||||||
| runHook postInstall | ||||||
| ''; | ||||||
|
|
||||||
| doCheck = true; | ||||||
| cargoCheckType = "release"; | ||||||
| checkFlags = [ | ||||||
| # flaky test | ||||||
| "--skip=msg::tests::serialize_request_with_null_params" | ||||||
| ]; | ||||||
|
|
||||||
| passthru = { | ||||||
| inherit lspce-module; | ||||||
| updateScript = nix-update-script { | ||||||
| attrPath = "emacsPackages.lspce.lspce-module"; | ||||||
| extraArgs = [ "--version=branch" ]; | ||||||
| }; | ||||||
| updateScript = nix-update-script { extraArgs = [ "--version=branch" ]; }; | ||||||
| }; | ||||||
|
|
||||||
| meta = { | ||||||
| homepage = "https://github.com/zbelial/lspce"; | ||||||
| description = "LSP Client for Emacs implemented as a module using Rust"; | ||||||
| license = lib.licenses.gpl3Only; | ||||||
| maintainers = with lib.maintainers; [ AndersonTorres ]; | ||||||
| }; | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thread for #334476 (comment):
@AndersonTorres Could you elaborate why you think it is not clean and what the structural problem is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One problem I see is that the current design of builders does not allow us to move phases. An example is that elisp packages with a Rust module want to do the elisp buildPhase after the Rust buildPhase and installPhase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too subjective and strongly tied to a very particular perception I have.
If I was in a more barebones, Slackware-like distro, I would just manually install the dependencies (Rust compiler, Emacs, libs etc.) and write a shell script that executes a sequence of commands in the pristine, upstream source code.
I would design such a build script in a pipeline fashion.
A rough and not very accurate sketch would be something like this:
On the other hand, when I look to your solution above, it is something similar to having two pipelines, one made for Emacs and other for Rust, disassemble both and amending specific parts of each so that they look externally similar to a Emacs pipeline.
Indeed, stretching the analogy a little bit, you are effectively debasing and polishing the pipes from the Rust pipeline so that they can be more easily amended to other pipes.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is exactly what I am doing here, following the line of work making the Rust builder use setup hooks by @ danieldk. We share the same motivation: #112438.
I would say this is a way to make builders composable with minimal changes.