Skip to content
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

Is it possible for naersk to use stable Rust #100

Closed
wezm opened this issue Apr 10, 2020 · 19 comments · Fixed by #189
Closed

Is it possible for naersk to use stable Rust #100

wezm opened this issue Apr 10, 2020 · 19 comments · Fixed by #189

Comments

@wezm
Copy link

wezm commented Apr 10, 2020

Hi apologies for my naïvety. I'm very new to Nix.

All the instructions I have found so far describe using nightly rust with naersk. I would rather use a release version of stable rust. Is this possible?

I tried removing "-Z" "unstable-options" from cargoOptions but it seems that was there to allow the use of --out-dir. Can the CARGO_TARGET_DIR be used instead?

@nmattia
Copy link
Collaborator

nmattia commented Apr 12, 2020

Hi! Unless you've tweaked the settings, rust stable is used. Those are cargo options, they won't impact the actual compiler. Does that help?

@wezm
Copy link
Author

wezm commented Apr 12, 2020

No sorry, I don't think that's right. Those options only work on nighly versions of cargo:

$ cargo --version
cargo 1.42.0 (86334295e 2020-01-31)

$ cargo -Z unstable-options build
error: the `-Z` flag is only accepted on the nightly channel of Cargo, but this is the `stable` channel
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.

$ cargo build --out-dir foo
error: the `--out-dir` flag is unstable, and only available on the nightly channel of Cargo, but this is the `stable` channel
See https://doc.rust-lang.org/book/appendix-07-nightly-rust.html for more information about Rust release channels.
See https://github.com/rust-lang/cargo/issues/6790 for more information about the `--out-dir` flag.

@lblasc
Copy link

lblasc commented Jun 3, 2020

I hit the same problem when I tried to use stable rust from mozilla-overlay.

  pkgs = import sources.nixpkgs {
    overlays = [
      nixpkgs-mozilla
      (self: super:
          rec {
            rust = (self.rustChannelOf { date = "2020-05-07"; channel = "stable"; }).rust;
            rustc = rust;
            cargo = rust;
            rls = rust;
          }
      )
    ];
  };

@ralsei
Copy link

ralsei commented Jun 11, 2020

Thirding this. Tried:

{ sources ? import ./nix/sources.nix
, pkgs ? import sources.nixpkgs {} }:
let
  rust = import ./nix/rust.nix { inherit sources; };

  naersk = pkgs.callPackage sources.naersk {
    rustc = rust;
    cargo = rust;
  };

  # tell nix-build to ignore the "target" directory
  src = builtins.filterSource
    (path: type: type != "directory" || builtins.baseNameOf path != "target")
    ./.;
in naersk.buildPackage {
  inherit src;
  cargoOptions = v: [];
  cargoBuildOptions = v: [ "$cargo_release" ''-j "$NIX_BUILD_CORES"''
                           "--message-format=$cargo_message_format"];
  cargoBuild = v: ''
    OUT_DIR=out cargo $cargo_options build $cargo_build_options >> $cargo_build_output_json
  '';
  remapPathPrefix = true; # remove nix store refs
}

(where ./nix/rust.nix is stable rust from nixpkgs-mozilla), and got this far:

    Finished release [optimized] target(s) in 47.03s
/nix/store/qghrkvk86f9llfkcr1bxsypqbw1a4qmw-stdenv-linux/setup: eval: line 1329: syntax error near unexpected token `||'
builder for '/nix/store/zrh0165cdhjg715xz3i2xi5r6s0l4fkm-lake-deps-0.2.0.drv' failed with exit code 2
cannot build derivation '/nix/store/8qa3543617i9jm159gp6s5ak9fr5983r-lake-0.2.0.drv': 1 dependencies couldn't be built
error: build of '/nix/store/8qa3543617i9jm159gp6s5ak9fr5983r-lake-0.2.0.drv' failed

There's got to be better ways to do this. As it currently stands, naersk is unusable with stable Cargo.

@jbaum98
Copy link

jbaum98 commented Jul 5, 2020

I also have this issue. I think that the --out-dir flag is unstable according to this, and according to the README that flag is important.

@jbaum98
Copy link

jbaum98 commented Jul 5, 2020

Okay, I figured out a trick: you can override rust to use a version with the mozilla overlay, and leave cargo untouched. Alternatively, I imagine you can override cargo to use a nightly version of cargo in a similar fashion, I haven't tried that yet.

let rustOverlay = self: super:
  let rust = (super.rustChannelOf {
    channel = "1.44.0";
    sha256 = "cc2f6f7515b934457bc537ed181aa04e9a844fa8567f6dae7b9403d1a5a7a09e";
  }).rust; in { rustc = rust; };

@klardotsh
Copy link

Is there any movement on this as far as mainlining some form of stable support? Taking a hard dependency on nightly is something I'd like to avoid in production. (I also can't seem to get @jbaum98's solution working in my project, which uses niv, but I'll keep playing with it)

@nmattia
Copy link
Collaborator

nmattia commented Apr 10, 2021

@klardotsh as mentioned above, I believe this only requires cargo nightly, not rustc nightly. Is this acceptable for you? If there's a big enough need for it I can try to figure out how to do this with cargo stable, please 👍 if you're interested

@paulyoung
Copy link

I'm using flakes and haven't been able to figure out how to use a stable version of the rust toolchain from nixpkgs but use a compatible nightly build version of cargo yet.

I'll post here if I get something that works.

@veehaitch
Copy link

If there's a big enough need for it I can try to figure out how to do this with cargo stable

I also ran into this when switching from nightly to stable. I would appreciate it if I could use the very same version of the rust toolchain during development and packaging, regardless of the rust channel.

@evanjs
Copy link

evanjs commented Jul 9, 2021

If there's a big enough need for it I can try to figure out how to do this with cargo stable

I also ran into this when switching from nightly to stable. I would appreciate it if I could use the very same version of the rust toolchain during development and packaging, regardless of the rust channel.

I was also thinking about this.
I am now referencing oxalica via tarball url to ensure rustc is always the latest stable, but deferring cargo's version to naersk.

I am curious if relying on the latest stable rustc and a potentially older nightly for cargo might cause any issues.

@dpc
Copy link
Contributor

dpc commented Aug 19, 2021

Seems like a simple thing to fix so I gave it a try and now I have a PR. So far it works for me.

@wezm
Copy link
Author

wezm commented Aug 19, 2021

Oh wow, thanks @dpc. If the fix is this simple, I'm embarrassed I didn't come up with it in my efforts before opening the issue last year.

@dpc
Copy link
Contributor

dpc commented Aug 19, 2021

Maybe it isn't, and I just don't know about it yet. 🤷 :)

@nmattia
Copy link
Collaborator

nmattia commented Aug 19, 2021

Ok, looks like there's a pretty big demand for this! @jonringer is it something you feel like tackling?

@jonringer
Copy link

Yea, I can try.

Just a little busy in my personal life for the short term.

@dpc
Copy link
Contributor

dpc commented Aug 23, 2021

Please reopen, because the PR was reverted. We are not giving up yet. :D

@tv42
Copy link

tv42 commented Mar 7, 2022

It seems naersk stopped using unstable cargo option --out-dir in commit 08afb3d (setting CARGO_TARGET_DIR instead). There are still some remnants of it in docs and comments, but it seems naersk works with stable cargo now.

tv42 added a commit to tv42/choosy that referenced this issue Mar 7, 2022
Remove workaround for
nix-community/naersk#100 that is no longer
needed.
@Patryk27
Copy link
Contributor

Seems like --out-dir is not used anymore, so I'm gonna go ahead and close this issue; if something's not working as intended, please feel free to re-open 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.