ivanceras / diwata

A user-friendly database interface
Apache License 2.0
395 stars 15 forks source link

Compile with stable release of rust #3

Open rehno-lindeque opened 6 years ago

rehno-lindeque commented 6 years ago

Hi, I was trying to create a diwata package for NixOS (and other platforms where the nix package manager is available).

However, in order to get it to build I've had to compile with nightly rustc, which would make it tough to get it accepted into the nixpkgs collection.

Running cargo build --release
   Compiling serde v1.0.27
   Compiling rustc-serialize v0.3.24
   Compiling gcc v0.3.54
   Compiling byteorder v1.2.1
   Compiling bitflags v1.0.1
   Compiling lazy_static v0.2.11
   Compiling strsim v0.7.0
   Compiling pear v0.0.12
   Compiling ordermap v0.2.13
   Compiling num-traits v0.2.1
   Compiling scopeguard v0.3.3
   Compiling matches v0.1.6
   Compiling unicode-normalization v0.1.5
   Compiling ansi_term v0.11.0
   Compiling nodrop v0.1.12
   Compiling byte-tools v0.2.0
   Compiling state v0.3.3
error[E0554]: #![feature] may not be used on the stable release channel
 --> /tmp/nix-build-diwata-0.1.0.drv-0/diwata-0.1.0-vendor/state/src/lib.rs:1:1
  |
1 | #![feature(const_fn)]
  | ^^^^^^^^^^^^^^^^^^^^^

error[E0554]: #![feature] may not be used on the stable release channel
 --> /tmp/nix-build-diwata-0.1.0.drv-0/diwata-0.1.0-vendor/state/src/lib.rs:2:1
  |
2 | #![feature(const_unsafe_cell_new)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: #![feature] may not be used on the stable release channel
 --> /tmp/nix-build-diwata-0.1.0.drv-0/diwata-0.1.0-vendor/state/src/lib.rs:3:1
  |
3 | #![feature(const_atomic_usize_new)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: #![feature] may not be used on the stable release channel
 --> /tmp/nix-build-diwata-0.1.0.drv-0/diwata-0.1.0-vendor/state/src/lib.rs:4:1
  |
4 | #![feature(const_atomic_bool_new)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors

error: Could not compile `state`.
warning: build failed, waiting for other jobs to finish...
error: build failed

I think I may have had similar problems with other dependencies. Is there any chance of a fix?

ivanceras commented 6 years ago

Hi @rehno-lindeque , this needed the nightly compiler at the moment. Even if I try to use stable, the project relies on a library that also uses a nightly compiler such as rocket.

rehno-lindeque commented 6 years ago

No worries, thanks for looking into it and interesting project. If you find it can compile on stable at some point ping me here and I'll try to look into it again.


For posterity, I didn't get around to figuring out how to build the webapp's assets but work could be continued from here:

{ stdenv, fetchFromGitHub, rustPlatform, elmPackages, closurecompiler, gnused, rsync, makeWrapper }:

rustPlatform.buildRustPackage rec {
  name = "diwata-${version}";
  version = "0.1.0";

  buildInputs = [ elmPackages.elm closurecompiler gnused rsync makeWrapper ];

  src = fetchFromGitHub {
    owner = "ivanceras";
    repo = "diwata";
    rev = "5f0293c3e22795314fbc11403f5d9ff5e4630225";
    sha256 = "0i40x2glz5zhwwx2j635i2vkma5kmrf9zzwa4ys7pprs6kj4z2nk";
    fetchSubmodules = true;
  };

  postInstall = ''
    mkdir -p $out/public
    substituteInPlace "webclient/compile.sh" \
        --replace "../public" "$out/public"
    substituteInPlace "webclient/compile_release.sh" \
        --replace "../public" "$out/public" \
        --replace "google-closure-compiler-js" "closure-compiler"
    cd webclient
    HOME=$out ELM_HOME=$out ./compile_release.sh
    wrapProgram $out/bin/diwata \
      --run "cd $out"
  '';

  cargoSha256 = "18zrj6fxn6pyllxrzkzy9qn1smbf6gwfyf8kdhr0389babkpaqcz";
  doCheck = false;

  meta = with stdenv.lib; {
    description = "A user-friendly database interface";
    homepage = https://github.com/ivanceras/diwata;
    license = licenses.apache;
    maintainers = [];
    platforms = platforms.all;
  };
}

Added this to my overlays to build with rustc nightly:

self: super:

let
  rustNightly = super.rust // rec {
    rustc = super.rust.rustc.override {
      configureFlags = [ "--release-channel=nightly" ];
      src = self.fetchurl {
        url = "https://static.rust-lang.org/dist/2018-03-01/rustc-1.24.1-src.tar.gz";
        sha256 = "1vv10x2h9kq7fxh2v01damdq8pvlp5acyh1kzcda9sfjx12kv99y";
      };
      doCheck = false;
    };

    cargo = super.cargo.override {
      inherit rustc;
    };
  };
in
{
  diwata = self.callPackage (import ./pkgs/diwata.nix) {
    rustPlatform = self.makeRustPlatform rustNightly;
  };

(apologies for the noise)

ivanceras commented 6 years ago

Dependency to rocket library(which relies on the nightly compiler) has now been removed. However, the project can't still be compiled with the nightly compiler due to the use of try_from. As soon as try_from feature is stabilized the project can then be built using the stable compiler. I think it would be enough time to have a usable build of the project.

ivanceras commented 5 years ago

TryFrom has already been stablized, but the dependency of diwata which is sauron uses 2 new features that are behind the a feature flag. which are #![feature(arbitrary_self_types)] and #![cons_generics]. It will take a little more while before the project could use the stable compiler