├── LICENSE ├── README.md ├── bindgen.nix ├── default.nix ├── esp-idf.nix ├── esp32-toolchain.nix ├── llvm-xtensa.nix ├── rust-analyzer.nix ├── rust-xtensa.nix └── xbuild.nix /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Vincent Khougaz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RUST ESP32 NIX XTENSA ESP-IDF ESPRESSIF OH MY 2 | 3 | This is a collection of nix files that support build rust onto the esp32 4 | 5 | Example shell file: 6 | 7 | shell.nix 8 | ```nix 9 | let 10 | pythonPackageOverrides = self: super: { 11 | pyparsing = super.buildPythonPackage rec { 12 | pname = "pyparsing"; 13 | version = "2.3.1"; 14 | doCheck = false; 15 | src = super.fetchPypi { 16 | inherit pname version; 17 | sha256 = "0yk6xl885b91dmlhlsap7x78hk2rdr879fln9anbq6k4ca42djb6"; 18 | }; 19 | }; 20 | }; 21 | 22 | idf-package-overlay = self: super: { 23 | python2 = super.python2.override { 24 | packageOverrides = pythonPackageOverrides; 25 | }; 26 | }; 27 | 28 | pkgs = import (builtins.fetchTarball { 29 | # https://releases.nixos.org/nixos/unstable/nixos-20.09pre223023.fce7562cf46 30 | name = "nixos-unstable-2020-04-30"; 31 | url = "https://github.com/nixos/nixpkgs/archive/fce7562cf46727fdaf801b232116bc9ce0512049.tar.gz"; 32 | sha256 = "14rvi69ji61x3z88vbn17rg5vxrnw2wbnanxb7y0qzyqrj7spapx"; 33 | }) { 34 | overlays = [ 35 | idf-package-overlay 36 | ]; 37 | }; 38 | 39 | rust-esp = pkgs.callPackage (builtins.fetchTarball { 40 | name = "rust-esp-nix"; 41 | url = "https://github.com/sdobz/rust-esp-nix/archive/791e35c4822a7bdb91a2fbf7323e64255b640bd0.tar.gz"; 42 | sha256 = "0qp3myqpnprf7wfxxvnxpkhs3rg1d85cd9zynrhva7clgs3axnn4"; 43 | }) {}; 44 | in 45 | pkgs.mkShell { 46 | buildInputs = [ 47 | rust-esp.xbuild 48 | rust-esp.bindgen 49 | rust-esp.rustc 50 | rust-esp.cargo 51 | rust-esp.esp-idf 52 | rust-esp.esp32-toolchain 53 | pkgs.rustfmt 54 | ]; 55 | 56 | shellHook = '' 57 | ${rust-esp.env} 58 | 59 | if ! [ -d esp-idf ]; then 60 | mkdir -p esp-idf 61 | pushd esp-idf 62 | git init 63 | git remote add origin https://github.com/espressif/esp-idf 64 | git fetch --depth 1 origin 0a03a55c1eb44a354c9ad5d91d91da371fe23f84 65 | git checkout FETCH_HEAD 66 | git submodule update --init --recursive 67 | popd 68 | fi 69 | IDF_PATH=$(pwd)/esp-idf 70 | ''; 71 | } 72 | ``` 73 | 74 | Example usage: 75 | 76 | ```bash 77 | $ git clone https://github.com/sdobz/esp32-hello 78 | $ cd esp32-hello 79 | $ nix-shell shell.nix 80 | 81 | [shell] $ ./all.sh /dev/ttyUSB0 82 | ... 83 | (2317) Rust: I, live, again!. 84 | ``` 85 | 86 | # Improvements: 87 | 88 | * Bindgen is not running tests, needs investigation 89 | * Package as an overlay so other rust based programs can use this version of rust 90 | * Figure out how to not have to compile python to override a package 91 | * More idiomatic nix? 92 | -------------------------------------------------------------------------------- /bindgen.nix: -------------------------------------------------------------------------------- 1 | /* 2 | * bindgen 3 | */ 4 | { stdenv, fetchFromGitHub, rustPlatform, pkgs }: 5 | let 6 | llvm-xtensa = pkgs.callPackage ./llvm-xtensa.nix {}; 7 | in 8 | rustPlatform.buildRustPackage rec { 9 | version = "v0.53.2"; 10 | pname = "rust-bindgen"; 11 | 12 | src = fetchFromGitHub { 13 | owner = "rust-lang"; 14 | repo = "rust-bindgen"; 15 | rev = version; 16 | 17 | sha256 = "01dkaa2akqrhpxxf0g2zyfdb3nx16y14qsg0a9d5n92c4yyvmwjg"; 18 | }; 19 | 20 | cargoSha256 = "1yvpj2bz11pcyaadp5vc6yf1q04asr7id6aiw1n875dggvnwb3i8"; 21 | 22 | /* 23 | * Copied from upstream crates.io 24 | */ 25 | 26 | # [2020-05-11T21:21:31Z ERROR bindgen::ir::item] Unhandled cursor kind 25: Cursor(~String kind: CXXDestructor, loc: /build/source/tests/headers/public-dtor.hpp:11:9, usr: Some("c:@N@cv@S@String@F@~String#")) 27 | # [2020-05-11T21:21:31Z ERROR bindgen::ir::ty] unsupported type: kind = 162; ty = Type(ObjectType, kind: ObjCTypeParam, cconv: 100, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)); at Cursor(get kind: ObjCInstanceMethodDecl, loc: /build/source/tests/headers/objc_template.h:5:15, usr: Some("c:objc(cs)Foo(im)get")) 28 | # [2020-05-11T21:21:31Z ERROR bindgen::ir::ty] unsupported type: kind = 162; ty = Type(KeyType, kind: ObjCTypeParam, cconv: 100, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)); at Cursor(key kind: ParmDecl, loc: /build/source/tests/headers/objc_template.h:9:46, usr: Some("c:objc_template.h@250objc(cs)FooMultiGeneric(im)objectForKey:@key")) 29 | # [2020-05-11T21:21:31Z ERROR bindgen::ir::ty] unsupported type: kind = 162; ty = Type(ObjectType, kind: ObjCTypeParam, cconv: 100, decl: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None), canon: Cursor( kind: NoDeclFound, loc: builtin definitions, usr: None)); at Cursor(objectForKey: kind: ObjCInstanceMethodDecl, loc: /build/source/tests/headers/objc_template.h:9:24, usr: Some("c:objc(cs)FooMultiGeneric(im)objectForKey:")) 30 | # [2020-05-11T21:21:31Z ERROR bindgen::ir::item] Unhandled cursor kind 24: Cursor(a kind: CXXConstructor, loc: /build/source/tests/headers/issue-544-stylo-creduce.hpp:5:50, usr: Some("c:@SP>2#T#pT@a>#Ft0.0(#Pt0.1)@F@a#&1>@ST>1#T@a1S0_#")) 31 | # [2020-05-11T21:21:31Z ERROR bindgen::ir::item] Unhandled cursor kind 24: Cursor(Bar kind: CXXConstructor, loc: /build/source/tests/headers/issue-1464.hpp:5:3, usr: Some("c:@ST>1#NI@Bar@F@Bar#")) 32 | # [2020-05-11T21:21:31Z ERROR bindgen::ir::item] Unhandled cursor kind 25: Cursor(~Bar kind: CXXDestructor, loc: /build/source/tests/headers/issue-1464.hpp:6:3, usr: Some("c:@ST>1#NI@Bar@F@~Bar#")) 33 | # [2020-05-11T21:21:31Z ERROR bindgen::ir::item] Unhandled cursor kind 21: Cursor(doBaz kind: CXXMethod, loc: /build/source/tests/headers/constructor-tp.hpp:12:9, usr: Some("c:@ST>1#T@Foo@F@doBaz#")) 34 | # [2020-05-11T21:21:31Z ERROR bindgen::ir::item] Unhandled cursor kind 24: Cursor(Foo kind: CXXConstructor, loc: /build/source/tests/headers/constructor-tp.hpp:21:9, usr: Some("c:@ST>1#T@Foo@F@Foo#")) 35 | # [2020-05-11T21:21:31Z ERROR bindgen::ir::item] Unhandled cursor kind 9: Cursor(kBar kind: VarDecl, loc: /build/source/tests/headers/auto.hpp:10:31, usr: Some("c:@ST>1#T@Bar@kBar")) 36 | # test header_constify_module_enums_namespace_hpp ... [2020-05-11T21:21:31Z ERROR bindgen::ir::item] Unhandled cursor kind 24: Cursor(Bar kind: CXXConstructor, loc: /build/source/tests/headers/constructor-tp.hpp:25:6, usr: Some("c:@S@Bar@F@Bar#")) 37 | checkPhase = '' 38 | runHook preCheck 39 | export LLVM_CONFIG_PATH="${llvm-xtensa}/bin/llvm-config" 40 | #cargo test --release 41 | runHook postCheck 42 | ''; 43 | 44 | meta = with stdenv.lib; { 45 | description = "Automatically generates Rust FFI bindings to C (and some C++) libraries."; 46 | homepage = https://github.com/rust-lang/rust-bindgen; 47 | maintainers = with maintainers; [ "crabtw" "fitzgen" "nox" "emilio" ]; 48 | license = with licenses; [ bsd3 ]; 49 | platforms = platforms.unix; 50 | }; 51 | } -------------------------------------------------------------------------------- /default.nix: -------------------------------------------------------------------------------- 1 | {pkgs}: 2 | let 3 | rust-xtensa = (pkgs.callPackage ./rust-xtensa.nix { }); 4 | in rec { 5 | inherit (rust-xtensa) rustc cargo rust-src rustPlatform; 6 | esp-idf = pkgs.callPackage ./esp-idf.nix {}; 7 | esp32-toolchain = pkgs.callPackage ./esp32-toolchain.nix {}; 8 | llvm-xtensa = (pkgs.callPackage ./llvm-xtensa.nix {}); 9 | 10 | xbuild = pkgs.callPackage ./xbuild.nix { 11 | inherit rustPlatform; 12 | }; 13 | bindgen = pkgs.callPackage ./bindgen.nix { 14 | inherit rustPlatform; 15 | }; 16 | rust-analyzer = (pkgs.callPackage ./rust-analyzer.nix { 17 | inherit rustPlatform; 18 | }).rust-analyzer; 19 | env = '' 20 | export XARGO_RUST_SRC="${rust-src}/src" 21 | export LLVM_XTENSA="${llvm-xtensa}" 22 | export LIBCLANG_PATH="${llvm-xtensa}/lib" 23 | 24 | export IDF_PATH=${esp-idf} 25 | export IDF_TOOLS_PATH=${esp32-toolchain} 26 | 27 | export CFLAGS_COMPILE="-Wno-error=incompatible-pointer-types -Wno-error=implicit-function-declaration" 28 | export OPENOCD_SCRIPTS=$IDF_TOOLS_PATH/tools/openocd-esp32/share/openocd/scripts 29 | export NIX_CFLAGS_LINK=-lncurses 30 | export PATH=$PATH:${esp-idf}/tools:${esp-idf}/components/esptool_py/esptool:$IDF_TOOLS_PATH/tools/esp32ulp-elf/bin:$IDF_TOOLS_PATH/tools/openocd-esp32/bin:$IDF_TOOLS_PATH/tools/xtensa-esp32-elf/bin 31 | ''; 32 | } -------------------------------------------------------------------------------- /esp-idf.nix: -------------------------------------------------------------------------------- 1 | { stdenv, fetchFromGitHub, pkgs, makeWrapper }: 2 | 3 | let 4 | version = "0a03a55c1eb44a354c9ad5d91d91da371fe23f84"; 5 | 6 | pypkgs = python-packages: with python-packages; [ 7 | pyserial 8 | click 9 | cryptography 10 | future 11 | pyparsing 12 | pyelftools 13 | setuptools 14 | pip 15 | ]; 16 | python = pkgs.python2.withPackages pypkgs; 17 | 18 | in stdenv.mkDerivation rec { 19 | name = "esp-idf"; 20 | 21 | inherit python; 22 | 23 | src = fetchFromGitHub { 24 | owner = "espressif"; 25 | repo = "esp-idf"; 26 | rev = "${version}"; 27 | fetchSubmodules = true; 28 | sha256 = "067rgddhh4fdpnarxz7qjhfb377zdppgk8xsjqpkc07rdyagmwx6"; 29 | }; 30 | 31 | propagatedBuildInputs = [ 32 | pkgs.cmake 33 | pkgs.ninja 34 | pkgs.gcc 35 | pkgs.git 36 | pkgs.ncurses 37 | pkgs.flex 38 | pkgs.bison 39 | pkgs.gperf 40 | pkgs.ccache 41 | python 42 | ]; 43 | 44 | phases = [ "unpackPhase" "installPhase" "fixupPhase" ]; 45 | 46 | installPhase = '' 47 | cp -r . $out 48 | ''; 49 | 50 | meta = with stdenv.lib; { 51 | description = "ESP IDF"; 52 | homepage = https://docs.espressif.com/projects/esp-idf/en/stable/get-started/linux-setup.html; 53 | license = licenses.gpl3; 54 | }; 55 | } -------------------------------------------------------------------------------- /esp32-toolchain.nix: -------------------------------------------------------------------------------- 1 | { pkgs ? import {} }: 2 | 3 | let 4 | # , stdenv, fetchurl, makeWrapper, buildFHSUserEnv 5 | stdenv = pkgs.stdenv; 6 | fetchurl = pkgs.fetchurl; 7 | fetchzip = pkgs.fetchzip; 8 | buildFHSUserEnv = pkgs.buildFHSUserEnv; 9 | makeWrapper = pkgs.makeWrapper; 10 | lib = pkgs.lib; 11 | 12 | fhsEnv = buildFHSUserEnv { 13 | name = "esp32-toolchain-env"; 14 | targetPkgs = pkgs: with pkgs; [ zlib libusb1 ]; 15 | runScript = ""; 16 | }; 17 | toolHashes = { 18 | "xtensa-esp32-elf" = "06b6hw4m1jy79yw1mkj3kgibssrw4d4c5kbipbnckrivw107acw0"; 19 | # "xtensa-esp32s2-elf" 20 | "esp32ulp-elf" = "02rnzkha3fvzx631y27l9nkzls2qky0v645d4pw888lxkx8p5il9"; 21 | # "esp32s2ulp-elf" 22 | "openocd-esp32" = "00529xj2pmzy49w3j0wzxlw0phcbmx4vpkqbi0la88smwnqv0nqd"; 23 | }; 24 | version = "0a03a55c1eb44a354c9ad5d91d91da371fe23f84"; 25 | 26 | tools = let 27 | toolInfoFile = fetchurl { 28 | url = "https://raw.githubusercontent.com/espressif/esp-idf/${version}/tools/tools.json"; 29 | sha256 = "19dlp282mb6lpnwxc7l5i50cnqdj1qlqm5y9k98pr7wyixgj409g"; 30 | }; 31 | toolInfo = builtins.fromJSON (builtins.readFile toolInfoFile); 32 | filteredTools = builtins.filter (tool: builtins.hasAttr tool.name toolHashes) toolInfo.tools; 33 | 34 | fetchTool = tool: 35 | let 36 | fileInfo = (builtins.elemAt tool.versions 0).linux-amd64; 37 | in { 38 | name = tool.name; 39 | src = fetchzip { 40 | url = fileInfo.url; 41 | sha256 = toolHashes.${tool.name}; 42 | }; 43 | }; 44 | in 45 | builtins.map fetchTool filteredTools; 46 | in 47 | 48 | pkgs.runCommand "esp32-toolchain" { 49 | buildInputs = [ makeWrapper ]; 50 | meta = with stdenv.lib; { 51 | description = "ESP32 toolchain"; 52 | homepage = https://docs.espressif.com/projects/esp-idf/en/stable/get-started/linux-setup.html; 53 | license = licenses.gpl3; 54 | }; 55 | } '' 56 | ${lib.strings.concatStrings (builtins.map ({name, src}: '' 57 | mkdir -p $out/tools 58 | TOOLDIR=$out/tools/${name} 59 | cp -r ${src} $TOOLDIR 60 | chmod u+w $TOOLDIR/bin 61 | for FILE in $(ls $TOOLDIR/bin); do 62 | FILE_PATH="$TOOLDIR/bin/$FILE" 63 | if [[ -x $FILE_PATH ]]; then 64 | mv $FILE_PATH $FILE_PATH-unwrapped 65 | makeWrapper ${fhsEnv}/bin/esp32-toolchain-env $FILE_PATH --add-flags "$FILE_PATH-unwrapped" 66 | fi 67 | done 68 | chmod u-w $TOOLDIR/bin 69 | '') tools)} 70 | '' 71 | -------------------------------------------------------------------------------- /llvm-xtensa.nix: -------------------------------------------------------------------------------- 1 | { stdenv, fetchFromGitHub, pkgs }: 2 | 3 | stdenv.mkDerivation rec { 4 | name = "llvm-xtensa"; 5 | version = "33d79cce656c8c85c38832c8f52810875a3fbddf"; 6 | 7 | src = fetchFromGitHub { 8 | owner = "espressif"; 9 | repo = "llvm-project"; 10 | rev = "${version}"; 11 | fetchSubmodules = true; 12 | sha256 = "1a433q374in781l7sjavdlajrhbd568jdr540n2qlgzvkas44g4v"; 13 | }; 14 | 15 | buildInputs = [ 16 | pkgs.python3 17 | pkgs.cmake 18 | pkgs.ninja 19 | ]; 20 | 21 | phases = [ "unpackPhase" "buildPhase" "installPhase" "fixupPhase" ]; 22 | 23 | # http://quickhack.net/nom/blog/2019-05-14-build-rust-environment-for-esp32.html 24 | buildPhase = '' 25 | mkdir llvm_build 26 | cd llvm_build 27 | cmake ../llvm -DLLVM_ENABLE_PROJECTS="clang;libc;libclc;libcxx;libcxxabi;libunwind;lld;parallel-libs" -DLLVM_INSTALL_UTILS=ON -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="Xtensa" -DCMAKE_BUILD_TYPE=Release -G "Ninja" 28 | cmake --build . 29 | ''; 30 | 31 | installPhase = '' 32 | mkdir -p $out 33 | cmake -DCMAKE_INSTALL_PREFIX=$out -P cmake_install.cmake 34 | ''; 35 | 36 | meta = with stdenv.lib; { 37 | description = "LLVM xtensa"; 38 | homepage = https://github.com/espressif/llvm-project; 39 | license = licenses.asl20; 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /rust-analyzer.nix: -------------------------------------------------------------------------------- 1 | { pkgs, rustPlatform }: 2 | 3 | rec { 4 | rust-analyzer-unwrapped = pkgs.callPackage (pkgs.path + /pkgs/development/tools/rust/rust-analyzer/generic.nix) rec { 5 | inherit rustPlatform; 6 | rev = "2020-05-11"; 7 | version = "unstable-${rev}"; 8 | sha256 = "07sm3kqqva2jw41hb3smv3h3czf8f5m3rsrmb633psb1rgbsvmii"; 9 | cargoSha256 = "1x1nkaf10lfa9xhkvk2rsq7865d9waxw0i4bg5kwq8kz7n9bqm90"; 10 | }; 11 | 12 | rust-analyzer = pkgs.callPackage (pkgs.path + /pkgs/development/tools/rust/rust-analyzer/wrapper.nix) { 13 | inherit rustPlatform; 14 | } { 15 | unwrapped = rust-analyzer-unwrapped; 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /rust-xtensa.nix: -------------------------------------------------------------------------------- 1 | {pkgs}: 2 | let 3 | llvm-xtensa = (pkgs.callPackage ./llvm-xtensa.nix {}); 4 | lib = pkgs.lib; 5 | lists = lib.lists; 6 | fetchCargoTarball = pkgs.callPackage (pkgs.path + /pkgs/build-support/rust/fetchCargoTarball.nix) {}; 7 | 8 | toRustTarget = platform: with platform.parsed; let 9 | cpu_ = { 10 | "armv7a" = "armv7"; 11 | "armv7l" = "armv7"; 12 | "armv6l" = "arm"; 13 | }.${cpu.name} or platform.rustc.arch or cpu.name; 14 | in platform.rustc.config 15 | or "${cpu_}-${vendor.name}-${kernel.name}${lib.optionalString (abi.name != "unknown") "-${abi.name}"}"; 16 | 17 | # bootstrap 18 | date = "2020-03-12"; 19 | # from rust-xtensa github 20 | version = "1.44.0"; 21 | 22 | rustBinary = pkgs.callPackage (pkgs.path + /pkgs/development/compilers/rust/binary.nix) rec { 23 | # Noted while installing out of band 24 | # https://static.rust-lang.org/dist/2020-03-12/rust-std-beta-x86_64-unknown-linux-gnu.tar.xz 25 | # https://static.rust-lang.org/dist/2020-03-12/rustc-beta-x86_64-unknown-linux-gnu.tar.xz 26 | # https://static.rust-lang.org/dist/2020-03-12/cargo-beta-x86_64-unknown-linux-gnu.tar.xz 27 | # https://static.rust-lang.org/dist/2020-01-31/rustfmt-nightly-x86_64-unknown-linux-gnu.tar.xz 28 | 29 | # noted by inspecting https://static.rust-lang.org/dist/2020-03-12 30 | # version = "1.42.0"; 31 | # version = "nightly"; 32 | version = "beta"; 33 | 34 | platform = toRustTarget pkgs.stdenv.hostPlatform; 35 | versionType = "bootstrap"; 36 | 37 | src = pkgs.fetchurl { 38 | url = "https://static.rust-lang.org/dist/${date}/rust-${version}-${platform}.tar.gz"; 39 | # sha256 = "0llhg1xsyvww776d1wqaxaipm4f566hw1xyy778dhcwakjnhf7kx"; # 1.42.0 40 | # sha256 = "0jhggcwr852c4cqb4qv9a9c6avnjrinjnyzgfi7sx7n1piyaad43"; # nightly 41 | sha256 = "1cv402wp9dx6dqd9slc8wqsqkrb7kc66n0bkkmvgjx01n1jhv7n5"; # beta 42 | }; 43 | }; 44 | bootstrapPlatform = pkgs.makeRustPlatform rustBinary; 45 | 46 | src = pkgs.fetchFromGitHub { 47 | owner = "MabezDev"; 48 | repo = "rust-xtensa"; 49 | # rust 1.42++ 50 | rev = "25ae59a82487b8249b05a78f00a3cc35d9ac9959"; 51 | fetchSubmodules = true; 52 | sha256 = "1xr8rayvvinf1vahzfchlkpspa5f2nxic1j2y4dgdnnzb3rkvkg5"; 53 | }; 54 | in 55 | rec { 56 | rust-src = src; 57 | 58 | rustc = (pkgs.rustc.override { 59 | rustPlatform = bootstrapPlatform; 60 | # override the rustc result attrs before calling 61 | }).overrideAttrs ( old: rec { 62 | pname = "rustc-xtensa"; 63 | inherit version src; 64 | 65 | llvmSharedForBuild = llvm-xtensa; 66 | llvmSharedForHost = llvm-xtensa; 67 | llvmSharedForTarget = llvm-xtensa; 68 | llvmShared = llvm-xtensa; 69 | patches = []; 70 | 71 | configureFlags = 72 | (lists.remove "--enable-llvm-link-shared" 73 | (lists.remove "--release-channel=stable" old.configureFlags)) ++ [ 74 | "--set=build.rustfmt=${pkgs.rustfmt}/bin/rustfmt" 75 | "--llvm-root=${llvm-xtensa}" 76 | "--experimental-targets=Xtensa" 77 | # Nightly because xargo (which compiles a new core) can only build on nightly 78 | # xargo replace with cargo xbuild 79 | "--release-channel=nightly" 80 | ]; 81 | 82 | cargoDeps = fetchCargoTarball { 83 | inherit pname; 84 | inherit src; 85 | sourceRoot = null; 86 | srcs = null; 87 | patches = []; 88 | sha256 = "0z4mb33f72ik8a1k3ckbg3rf6p0403knx5mlagib0fs2gdswg9w5"; 89 | }; 90 | 91 | postConfigure = '' 92 | ${old.postConfigure} 93 | unpackFile "$cargoDeps" 94 | mv $(stripHash $cargoDeps) vendor 95 | # export VERBOSE=1 96 | ''; 97 | }); 98 | 99 | cargo = (pkgs.callPackage (pkgs.path + /pkgs/development/compilers/rust/cargo.nix) { 100 | rustPlatform = bootstrapPlatform; 101 | inherit (pkgs.darwin.apple_sdk.frameworks) Security CoreFoundation; 102 | inherit rustc; 103 | }).overrideAttrs(old: rec { 104 | name = "cargo-xtensa-${version}"; 105 | inherit version src; 106 | cargoDeps = fetchCargoTarball { 107 | inherit name; 108 | inherit src; 109 | sourceRoot = null; 110 | srcs = null; 111 | patches = []; 112 | sha256 = "1w5fz966vf09p87xbxc5pm9xq4f1gx8a2vj7fskx30skkwb97d13"; 113 | }; 114 | 115 | # cargoVendorDir = builtins.trace "${cargoDeps}" null; 116 | postConfigure = '' 117 | unpackFile "$cargoDeps" 118 | mv $(stripHash $cargoDeps) vendor 119 | # export VERBOSE=1 120 | ''; 121 | }); 122 | 123 | rustPlatform = pkgs.makeRustPlatform { 124 | inherit rustc cargo; 125 | }; 126 | } 127 | -------------------------------------------------------------------------------- /xbuild.nix: -------------------------------------------------------------------------------- 1 | /* 2 | * xbuild 3 | */ 4 | { stdenv, fetchFromGitHub, rustPlatform, pkgs }: 5 | rustPlatform.buildRustPackage rec { 6 | version = "v0.5.29"; 7 | pname = "cargo-xbuild"; 8 | 9 | src = fetchFromGitHub { 10 | owner = "rust-osdev"; 11 | repo = "cargo-xbuild"; 12 | rev = version; 13 | 14 | sha256 = "05wg1xx2mcwb9cplmrpg13jimddlzmv7hf5g3vjppjp8kz2gb7zj"; 15 | }; 16 | 17 | propagatedBuildInputs = [ 18 | pkgs.ncurses 19 | ]; 20 | 21 | cargoSha256 = "1pj8zfkr51y7lbjg9c3di4gr8a2l0z5gqslk6wmsiry6vcj2sks1"; 22 | 23 | /* 24 | * Just copied from upstream crates.io 25 | */ 26 | meta = with stdenv.lib; { 27 | description = "Automatically cross-compiles the sysroot crates core, compiler_builtins, and alloc."; 28 | homepage = https://github.com/rust-osdev/cargo-xbuild; 29 | maintainers = with maintainers; [ "phil-opp" ]; 30 | license = with licenses; [ mit asl20 ]; 31 | platforms = platforms.unix; 32 | }; 33 | } --------------------------------------------------------------------------------