GithubHelp home page GithubHelp logo

rust-esp-nix's Introduction

RUST ESP32 NIX XTENSA ESP-IDF ESPRESSIF OH MY

This is a collection of nix files that support build rust onto the esp32

Example shell file:

shell.nix

let
  pythonPackageOverrides = self: super: {
    pyparsing = super.buildPythonPackage rec {
      pname = "pyparsing";
      version = "2.3.1";
      doCheck = false;
      src = super.fetchPypi {
        inherit pname version;
        sha256 = "0yk6xl885b91dmlhlsap7x78hk2rdr879fln9anbq6k4ca42djb6";
      };
    };
  };

  idf-package-overlay = self: super: {
    python2 = super.python2.override {
      packageOverrides = pythonPackageOverrides;
    };
  };

  pkgs = import (builtins.fetchTarball {
    # https://releases.nixos.org/nixos/unstable/nixos-20.09pre223023.fce7562cf46
    name = "nixos-unstable-2020-04-30";
    url = "https://github.com/nixos/nixpkgs/archive/fce7562cf46727fdaf801b232116bc9ce0512049.tar.gz";
    sha256 = "14rvi69ji61x3z88vbn17rg5vxrnw2wbnanxb7y0qzyqrj7spapx";
  }) {
    overlays = [
      idf-package-overlay
    ];
  };

  rust-esp = pkgs.callPackage (builtins.fetchTarball {
    name = "rust-esp-nix";
    url = "https://github.com/sdobz/rust-esp-nix/archive/791e35c4822a7bdb91a2fbf7323e64255b640bd0.tar.gz";
    sha256 = "0qp3myqpnprf7wfxxvnxpkhs3rg1d85cd9zynrhva7clgs3axnn4";
  }) {};
in
pkgs.mkShell {
    buildInputs = [ 
      rust-esp.xbuild
      rust-esp.bindgen
      rust-esp.rustc
      rust-esp.cargo
      rust-esp.esp-idf
      rust-esp.esp32-toolchain
      pkgs.rustfmt
    ];

    shellHook = ''
${rust-esp.env}

if ! [ -d esp-idf ]; then
  mkdir -p esp-idf
  pushd esp-idf
  git init
  git remote add origin https://github.com/espressif/esp-idf
  git fetch --depth 1 origin 0a03a55c1eb44a354c9ad5d91d91da371fe23f84
  git checkout FETCH_HEAD
  git submodule update --init --recursive
  popd
fi
IDF_PATH=$(pwd)/esp-idf
    '';
}

Example usage:

$ git clone https://github.com/sdobz/esp32-hello
$ cd esp32-hello
$ nix-shell shell.nix
<wait for a long long time while we build the world>
[shell] $ ./all.sh /dev/ttyUSB0
...
 (2317) Rust: I, live, again!.

Improvements:

  • Bindgen is not running tests, needs investigation
  • Package as an overlay so other rust based programs can use this version of rust
  • Figure out how to not have to compile python to override a package
  • More idiomatic nix?

rust-esp-nix's People

Contributors

sdobz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rust-esp-nix's Issues

Not working anymore, easy fix

Hi @sdobz

First of all thanks for such contribution. You're solving in a beautiful manner the build of all this mess. Thanks!

The build finished correctly, and I managed to enter the nix environment without any issue (after a couple of hours).

However when building the project (sdobz/esp32-hello) there is a failure:

[nix-shell:~/persospace/rust-esp-nix/esp32-hello]$ ./all.sh /dev/ttyUSB0
Toolchain path: /nix/store/fsw629zbkgzxbyv54gfml8fxwjqs8xmw-esp32-toolchain/tools/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc
Toolchain version: esp32-2019r1
Compiler version: 8.2.0
Python requirements from /home/mjost/persospace/rust-esp-nix/esp32-hello/esp-idf/requirements.txt are satisfied.
App "hello-world" version: 643b3b1-dirty
App built. Default flash app command is:
python /home/mjost/persospace/rust-esp-nix/esp32-hello/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 40m --flash_size detect 0x10000 /home/mjost/persospace/rust-esp-nix/esp32-hello/build/hello-world.bin
    Updating crates.io index
   Compiling compiler_builtins v0.1.43
   Compiling core v0.0.0 (/nix/store/5qr9mk1pf2rcpdr5y4r715s30di12rib-source/src/libcore)
   Compiling rustc-std-workspace-core v1.99.0 (/nix/store/5qr9mk1pf2rcpdr5y4r715s30di12rib-source/src/tools/rustc-std-workspace-core)
error[E0658]: `loop` is not allowed in a `const`
   --> /home/mjost/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.43/src/int/mod.rs:107:13
    |
107 | /             loop {
108 | |                 if l >= ((bits / 2) as u8) {
109 | |                     break;
110 | |                 }
...   |
116 | |                 l *= 2;
117 | |             }
    | |_____________^
...
251 |   int_impl!(isize, usize);
    |   ------------------------ in this macro invocation
    |
    = note: see issue #52000 <https://github.com/rust-lang/rust/issues/52000> for more information
    = help: add `#![feature(const_loop)]` to the crate attributes to enable
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0658]: `if` is not allowed in a `const`
   --> /home/mjost/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.43/src/int/mod.rs:108:17
    |
108 | /                 if l >= ((bits / 2) as u8) {
109 | |                     break;
110 | |                 }
    | |_________________^
...
251 |   int_impl!(isize, usize);
    |   ------------------------ in this macro invocation
    |
    = note: see issue #49146 <https://github.com/rust-lang/rust/issues/49146> for more information
    = help: add `#![feature(const_if_match)]` to the crate attributes to enable
    = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0658]: `if` is not allowed in a `const`
   --> /home/mjost/.cargo/registry/src/github.com-1ecc6
...

@mebubo figured out why. As per what I understand the version used of compiler_builtins is not the same as the one you used when you wrote this project. The version resolved is now different. This has to do with the fact that the project xbuild generates a Cargo.toml which depends on the version 0.1.0 of compiler_builtins, which means any patch 0.1.x (to avoid this it should use =0.1.0 instead of 0.1.0). While performing the (x)build cargo takes the latest patch available for such dependency, going to 0.1.43 (!!!), which breaks the compilation as shown above . As per semver, until you have a major=1 it seems to be legal to make breaking changes without bumps in major (https://semver.org/#spec-item-4), so I think xbuild project should for now pin a fixed version, even at patch number.

This build worked: https://github.com/mauriciojost/rust-esp-nix/tree/mjost (is a fork of your project with the above suggested changes).

How do you think this could be solved?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.