Skip to content

Make no libusb build clearer #246

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

Merged
merged 4 commits into from
Jun 23, 2025
Merged
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
2 changes: 1 addition & 1 deletion BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ git submodule update --init lib/mbedtls

You also need to install `libusb-1.0` if you want to use the USB functionality.

> If libusb-1.0 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 won't appear in the output of the help command. The build output message 'libUSB is not found - no USB support will be built' also appears in the build logs.
> If libusb-1.0 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 identified by running `picotool version`, which will state `This version of picotool was compiled without USB support. Some commands are not available.`. Additionally, the unsupported commands won't appear in the output of the help command, and if you attempt to execute an invalid command you will get an error message. The build output message `libUSB is not found - no USB support will be built` also appears in the build logs.

### Linux / macOS

Expand Down
26 changes: 25 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ static const string rp2350_arm_s_family_name = "rp2350-arm-s";
static const string rp2350_arm_ns_family_name = "rp2350-arm-ns";
static const string rp2350_riscv_family_name = "rp2350-riscv";

#if !HAS_LIBUSB
static const string built_without_libusb_message = "\nThis version of picotool was compiled without USB support. Some commands are not available.\n";
#endif

static string hex_string(int64_t value, int width=8, bool prefix=true, bool uppercase=false) {
std::stringstream ss;
if (prefix) ss << "0x";
Expand Down Expand Up @@ -705,7 +709,11 @@ struct info_command : public cmd {
}

string get_doc() const override {
#if HAS_LIBUSB
return "Display information from the target device(s) or file.\nWithout any arguments, this will display basic information for all connected RP-series devices in BOOTSEL mode";
#else
return "Display information from the target file.";
#endif
}
};

Expand Down Expand Up @@ -736,7 +744,11 @@ struct config_command : public cmd {
}

string get_doc() const override {
#if HAS_LIBUSB
return "Display or change program configuration settings from the target device(s) or file.";
#else
return "Display or change program configuration settings from the target file.";
#endif
}
};

Expand Down Expand Up @@ -1376,8 +1388,12 @@ struct version_command : public cmd {
bool execute(device_map &devices) override {
if (settings.version.semantic)
std::cout << PICOTOOL_VERSION << "\n";
else
else {
std::cout << "picotool v" << PICOTOOL_VERSION << " (" << SYSTEM_VERSION << ", " << COMPILER_INFO << ")\n";
#if !HAS_LIBUSB
std::cout << built_without_libusb_message;
#endif
}
if (!settings.version.version.empty()) {
string picotool_v = string(PICOTOOL_VERSION);
picotool_v = picotool_v.substr(0, picotool_v.find("-"));
Expand Down Expand Up @@ -1623,6 +1639,9 @@ int parse(const int argc, char **argv) {
} else {
fos << string("Use \"picotool help ").append(selected_cmd->name()).append("\" for more info\n");
}
#if !HAS_LIBUSB
fos << built_without_libusb_message;
#endif
} else {
cli::option_map options;
selected_cmd->get_cli().get_option_help("", "", options);
Expand Down Expand Up @@ -1654,6 +1673,11 @@ int parse(const int argc, char **argv) {
fos.hanging_indent(0);
fos.wrap_hard();
fos << "Use \"picotool help <cmd>\" for more info\n";
#if !HAS_LIBUSB
if (!help_mode) {
fos << built_without_libusb_message;
}
#endif
}
fos.flush();
};
Expand Down
Loading