-
Notifications
You must be signed in to change notification settings - Fork 268
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
Custom rust toolchains #667
Conversation
i also considered defining languages.rust.toolchain = pkgs.fenix.stable;
languages.rust.toolchain = pkgs.fenix.fromManifestFile inputs.rustup-manifest;
# depends on https://github.com/nix-community/fenix/pull/108
languages.rust.toolchain = pkgs.fenix.fromToolchainName (importTOML ./rust-toolchain.toml).toolchain.channel; let me know if a different API is desired and I can implement that instead :) Either way, making it easier to use custom toolchains would be awesome |
Have you seen #640 |
i haven't! i'll note that the current implementation of that PR recreates a
My PR addresses both; you may use a pre-existing If @nothingnesses would accept contributions to their PR I'd be glad to merge our work :) |
additionally, that PR cuts out rust components from |
Hi. I'd be happy to work together on this issue, but am not sure if there's anything much I can contribute further. I already like your solution better than mine and agree that recreating a "rust-toolchain.toml" file is undesirable and would prefer a way to just use an existing one (I couldn't figure out a way to do it without having to make a TOML parser). I think your solution would even allow using a different overlay, right? One thing I think I'd change is the default components. I think it'd be better just to stick with the ones included in the default rustup profile, which I've done in my PR. To handle the pre-commit hooks, I just set the components to be the ones from nixpkgs, if they weren't already included in the toolchain options/part of the selected profile; I think you should be able to do something similar to that with you solution. |
ah, i guess that's true! didn't think about that - yeah, https://github.com/oxalica/rust-overlay should work with this design as well
Hm, yeah that should work. I guess I'd like to know if a goal of devenv is to handle language server installation? @domenkozar if you can weigh in here that'd be appreciated. Additionally, I'd like to know if you have any input on the trade-off between only accepting fenix's
yes I could, but I think it's better to use the binary from the
I guess I forgot to change that part in this PR, I'll use the bin directory of the built |
it seems gleam and ruby both have hard-dependencies on external inputs, but nonetheless I think I made a flexible API, defining both |
Is it ready for review? |
not quite yet - i tried to use this in a project but didn't have time to dig into failures. i'll have time to take care of this in a few days - i'll ping back here when it works and it's ready for review. |
but i'll note this is one of the more complex nix modules i've written, any input on its current state/design would be appreciated :) |
Maybe we should add that as a comment?
…On Sun, Jul 2, 2023, 21:11 Simon Žlender ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/modules/languages/rust.nix
<#667 (comment)>:
> - env.RUST_SRC_PATH = cfg.packages.rust-src;
-
RUST_SRC_PATH is necessary when rust-src is not at the same location as
as rustc. This is the case with the rust toolchain from nixpkgs. You'll
run into this issue when using rust-analyzer in vscode.
—
Reply to this email directly, view it on GitHub
<#667 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA63A5EF5Y7O3VRZL2WMT3XOHIYDANCNFSM6AAAAAAZI3XGJ4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I'm really tempted to just implement using
|
Try with Either way though I feel like supporting cross-compilation is a bit much for this PR. I don't have experience with WASM, so maybe that's simpler. But getting other targets to work is far move involved than just installing the target So if someone with more experience can chip in to make a limited set of targets working, that would be great. But I don't think it should be a blocker. |
env.RUST_SRC_PATH = | ||
if cfg.toolchain ? rust-src | ||
then "${cfg.toolchain.rust-src}/lib/rustlib/src/rust/library" | ||
else pkgs.rustPlatform.rustLibSrc; |
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.
If it makes things easier, we only really need this for "nixpkgs" (as long as rust-src is in components when fenix is used).
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.
we only really need this for "nixpkgs"
i don't think that's true:
enable = true;
toolchain.rust-std = my-fenix-toolchain.rust-std;
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.
Actually I just checked the docs so I may be wrong on this. Mixed it up with rust-overlay. I would leave it as 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.
for clarity, when you say "leave it as is" you mean my current if-expression is fine?
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.
It's rust-src
in this instance. But yeah, I may be wrong here, sorry.
yeah, i'll leave extra targets as a non-blocker for this. if the user wants to accomplish this, they might be able to do so by either adding a i think this use-case is perhaps better solved by using devenv in a nix flake instead of as a standalone tool to only have to evaluate nixpkgs once |
I was actually hoping for this. :'( We're cross compiling against aarch64-unknown-linux-gnu on x86_64-unknown-linux-gnu in CI but for the system platform on the developer's machine. I'm not too familiar with Nix, but perhaps there's a better way? |
sounds like you want to make it an output in a flake. look at fenix docs for an example of how to accomplish this. alternatively, you can try my suggestions above |
Like @cdmistman said, something like this might work, but I can't test cause I'd need to bootstrap gcc from source: packages = [ <fenix>.targets.aarch64-unknown-linux-gnu.stable.rust-std ];
env.CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER =
let
inherit (pkgs.pkgsCross.aarch64-multiplatform.stdenv) cc;
in
"${cc}/bin/${cc.targetPrefix}cc"; Though this will break as soon as you have to link with any C dependencies. |
LGTM, great job on this! A bit suprised something like |
yeah, I had thought the same as well - quite disappointing that |
Could you also change |
i didn't update the documentation - afaict, the docs get auto-updated but i couldn't rebuild them on my machine (aarch64-darwin, can't find libcairo). it seems GHA might rebuild them anyways |
i have to update the PR description and want to do a little more testing. I'm about to get on a flight but I'll be able to do all of that late tonight/tomorrow morning PST (depending on how i'm feeling tonight) |
updated the PR description and hopefully fixed failing CI (for rust - not going to fix if CI passes/no more feedback should be good to merge! |
Could you also add rename hints for all the changed options?
|
Great work, thank you for the patience with reviews :) |
I wonder if it also fixes #662 by any chance? |
Just leaving this here for anybody who wants to get devenv working with rust wasm. in inputs:
nixpkgs:
url: github:NixOS/nixpkgs/nixpkgs-unstable
fenix:
url: github:nix-community/fenix
inputs:
nixpkgs:
follows: nixpkgs
rust-overlay:
url: github:oxalica/rust-overlay
overlays:
- default and in ...
let
rustVersion = pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default);
in
...
languages = {
rust = {
enable = true;
toolchain.rustc = (rustVersion.override {
extensions = [ "rust-src" ];
targets = [ "wasm32-unknown-unknown" ];
});
};
};
... |
Or for anyone using Flakes, Fenix and a toolchain file: {
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
systems.url = "github:nix-systems/default";
fenix.url = "github:nix-community/fenix";
};
outputs = { self, nixpkgs, devenv, systems, fenix, ... } @ inputs:
let
system = builtins.currentSystem;
pkgs = nixpkgs.legacyPackages.${system};
fenixpkgs = fenix.packages.${system};
aarch64-binutils = pkgs.pkgsCross.aarch64-multiplatform.stdenv.cc;
x86_64-binutils = pkgs.pkgsCross.gnu64.stdenv.cc;
in
{
devShell.${system} = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
{
packages = [
pkgs.libunwind
aarch64-binutils
] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin (with pkgs.darwin.apple_sdk; [
frameworks.Security
frameworks.CoreFoundation
x86_64-binutils
]);
languages.rust = {
enable = true;
toolchain.rustc = fenixpkgs.fromToolchainFile { dir = ./.; };
};
}
];
};
};
}
[toolchain]
channel = "1.70.0"
targets = ["x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu"] |
Maybe we could allow setting |
We could, but most targets wont work without a cross stdenv so that's a lot to wire up correctly and most of these toolchains need to be bootstrapped from source which can be hours of compiling, depending on your system. Though you can get pretty far with just cargo zigbuild: https://github.com/rust-cross/cargo-zigbuild |
That's exactly why we should turn it into a flag so that it's not needed to go though that pain. |
Right now using custom
fenix
toolchains (ie, for use withrust-toolchain.toml
) requires duplicating alet
-boundtools
list, which is inconvenient. Further, the rustup components that are installed is fixed, so egmiri
can't be installed without adding it to top-levelpackages
.This change makes it easier to support both use-cases:
components
is now an option and is used in place of thelet
-boundtools
languages.rust.packages
has been renamed tolanguages.rust.toolchain
to be more consistent with rustup's terminology, and now has afreeformType
to allow usage of components that aren't innixpkgs
version
has been renamed tochannel
and is a bit more consistent with rustup's concept of a channelrust-src
component is now properly overridden when defined incomponents
Here's a few examples (using
fenix
as an overlay):