-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
How to deal with deprecated libusb_init() in other projects #1236
Comments
It affects HIDAPI as well but it is just a warning here.
|
@hjelmn and @tormodvolden Shall we keep it for now (not deprecate Basically it affects many projects using libusb, wmost of them (ge: HIDAPI and libftdi and avrdude) will generate a warning which is good. But for some projects it will be treated as errors like OpenOCD and libjaylink. |
For our own libusb-compat-0.1 project, I will fix it later.
|
I would be fine with delaying the deprecation a bit, also to get some wider user experiences on the new one where it will be useful, before ditching the old which for many simpler use cases works exactly the same. I see no problem in keeping the old libusb_init in parallel for a good while, just that we want any users of LIBUSB_OPTION_NO_DEVICE_DISCOVERY (almost no-one since it is rather new and its applications are probably experimental) and LIBUSB_OPTION_USE_USBDK (maybe some, but the old libusb_open has no great disadvantage here) to use libusb_init_context. Also LIBUSB_OPTION_LOG_LEVEL users can profit from libusb_init_context and avoid using the shaky "set options for any future context" procedure that kind of works right now. But in case libusb_init_context is the way to go and it will stay, it would only be harmful to drag out the transition. Those who choose to use -Werror likely do it also for this reason, to quickly react to e.g. deprecated code. An application supporting older libusb versions probably have a bunch of LIBUSB_API_VERSION checks and alternative code already. Another check for libusb_open will need to be added. The sooner they change it the better. The problem would be if application developers don't test against libusb git but make their new release building with -Werror before 1.0.27 is out and picked up by them. A distribution then upgrades to libusb 1.0.27 and the application won't build there without distribution tweaking. But I guess adding -Wno-deprecated flags is part of the distribution game. |
No problem, I'll update HIDAPI once libusb 1.0.27 is released. |
In htis case, I will just send an email to the OpenOCD mailing list to mention about this change. Let's see if we get some objections or not. |
There is a strong objection from avrdude lead developer here. avrdudes/avrdude#1295 (comment)
|
Just wondering if you can implement the same API for FreeBSD libusb implementations. Thanks. |
Feedbacks from OpenOCD developer. On Wed, Jan 25, 2023 at 10:00 PM Antonio Borneo wrote:
|
You mean libusb_init_context() ? Yes, FreeBSD can do that. Can you send me a patch for /usr/src/lib/libusb to [email protected] ? In worst case, we can also use symbol versioning, but it is good that new and different names are chosen when changing libusb APIs. That's the best way forward. Anyway. I see no problem supporting libusb 0.1 in the future aswell. Some people want it simple and some people need more complicated features as offered by libusb 1.0. I see no reason to support the one-shoe fits everyone thought, but other people may. Again, send me a patch and I'll look into it. |
About time they rear they heads then, these API changes have been out for discussions for years here now.
I don't understand exactly what he means by "there". Maybe he didn't get that libusb_init is to be replaced by libusb_init_context.
|
What are the downside(s) of keeping the |
We will of course bump LIBUSB_API_VERSION, just not happened in the git tree yet. It needs to be bumped for all the new API functions we just added. EDIT: Done in commit 54350bd |
Not from me anyway. I am not so sure who would like to do it. I actually think you are the one to do it for FreeBSD. :-) |
@mcuee: May I of total lazyness ask for a link to the implementation of the needed function in Linux's LibUSB? |
I see. This is the PR. |
|
@tormodvolden : It's not really an own version, but more a USB "backend" redesign inside LibUSB, which optimizes and reduce error situations under FreeBSD. We try to keep up with new ideas and APIs in LibUSB, but at the same time appreciate that some things are written in stone, so to speak. Also due to Licensing issues, this was needed, because FreeBSD uses primarly a 2-clause-BSD license, and LibUSB is now part of the FreeBSD base system. I think NetBSD and OpenBSD only provide this library in their "ports", so the issue is not quite the same. |
To anyone interested, I've put up a review for FreeBSD: As a FreeBSD libusb maintainer I would be very happy if:
was removed from libusb.h to avoid unneeded churn in the code bases around the world. The new functions are technically fine, but really have no value for FreeBSD except for the possibility to atomically supply the default libusb debug value during context init. Also forcing users to set the debug value via libusb_set_option() is not really good for anything except breaking backwards compatibility and forcing users to upgrade. @tormodvolden : If your intent with these changes is to force libusb users to upgrade, then I agree about the deprecated thing. Else not. Technically, if libusb was a C++ library, then this would not be an issue at all I presume. |
I am also not so happy with this. I think the intention was to not have to support (and encourage) too many ways of doing things. In the larger picture I am not sure I like so much libusb_set_option and how we try to squeeze everything through it but that's a longer story. What exactly do you mean by "forcing users to upgrade"? Forcing application developers to update their code, inserting more LIBUSB_API_VERSION checks? Yes, but it wouldn't force end users and distributions to upgrade libusb at the same time, and the applications would still build against older libusb. Old applications would also link fine against newer libusb, the deprecation is only a compilation warning. I would be happy keeping libusb_init not deprecated in libusb 1.0.x (also since its implementation costs us nothing), but rather find ways to hit down on applications attempting libusb_set_options with NO_DEVICE_DISCOVERY or USE_USBDK. |
@tormodvolden : Many people are pedandic about C-code and use -Werror and -Wall by default. When an upstream project sees a compiler error like "deprecated function", they will fix it and use the new function, but that also pulls in the requirement for upgrading the libusb package. Because the libusb in FreeBSD is in the base system, that requires a base system upgrade vs a package upgrade. |
That is not entirely true. So many projects are being compiled with And while for GCC/Clang there is a workaround ( |
I was talking about run-time linking, and in the context of end users and distributions. You can build an application against libusb 1.0.26, then upgrade libusb to 1.0.27 and the same application binary will run fine (maybe even better, since libusb has improved). There will be no deprecation warning. |
They would be doing it wrong. They should simply insert #if LIBUSB_API_VERSION >= 0x0100010A \n libusb_init_context(ctx, NULL, 0); \n #else \n libusb_init(ctx); \n #endif Then the requirements won't need bumping and everybody is happy. (Of course, as upstream developers we'd like everybody to use our latest version, so they can enjoy our improvements and not fight with resolved bugs - but within reason.) |
With this MSVC logic, what would be a valid case for using deprecation at all then? One could as well just rip out the old function. Only difference that the (error) message shows which new function to use. OTOH deprecated means it is available, but should be replaced. |
If a project chooses to build with -Werror without -Wno-deprecated, this is exactly what they ask for. They want to be sure a deprecated function is identified and replaced rather than going unnoticed. If you want your project to build in as many situations as possible without having to maintain it, you shouldn't use -Werror without -Wno-deprecated. |
That is a fare point
I find it a "design bug" of MSVC. Don't think there is in such scenarios.
That is true in cases when all packages are distributed in a binary form, but there are things like Yocto/Gentoo/(I imagine maby others), when all packages are always built from sources. And imagine an application that is linking against libusb1.0.24 and totally happy with its functionality. There is a choice - force to upgrade, or postpone upgrade of libusb for everyone (that's what most likely to happen).
Qt actually has an interesting mechanism for that: they use a macro So ideally would be great to specify that the API is deprecated only for those users that are targeting the latest/specific version of libusb. So that's more an idea to think about rather then a real action item here.
That would be no longer a |
Looking at the current implementation of IMHO, for a popular library such as libusb, there needs to be a strong technical reason (say 'security issue' or 'high maintenance') to deprecate a public function API. |
Anyway, MSVC is already special-cased in our definition of LIBUSB_DEPRECATED_FOR() so it is would be easy to just disable deprecation warnings there altogether if we want to keep these functions tagged as deprecated. Interestingly, libusb_set_debug() was deprecated already in 1.0.20, but that has been going quiet without uproar as far as I know. Is it really that little used?
You mean a distribution will hold back libusb instead of patching the offending applications (or simply adding -Wno-deprecated)? I don't think so lowly of distribution packagers. Or you mean static linking? So not distributions. Some lazy application developer, basing their program on libusb, but not willing to make a small adaption to be able to include the newer libusb? I cannot really imagine this either. I guess we don't disagree that much, but it is good to get all perspectives on the table. I reckon we want some kind of soft "deprecation" which makes application developers take notice, but doesn't break anything. That is what the GCC warnings are meant for, I believe. But I understand the common use of -Werror makes it different. I would prefer we don't technically deprecate it with compiler attributes yet, but solely deprecate it in documentation and examples. |
Sounds excellent.
My feeling about this conversation is mutual.
Quick searching over Github shows quite a bit of usages (but I imagine lots of those are forks, etc., but still) and patches/fixes. Could be a number of reasons/coincidences why people didn't complain about it - mayby that really was a "natural" change.
Lets assume that most/major distribution packagers really are disciplined-enough and will deal with such cases, i.e. will patch broken packages, etc. Secondly - there're distributions, most library developers wouldn't even know about. I mean closed/corporate solutions/etc., and of course they are still compliant with the library's license. I had a case on my project about 3 years ago (yes, a corporate solution), when we couldn't upgrade a Yocto/BSP to a newer version for more than 8 months, because a change in one of the (non-direct) dependencies broke compilation of our Core module (and we couldn't "just fix it" - it was complicated at the moment). |
Hey, I just found this thread. Seeing the impact, in my opinion deprecating the function was a mistake. The role of a library is to make maintenance safe and easy for downstream users. We didn't hold this. As it stands, this likely propagates breaking changes to unmaintained projects that used to build fine. |
With all this attention, it seems important to mention that libusb is badly in need of maintainers. There was almost nobody available to review the change that preceded this issue. |
Maybe not a full-time mantainer, but I'll find more time at least reviewing the PRs. |
Hey, hold on, we haven't released this yet :) We are free to test out things in our development git repository. This discussion is about what we will do in the release. |
This is true, many programs don't use libusb_set_debug. We can also safely say that many (simple or older) programs won't need the features of libusb_init_context and are not affected by the limitations of libusb_init. |
The suggested changes have also been brought up on the libusb mailing list many times. I am disappointed that projects that rely on libusb are not following the mailing list. |
I think people expect basic libusb functions like |
Yes, libusb_init() is guaranteed to continue to work in 1.0.x (we haven't adopted the full x.y.z semantic version convention yet, but that is another discussion, so maybe even 1.x.x). I think everybody has been agreeing to that from the start. Marking something as deprecated doesn't make it not work. The question is if we should do these -Werrors people a favour and not deprecate using compiler attributes. |
Not only Actually I think we should not deprecate of On a related note, you can see
Related discussion: |
The fix from OpenOCD project seems to be simple enough.
|
I believe the above change from OpenOCD is also okay for FreeBSD. But I am just wondering if you want to implement something like LIBUSB_API_VERSION for FreeBSD, maybe LIBUSB_FREEBSD_API_VERSION or similar. |
I have a change for FreeBSD. This should be fixed in libusb itself by removing those deprecated warnings like already agreed! |
Resolve the following two issues. * libusb#990 * libusb#1236
I have created PR #1241. Let's see if other maintainers approve the PR or not. |
I have no strong feelings one way or another. Deprecation of an old function is done a lot and precedes the removal in the next major version. It is annoying that |
Do have to say this issue came about not from lack of maintainers but from lack of involvement from users. We asked for feedback on multiple occasions. Oh well. |
These functions are used in a lot of existing downstream code and the deprecation makes -Werror builds fail. It seems reasonable to keep these functions supported at least until a major API overhaul. Closes libusb#990 Closes libusb#1236
PR #1026 has been merged.
Now I have a problem building OpenOCD.
https://github.com/openocd-org/openocd/blob/master/src/jtag/drivers/libusb_helper.c
For now, I have to use
./configure --disable-werror
. What will be a proper fix for OpenOCD? They may have to support older libusb version.OpenOCD has dependancy to libjaylink which has the same issue.
The text was updated successfully, but these errors were encountered: