How to create a bug #1
Patrick Vollebregt
Senior DevOps | Cloud | Kubernetes | Modernisation | Mentor | Lead | E-Mobility | Clean Energy
We all need to learn how to create bugs, otherwise software development and engineering becomes way to boring.
I needed to update a Rust library to support vcpkg in manifest mode. I found that the library hasn't been maintained for over 3 years. It still works fine if you use vcpkg in classic mode, but that's not what I needed. So I forked the repo and created a release that supports vcpkg in manifest mode.
I discovered a small bug, that is want a crate is using vcpkg in manifest mode it got the path to the vcpkg_installed directory wrong. That is not the bug I want to talk about, and the fix was easy. I just needed to canonicalise the path. https://doc.rust-lang.org/stable/std/fs/fn.canonicalize.html
The documentation already spoils it, but I did not give it a good read:
领英推荐
On Windows, this converts the path to use extended length path syntax, which allows your program to use longer path names, but means you can only join backslash-delimited paths to it, and it may be incompatible with other applications (if passed to the application on the command-line, or written to a file another application may read).
The key thing: It only supports backslash-delimited paths. Now, when I had made this change everything worked, except on Windows. I got the weirdest errors, and I worked around it. But then I realised: It looks like Windows doesn't support forward slashes anymore. Most c/c++ source code use includes like 'library/lib.h' which the compiler just appends to the paths it has gotten.
Ta-da, this is how you create bugs! Now, the resolution it to use https://docs.rs/dunce/latest/dunce/fn.canonicalize.html instead, and scold at Rust for picking a highly incompatible path for Windows by default. Some Microsoft programs don't support it properly either.