From 58a28c2715be6b641c1644b6d169c77709612841 Mon Sep 17 00:00:00 2001 From: Rien Maertens Date: Thu, 4 Nov 2021 16:31:37 +0100 Subject: [PATCH 1/3] Add Nix flake with devShell --- .cargo/config | 14 ----------- Cargo.lock | 2 ++ README.md | 12 ++++++++- flake.lock | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 49 +++++++++++++++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 15 deletions(-) delete mode 100644 .cargo/config create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.cargo/config b/.cargo/config deleted file mode 100644 index 2b2e52a..0000000 --- a/.cargo/config +++ /dev/null @@ -1,14 +0,0 @@ -[target.armv7-unknown-linux-gnueabihf] -linker = "/usr/local/oecore-x86_64/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-gcc" -rustflags = [ - "-C", "link-arg=-march=armv7-a", - "-C", "link-arg=-marm", - "-C", "link-arg=-mfpu=neon", - "-C", "link-arg=-mfloat-abi=hard", - "-C", "link-arg=-mcpu=cortex-a9", - "-C", "link-arg=--sysroot=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi", -] - -[build] -# Set the default --target flag -target = "armv7-unknown-linux-gnueabihf" diff --git a/Cargo.lock b/Cargo.lock index e9e700a..6609f49 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "anyhow" version = "1.0.37" diff --git a/README.md b/README.md index 39fd3d6..d08df2d 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,17 @@ Steps you can try if the script isn't working: If you want to play with the `restream` code, you will have to [install Rust](https://www.rust-lang.org/learn/get-started). -There are two ways of building the required restream binary for streaming the reMarkable framebuffer. For both approaches, the generated restream binary will be located under `target/armv7-unknown-linux-gnueabihf/release/restream`. +There are three ways of building the required restream binary for streaming the reMarkable framebuffer. For these approaches, the generated restream binary will be located under `target/armv7-unknown-linux-gnueabihf/release/restream`. + +- **Using nix flakes** + With [Nix](https://nixos.org/guides/install-nix.html) installed and + [Nix flakes](https://nixos.wiki/wiki/Flakes#Installing_flakes) enabled, you + can easily setup the devlopment environment with: + ``` + nix develop + ``` + After which you can simply run `cargo build --release` to build the restream + binary. - **Using docker and the toltec toolchain:** You can use the [toltec toolchain docker images](https://github.com/toltec-dev/toolchain) to build a restream binary compatible with the reMarkable. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a66f1b6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,67 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1634851050, + "narHash": "sha256-N83GlSGPJJdcqhUxSCS/WwW5pksYf3VP1M13cDRTSVA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c91f3de5adaf1de973b797ef7485e441a65b8935", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1635844945, + "narHash": "sha256-tZcL307dj28jgEU1Wdn+zwG9neyW0H2+ZjdVhvJxh9g=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "b67e752c29f18a0ca5534a07661366d6a2c2e649", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1635992196, + "narHash": "sha256-+Duob7Ashxc/2pyhzZI3peZRLUlbzcmy2ZLzZN0Oups=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "a7d961b654c38b85877db7af4fac57ba3eaede16", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8f90aa5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,49 @@ +{ + description = "Stream the reMarkable screen to your computer"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-utils.follows = "flake-utils"; + }; + }; + outputs = {self, nixpkgs, flake-utils, rust-overlay, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { + inherit system overlays; + }; + in + with pkgs; + { + devShell = mkShell { + buildInputs = [ + remarkable-toolchain + (rust-bin.stable.latest.default.override { + targets = [ "armv7-unknown-linux-gnueabihf" ]; + extensions = [ "rust-src" ]; + }) + openssl.dev + pkg-config + cargo-watch + cargo-limit + shellcheck + lz4 + ]; + CARGO_BUILD_TARGET="armv7-unknown-linux-gnueabihf"; + CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER="${pkgs.remarkable-toolchain}/sysroots/x86_64-codexsdk-linux/usr/bin/arm-remarkable-linux-gnueabi/arm-remarkable-linux-gnueabi-gcc"; + CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUSTFLAGS=[ + "-C link-arg=-march=armv7-a" + "-C link-arg=-marm" + "-C link-arg=-mfpu=neon" + "-C link-arg=-mfloat-abi=hard" + "-C link-arg=-mcpu=cortex-a9" + "-C link-arg=--sysroot=${pkgs.remarkable-toolchain}/sysroots/cortexa9hf-neon-remarkable-linux-gnueabi" + ]; + }; + }); +} From 85f4104796feccec710c6a94e828a53d5dae3fa2 Mon Sep 17 00:00:00 2001 From: Rien Maertens Date: Thu, 4 Nov 2021 16:58:13 +0100 Subject: [PATCH 2/3] Also add a shell.nix --- README.md | 13 +++++-------- default.nix | 27 +++++++++++++++++++++++++++ flake.nix | 26 +------------------------- shell.nix | 8 ++++++++ 4 files changed, 41 insertions(+), 33 deletions(-) create mode 100644 default.nix create mode 100644 shell.nix diff --git a/README.md b/README.md index d08df2d..9874719 100644 --- a/README.md +++ b/README.md @@ -172,14 +172,11 @@ If you want to play with the `restream` code, you will have to [install Rust](ht There are three ways of building the required restream binary for streaming the reMarkable framebuffer. For these approaches, the generated restream binary will be located under `target/armv7-unknown-linux-gnueabihf/release/restream`. - **Using nix flakes** - With [Nix](https://nixos.org/guides/install-nix.html) installed and - [Nix flakes](https://nixos.wiki/wiki/Flakes#Installing_flakes) enabled, you - can easily setup the devlopment environment with: - ``` - nix develop - ``` - After which you can simply run `cargo build --release` to build the restream - binary. + With [Nix](https://nixos.org/guides/install-nix.html) installed you can + create the development environment with `nix-shell` or (when using + [Nix flakes](https://nixos.wiki/wiki/Flakes#Installing_flakes) `nix-develop`. + After which you can simply run `cargo build --release` to build the restream + binary on your machine. - **Using docker and the toltec toolchain:** You can use the [toltec toolchain docker images](https://github.com/toltec-dev/toolchain) to build a restream binary compatible with the reMarkable. diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..42d06de --- /dev/null +++ b/default.nix @@ -0,0 +1,27 @@ +{ + devShell = pkgs: with pkgs; mkShell { + buildInputs = [ + remarkable-toolchain + (rust-bin.stable.latest.default.override { + targets = [ "armv7-unknown-linux-gnueabihf" ]; + extensions = [ "rust-src" ]; + }) + openssl.dev + pkg-config + cargo-watch + cargo-limit + shellcheck + lz4 + ]; + CARGO_BUILD_TARGET="armv7-unknown-linux-gnueabihf"; + CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER="${pkgs.remarkable-toolchain}/sysroots/x86_64-codexsdk-linux/usr/bin/arm-remarkable-linux-gnueabi/arm-remarkable-linux-gnueabi-gcc"; + CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUSTFLAGS=[ + "-C link-arg=-march=armv7-a" + "-C link-arg=-marm" + "-C link-arg=-mfpu=neon" + "-C link-arg=-mfloat-abi=hard" + "-C link-arg=-mcpu=cortex-a9" + "-C link-arg=--sysroot=${pkgs.remarkable-toolchain}/sysroots/cortexa9hf-neon-remarkable-linux-gnueabi" + ]; + }; +} diff --git a/flake.nix b/flake.nix index 8f90aa5..23ee015 100644 --- a/flake.nix +++ b/flake.nix @@ -20,30 +20,6 @@ in with pkgs; { - devShell = mkShell { - buildInputs = [ - remarkable-toolchain - (rust-bin.stable.latest.default.override { - targets = [ "armv7-unknown-linux-gnueabihf" ]; - extensions = [ "rust-src" ]; - }) - openssl.dev - pkg-config - cargo-watch - cargo-limit - shellcheck - lz4 - ]; - CARGO_BUILD_TARGET="armv7-unknown-linux-gnueabihf"; - CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER="${pkgs.remarkable-toolchain}/sysroots/x86_64-codexsdk-linux/usr/bin/arm-remarkable-linux-gnueabi/arm-remarkable-linux-gnueabi-gcc"; - CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUSTFLAGS=[ - "-C link-arg=-march=armv7-a" - "-C link-arg=-marm" - "-C link-arg=-mfpu=neon" - "-C link-arg=-mfloat-abi=hard" - "-C link-arg=-mcpu=cortex-a9" - "-C link-arg=--sysroot=${pkgs.remarkable-toolchain}/sysroots/cortexa9hf-neon-remarkable-linux-gnueabi" - ]; - }; + devShell = (import ./default.nix).devShell pkgs; }); } diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..d69c239 --- /dev/null +++ b/shell.nix @@ -0,0 +1,8 @@ +let + pkgs = import { + overlays = [ + (import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz")) + ]; + }; + reStreamDev = import ./default.nix; +in reStreamDev.devShell pkgs From d3422b14439c615058ea4eb7636ba432a2a5c023 Mon Sep 17 00:00:00 2001 From: Rien Maertens Date: Thu, 4 Nov 2021 19:52:59 +0100 Subject: [PATCH 3/3] Add workflow to build rust binary --- .github/workflows/check.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a468cde..a4bf63c 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -33,3 +33,19 @@ jobs: - name: Shell Formatter run: docker run -v $GITHUB_WORKSPACE:/mnt -w /mnt mvdan/shfmt -d reStream.sh + + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - uses: cachix/install-nix-action@v14.1 + with: + nix_path: nixpkgs=channel:nixos-unstable + + - run: nix-shell + - run: cargo build