Rewriting Libimagequant in Rust for Portability
Rust has de-facto standards&#x2F;monoculture. Things don&#x27;t have to be stamped by ISO for everyone to agree on them. There is bare `rustc` for cases Cargo can&#x27;t handle, but Cargo is good enough for almost everyone. People forgive (and hack around) some of Cargo&#x27;s quirks and limitations, because there is a huge value in consistency and interoperability that a single unified build system brings. <a href="https:&#x2F;&#x2F;docs.rs" rel="nofollow">https:&#x2F;&#x2F;docs.rs</a> can build docs for literally every Rust package. The Rust team runs unit tests of all public Rust packages when testing compiler changes. 3rd party tools integrate smoothly, e.g. cargo-deb makes a .deb from any Rust project, with no config at all.<p>&gt; C11 optional supports a thread model<p>I&#x27;ve been fighting for C99 support 15 years after its publication, so a merely decade-old C11 seems too new and radical. MSVC of course doesn&#x27;t support C11 threads.<p>&gt; How do I depend on a specific C library from a cargo.toml?<p>It is easier if you rewrite it in Rust ;)<p>But seriously, you make (or usually use an existing) Cargo package for it. Cargo calls them &quot;-sys crates&quot;. They contain an arbitrary build script that figures out what combination of pkg-config, vcpkg, brew, or vendoring is the right one for a given snowflake C library. This may seem like overkill, but it really is helpful and often necessary if you target more than a Linux distro. pkg-config is utterly useless on Windows. Gives out brittle library paths on macOS. Non-existent on iOS. On every OS it gives invalid results for cross-compilation, unless user works around that in a platform-specific way. Some packages like libpng, llvm or macOS openssl may have non-working or incorrect pkg-config files on purpose.<p>Would your build script include workarounds for Homebrew? Emscripten? If you&#x27;re not a user of these, would you even know you need them? In Cargo people collaborate and share their build script workarounds as dependencies too. It does look like duplicating work done by Linux distros, but it&#x27;s done for all platforms, so you get the consistency you expect from a Linux distro everywhere. e.g. openssl-sys has this monster <a href="https:&#x2F;&#x2F;github.com&#x2F;sfackler&#x2F;rust-openssl&#x2F;blob&#x2F;master&#x2F;openssl-sys&#x2F;build&#x2F;main.rs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sfackler&#x2F;rust-openssl&#x2F;blob&#x2F;master&#x2F;openssl...</a> or all the pains to configure ffmpeg build, e.g for cross-builds or static linking on macOS: <a href="https:&#x2F;&#x2F;github.com&#x2F;meh&#x2F;rust-ffmpeg-sys&#x2F;blob&#x2F;master&#x2F;build.rs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;meh&#x2F;rust-ffmpeg-sys&#x2F;blob&#x2F;master&#x2F;build.rs</a>