diff --git a/deps.bzl b/deps.bzl index 74b140f7d629..00e6000e18a4 100644 --- a/deps.bzl +++ b/deps.bzl @@ -871,9 +871,6 @@ def prysm_deps(): ) go_repository( name = "com_github_ethereum_go_ethereum", - build_directives = [ - "gazelle:resolve go github.com/karalabe/usb @prysm//third_party/usb:go_default_library", - ], importpath = "github.com/ethereum/go-ethereum", patch_args = ["-p1"], patches = [ @@ -1929,6 +1926,11 @@ def prysm_deps(): importpath = "github.com/karalabe/hid", sum = "h1:msKODTL1m0wigztaqILOtla9HeW1ciscYG4xjLtvk5I=", version = "v1.0.1-0.20240306101548-573246063e52", + patch_args = ["-p1"], + patches = [ + # This patch disables the cgo aspects of this library. + "//third_party:com_github_karalabe_hid.patch", + ], ) go_repository( name = "com_github_kataras_blocks", diff --git a/third_party/com_github_karalabe_hid.patch b/third_party/com_github_karalabe_hid.patch new file mode 100644 index 000000000000..3768703835b9 --- /dev/null +++ b/third_party/com_github_karalabe_hid.patch @@ -0,0 +1,77 @@ +diff --git a/BUILD.bazel b/BUILD.bazel +index 9be80a1..0e78457 100755 +--- a/BUILD.bazel ++++ b/BUILD.bazel +@@ -8,58 +8,7 @@ go_library( + srcs = [ + "hid.go", + "hid_disabled.go", +- "hid_enabled.go", +- "wchar.go", + ], +- cgo = True, +- clinkopts = select({ +- "@io_bazel_rules_go//go/platform:darwin": [ +- "-framework CoreFoundation -framework IOKit -lobjc", +- ], +- "@io_bazel_rules_go//go/platform:freebsd": [ +- "-lusb", +- ], +- "@io_bazel_rules_go//go/platform:linux": [ +- "-lrt", +- ], +- "@io_bazel_rules_go//go/platform:windows": [ +- "-lsetupapi", +- ], +- "//conditions:default": [], +- }), +- copts = select({ +- "@io_bazel_rules_go//go/platform:android": [ +- "-DDEFAULT_VISIBILITY=", +- "-DPOLL_NFDS_TYPE=int", +- "-Ihidapi/hidapi", +- "-Ilibusb/libusb -DOS_LINUX -D_GNU_SOURCE -DHAVE_SYS_TIME_H -DHAVE_CLOCK_GETTIME", +- ], +- "@io_bazel_rules_go//go/platform:darwin": [ +- "-DDEFAULT_VISIBILITY=", +- "-DOS_DARWIN -DHAVE_SYS_TIME_H", +- "-DPOLL_NFDS_TYPE=int", +- "-Ihidapi/hidapi", +- ], +- "@io_bazel_rules_go//go/platform:freebsd": [ +- "-DDEFAULT_VISIBILITY=", +- "-DOS_FREEBSD", +- "-DPOLL_NFDS_TYPE=int", +- "-Ihidapi/hidapi", +- ], +- "@io_bazel_rules_go//go/platform:linux": [ +- "-DDEFAULT_VISIBILITY=", +- "-DPOLL_NFDS_TYPE=int", +- "-Ihidapi/hidapi", +- "-Ilibusb/libusb -DOS_LINUX -D_GNU_SOURCE -DHAVE_SYS_TIME_H -DHAVE_CLOCK_GETTIME", +- ], +- "@io_bazel_rules_go//go/platform:windows": [ +- "-DDEFAULT_VISIBILITY=", +- "-DOS_WINDOWS", +- "-DPOLL_NFDS_TYPE=int", +- "-Ihidapi/hidapi", +- ], +- "//conditions:default": [], +- }), + importpath = "github.com/karalabe/hid", + visibility = ["//visibility:public"], + ) +diff --git a/hid_disabled.go b/hid_disabled.go +index fa2c504..0091853 100644 +--- a/hid_disabled.go ++++ b/hid_disabled.go +@@ -4,9 +4,6 @@ + // This file is released under the 3-clause BSD license. Note however that Linux + // support depends on libusb, released under GNU LGPL 2.1 or later. + +-//go:build (!freebsd && !linux && !darwin && !windows) || ios || !cgo +-// +build !freebsd,!linux,!darwin,!windows ios !cgo +- + package hid + + // Supported returns whether this platform is supported by the HID library or not. diff --git a/third_party/usb/AUTHORS b/third_party/usb/AUTHORS deleted file mode 100644 index bae45b3ec294..000000000000 --- a/third_party/usb/AUTHORS +++ /dev/null @@ -1,7 +0,0 @@ -Felix Lange -Guillaume Ballet -Jakob Weisblat -Martin Holst Swende -Mateusz Mikołajczyk -Péter Szilágyi -Rosen Penev diff --git a/third_party/usb/BUILD.bazel b/third_party/usb/BUILD.bazel deleted file mode 100644 index a8a9d019ec2f..000000000000 --- a/third_party/usb/BUILD.bazel +++ /dev/null @@ -1,21 +0,0 @@ -load("@prysm//tools/go:def.bzl", "go_library", "go_test") - -# gazelle:prefix github.com/karalabe/usb - -go_library( - name = "go_default_library", - srcs = [ - "hid_disabled.go", - "raw_disabled.go", - "usb.go", - "usb_disabled.go", - ], - importpath = "github.com/karalabe/usb", - visibility = ["@com_github_ethereum_go_ethereum//:__subpackages__"], -) - -go_test( - name = "go_default_test", - srcs = ["usb_test.go"], - embed = [":go_default_library"], -) diff --git a/third_party/usb/LICENSE b/third_party/usb/LICENSE deleted file mode 100644 index 65c5ca88a67c..000000000000 --- a/third_party/usb/LICENSE +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/third_party/usb/README.md b/third_party/usb/README.md deleted file mode 100644 index a8f556681321..000000000000 --- a/third_party/usb/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# usb - -This is a copy of github.com/karalabe/usb, except that it is fully disabled. - -The current karalabe/usb library requires a bit of handwritten cc_library targets. -This library isn't used in Prysm anyway, so it is disabled for now. \ No newline at end of file diff --git a/third_party/usb/hid_disabled.go b/third_party/usb/hid_disabled.go deleted file mode 100644 index e8134ecb5fc2..000000000000 --- a/third_party/usb/hid_disabled.go +++ /dev/null @@ -1,40 +0,0 @@ -// usb - Self contained USB and HID library for Go -// Copyright 2017 The library Authors -// -// This library is free software: you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation, either version 3 of the License, or (at your option) any -// later version. -// -// The library is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -// A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License along -// with the library. If not, see . - -package usb - -// HidDevice is a live HID USB connected device handle. On platforms that this file -// implements, the type lacks the actual HID device and all methods are noop. -type HidDevice struct { - DeviceInfo // Embed the infos for easier access -} - -// Close releases the HID USB device handle. On platforms that this file implements, -// the method is just a noop. -func (dev *HidDevice) Close() error { - return ErrUnsupportedPlatform -} - -// Write sends an output report to a HID device. On platforms that this file -// implements, the method just returns an error. -func (dev *HidDevice) Write(b []byte) (int, error) { - return 0, ErrUnsupportedPlatform -} - -// Read retrieves an input report from a HID device. On platforms that this file -// implements, the method just returns an error. -func (dev *HidDevice) Read(b []byte) (int, error) { - return 0, ErrUnsupportedPlatform -} diff --git a/third_party/usb/raw_disabled.go b/third_party/usb/raw_disabled.go deleted file mode 100644 index e00fa5878f11..000000000000 --- a/third_party/usb/raw_disabled.go +++ /dev/null @@ -1,40 +0,0 @@ -// usb - Self contained USB and HID library for Go -// Copyright 2017 The library Authors -// -// This library is free software: you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation, either version 3 of the License, or (at your option) any -// later version. -// -// The library is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -// A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License along -// with the library. If not, see . - -package usb - -// RawDevice is a live raw USB connected device handle. On platforms that this file -// implements, the type lacks the actual USB device and all methods are noop. -type RawDevice struct { - DeviceInfo // Embed the infos for easier access -} - -// Close releases the USB device handle. On platforms that this file implements, -// the method is just a noop. -func (dev *RawDevice) Close() error { - return ErrUnsupportedPlatform -} - -// Write sends a binary blob to a USB device. On platforms that this file -// implements, the method just returns an error. -func (dev *RawDevice) Write(b []byte) (int, error) { - return 0, ErrUnsupportedPlatform -} - -// Read retrieves a binary blob from a USB device. On platforms that this file -// implements, the method just returns an error. -func (dev *RawDevice) Read(b []byte) (int, error) { - return 0, ErrUnsupportedPlatform -} diff --git a/third_party/usb/usb.go b/third_party/usb/usb.go deleted file mode 100644 index 96a1e2502c1b..000000000000 --- a/third_party/usb/usb.go +++ /dev/null @@ -1,68 +0,0 @@ -// usb - Self contained USB and HID library for Go -// Copyright 2019 The library Authors -// -// This library is free software: you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation, either version 3 of the License, or (at your option) any -// later version. -// -// The library is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -// A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License along -// with the library. If not, see . - -// Package usb provide interfaces for generic USB devices. -package usb - -import "errors" - -// ErrDeviceClosed is returned for operations where the device closed before or -// during the execution. -var ErrDeviceClosed = errors.New("usb: device closed") - -// ErrUnsupportedPlatform is returned for all operations where the underlying -// operating system is not supported by the library. -var ErrUnsupportedPlatform = errors.New("usb: unsupported platform") - -// DeviceInfo contains all the information we know about a USB device. In case of -// HID devices, that might be a lot more extensive (empty fields for raw USB). -type DeviceInfo struct { - Path string // Platform-specific device path - VendorID uint16 // Device Vendor ID - ProductID uint16 // Device Product ID - Release uint16 // Device Release Number in binary-coded decimal, also known as Device Version Number - Serial string // Serial Number - Manufacturer string // Manufacturer String - Product string // Product string - UsagePage uint16 // Usage Page for this Device/Interface (Windows/Mac only) - Usage uint16 // Usage for this Device/Interface (Windows/Mac only) - - // The USB interface which this logical device - // represents. Valid on both Linux implementations - // in all cases, and valid on the Windows implementation - // only if the device contains more than one interface. - Interface int - - // Raw low level libusb endpoint data for simplified communication - rawDevice interface{} - rawPort *uint8 // Pointer to differentiate between unset and port 0 - rawReader *uint8 // Pointer to differentiate between unset and endpoint 0 - rawWriter *uint8 // Pointer to differentiate between unset and endpoint 0 -} - -// Device is a generic USB device interface. It may either be backed by a USB HID -// device or a low level raw (libusb) device. -type Device interface { - // Close releases the USB device handle. - Close() error - - // Write sends a binary blob to a USB device. For HID devices write uses reports, - // for low level USB write uses interrupt transfers. - Write(b []byte) (int, error) - - // Read retrieves a binary blob from a USB device. For HID devices read uses - // reports, for low level USB read uses interrupt transfers. - Read(b []byte) (int, error) -} diff --git a/third_party/usb/usb_disabled.go b/third_party/usb/usb_disabled.go deleted file mode 100644 index 6e4a30037a81..000000000000 --- a/third_party/usb/usb_disabled.go +++ /dev/null @@ -1,49 +0,0 @@ -// usb - Self contained USB and HID library for Go -// Copyright 2019 The library Authors -// -// This library is free software: you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation, either version 3 of the License, or (at your option) any -// later version. -// -// The library is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -// A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License along -// with the library. If not, see . - -package usb - -// Supported returns whether this platform is supported by the USB library or not. -// The goal of this method is to allow programmatically handling platforms that do -// not support USB and not having to fall back to build constraints. -func Supported() bool { - return false -} - -// Enumerate returns a list of all the USB devices attached to the system which -// match the vendor and product id. On platforms that this file implements the -// function is a noop and returns an empty list always. -func Enumerate(vendorID uint16, productID uint16) ([]DeviceInfo, error) { - return nil, nil -} - -// EnumerateRaw returns a list of all the USB devices attached to the system which -// match the vendor and product id. On platforms that this file implements the -// function is a noop and returns an empty list always. -func EnumerateRaw(vendorID uint16, productID uint16) ([]DeviceInfo, error) { - return nil, nil -} - -// EnumerateHid returns a list of all the HID devices attached to the system which -// match the vendor and product id. On platforms that this file implements the -// function is a noop and returns an empty list always. -func EnumerateHid(vendorID uint16, productID uint16) ([]DeviceInfo, error) { - return nil, nil -} - -// Open connects to a previously discovered USB device. -func (info DeviceInfo) Open() (Device, error) { - return nil, ErrUnsupportedPlatform -} diff --git a/third_party/usb/usb_test.go b/third_party/usb/usb_test.go deleted file mode 100644 index c238c0af432f..000000000000 --- a/third_party/usb/usb_test.go +++ /dev/null @@ -1,86 +0,0 @@ -// usb - Self contained USB and HID library for Go -// Copyright 2017 The library Authors -// -// This library is free software: you can redistribute it and/or modify it under -// the terms of the GNU Lesser General Public License as published by the Free -// Software Foundation, either version 3 of the License, or (at your option) any -// later version. -// -// The library is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -// A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License along -// with the library. If not, see . - -package usb - -import ( - "os" - "runtime" - "sync" - "testing" -) - -// Tests that HID enumeration can be called concurrently from multiple threads. -func TestThreadedEnumerateHid(t *testing.T) { - var pend sync.WaitGroup - for i := 0; i < 8; i++ { - pend.Add(1) - - go func(index int) { - defer pend.Done() - for j := 0; j < 512; j++ { - if _, err := EnumerateHid(uint16(index), 0); err != nil { - t.Errorf("thread %d, iter %d: failed to enumerate: %v", index, j, err) - } - } - }(i) - } - pend.Wait() -} - -// Tests that RAW enumeration can be called concurrently from multiple threads. -func TestThreadedEnumerateRaw(t *testing.T) { - // Travis does not have usbfs enabled in the Linux kernel - if os.Getenv("TRAVIS") != "" && runtime.GOOS == "linux" { - t.Skip("Linux on Travis doesn't have usbfs, skipping test") - } - // Yay, we can actually test this - var pend sync.WaitGroup - for i := 0; i < 8; i++ { - pend.Add(1) - - go func(index int) { - defer pend.Done() - for j := 0; j < 512; j++ { - if _, err := EnumerateRaw(uint16(index), 0); err != nil { - t.Errorf("thread %d, iter %d: failed to enumerate: %v", index, j, err) - } - } - }(i) - } - pend.Wait() -} - -// Tests that generic enumeration can be called concurrently from multiple threads. -func TestThreadedEnumerate(t *testing.T) { - // Travis does not have usbfs enabled in the Linux kernel - if os.Getenv("TRAVIS") != "" && runtime.GOOS == "linux" { - t.Skip("Linux on Travis doesn't have usbfs, skipping test") - } - var pend sync.WaitGroup - for i := 0; i < 8; i++ { - pend.Add(1) - - go func(index int) { - defer pend.Done() - for j := 0; j < 512; j++ { - if _, err := Enumerate(uint16(index), 0); err != nil { - t.Errorf("thread %d, iter %d: failed to enumerate: %v", index, j, err) - } - } - }(i) - } - pend.Wait() -}