Skip to content

Picotool dependencies solved with Nix #202

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ if (NOT PICOTOOL_NO_LIBUSB)
add_dependencies(xip_ram_perms_elf xip_ram_perms)
set_property(TARGET xip_ram_perms_elf PROPERTY IMPORTED_LOCATION ${XIP_RAM_PERMS_ELF})
# copy xip_ram_perms.elf into build directory
add_custom_command(TARGET xip_ram_perms
COMMAND ${CMAKE_COMMAND} -E copy ${XIP_RAM_PERMS_ELF} ${CMAKE_BINARY_DIR}/xip_ram_perms.elf
DEPENDS xip_ram_perms
add_custom_command(TARGET xip_ram_perms POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${XIP_RAM_PERMS_ELF} ${CMAKE_BINARY_DIR}/xip_ram_perms.elf
)

add_dependencies(xip_ram_perms xip_ram_perms)

# compile flash_id
ExternalProject_Add(flash_id
PREFIX picoboot_flash_id
Expand All @@ -104,11 +105,12 @@ if (NOT PICOTOOL_NO_LIBUSB)
add_dependencies(flash_id_bin flash_id)
set_property(TARGET flash_id_bin PROPERTY IMPORTED_LOCATION ${FLASH_ID_BIN})
# copy flash_id.bin into build directory
add_custom_command(TARGET flash_id
COMMAND ${CMAKE_COMMAND} -E copy ${FLASH_ID_BIN} ${CMAKE_BINARY_DIR}/flash_id.bin
DEPENDS flash_id
add_custom_command(TARGET flash_id POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${FLASH_ID_BIN} ${CMAKE_BINARY_DIR}/flash_id.bin
)

add_dependencies(flash_id flash_id)

# We want to generate headers from WELCOME.HTM etc.
ExternalProject_Add(otp_header_parser
PREFIX otp_header_parser
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ sudo apt install build-essential pkg-config libusb-1.0-0-dev cmake

> If libusb-1.0-0-dev is not installed, picotool still builds, but it omits all options that deal with managing a pico via USB (load, save, erase, verify, reboot). Builds that do not include USB support can be recognized because these commands also do not appear in the help command. The build output message 'libUSB is not found - no USB support will be built' also appears in the build logs.

##### Alternative to install dependencies with nix

Instead of having to manually install every dependency, it can be managed through [Nix](https://nixos.org/download/) / [Lix](https://lix.systems/install/).

Before building the project, just use the following command: `nix develop`


Then simply build like a normal CMake project:

```console
Expand Down
60 changes: 60 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
description = "A flake for compiling picotool from Raspberry Pi";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"] (system:
let
pkgs = import nixpkgs { inherit system; };

picoSdk = pkgs.fetchFromGitHub {
owner = "raspberrypi";
repo = "pico-sdk";
rev = "master";
sha256 = "0qzj3x7vqrflirgbxmji2m5fqxha7ib95nsg6glhpn7id7lkb9s0";
};

commonDeps = [
pkgs.cmake
pkgs.libusb1
];

macDeps = [
pkgs.llvmPackages.clang
pkgs.libiconv
];

linuxDeps = [
pkgs.gcc
];

buildDeps = if pkgs.stdenv.isDarwin then commonDeps ++ macDeps else commonDeps ++ linuxDeps;

in {
devShells.default = pkgs.mkShell {
buildInputs = buildDeps;
shellHook = ''
export PICO_SDK_PATH=${picoSdk}
echo "PICO_SDK_PATH set to ${picoSdk}"
'';
};
});
}