3 ms·
Yeah, build with -Werror when you control the compiler, e.g. in your CI system, or whatever you use to produce build artifacts, but don't hardcode it in your bu
by 4ad 5y ago
Yeah, build with -Werror when you control the compiler, e.g. in your CI system, or whatever you use to produce build artifacts, but don't hardcode it in your build otherwise.
- twic 5y agoYou should always control the compiler. The compiler is a dependency of your project, just like the libraries you use. The project should specify the version, just as it does for libraries. In Rust, you use the rust-toolchain file, in Gradle, set java.toolchain.languageVersion, etc. In my C++ projects, i use an ugly ball of shell script; the author of this article explains how to do it using Docker. If someone wants to build the project with a different compiler, that's fine - they have to make the change and fix any resulting problems, just as if they were changing the version of a library.
- 4ad 5y agoHave you ever heard of libraries (as opposed to binaries)? Or open source software packaged by distributions?
- ludocode 5y agoIt is difficult to assume good faith in your comment. Of course the parent has heard of libraries. It is sad to see they are being downvoted because they are quite correct. In any professional project I've ever worked on, the compiler version has been strictly controlled. The entire team must use the same version of Visual Studio, or Xcode, or the JDK, or the Android build tools or whatever. You don't just let your developers upgrade whenever they want. Upgrading the build tools is an involved process that must be coordinated with the release cycle. All new warnings need to be fixed, all CI nodes need to be upgraded at once, scripts and metadata need fixes to work with the new tools, etc. You are only approaching this issue from the perspective of open source software. That is not most software. The parent is correct: the compiler version is a dependency of your project and, in any serious development team, should be fixed for the whole team.
- 4ad 5y agoAh, yes, so a "professional team" is one where 1. the deliverable are binaries (as opposed to source code), and which 2. is not open source. I get it.
- strenholme 5y agoThe article we’re linking to very specifically asks open source software to use -Werror. They’re saying we should just have a Dockerfile, and force people to use Docker to compile an open source application, which is a rather disingenuous solution: Dockerfiles can only run Linux, and there’s a lot more than Linux out there (FreeBSD, etc.) There was a time my open source project was running on Solaris, MacOS X, Linux (multiple distros), and Windows. Making something run only on Docker is a little restrictive by comparison.
- 4ad 5y agoYeah, although in reality the OSS angle is kind of moot. There can only be one party in control of dependencies. If there is more than one party involved in the development of a product, only the downstream consumer can be in charge of dependencies. This happens all the time with closed source projects too, it's not specific to OSS. There is a difference between being a leaf and a node in a tree of producers and consumers.
- strenholme 5y agoThanks for your reply. With OSS, the exact compiler and build toolchain varies from user to user, so good OSS code tries to be as easy as possible to compile, i.e. avoid -Werror or anything else that deliberately stops compiling.
- 4ad 5y agoOf course, the GP tries to instill the idea that open source is not "professional" when in fact in OSS you will see far more variation in development practices and deployment practices than in closed source world. It's a strict superset.
- strenholme 5y agoFrom the article: “some (many?) folks in the open source and academic world hate -Werror with passion” (emphasis mine). In the open source world, the developer can not control which compiler their users will use to try and compile their program. (OK, the article advocates forcing users to use Docker, but that significantly restricts who will be able to use their software.) This leads to a lot of interesting coding style practices. For a while, I needed to always declare variables at the beginning of my functions because FreeBSD users at the time would make a stink because their compiler back then could not handle variables declared mid-function. -Werror was unthinkable. More like, -Wall and people would make a stink on the mailing list when they saw compiler warnings. Of course, I would minimize them, but new compiler warnings come up with every GCC update (CLANG makes a lot fewer warnings), and I can just imagine what my GitHub issues page would look like if I were foolish enough to actually use -Werror The linked article is wrong. Do not, repeat, do not use -Werror in environments where end users will compile the code themselves. Feel free, however, to use -Werror for CI builds on a Docker container with a known version of GCC.