libc
rustc_codegen_cranelift
Our great sponsors
libc | rustc_codegen_cranelift | |
---|---|---|
10 | 44 | |
1,966 | 1,446 | |
2.7% | 6.0% | |
9.4 | 9.7 | |
4 days ago | 2 days ago | |
Rust | Rust | |
Apache License 2.0 | Apache License 2.0 |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
libc
-
Pragmatic Versioning – An Alternative to Semver
> I absolutely don't see how this is a problem with semver,
Strange to not see it. Semver promises to solve dependency hell. In the example everyone correctly followed the sevmver and the app is broken by a dependency hell issue.
> it is not the responsibility of semver to tell a language how packages should be isolated and loaded. That is a problem of a) the language and b) dependency resolution in the package manager.
So semver only works for "good" languages?
> Bundler, by design, does not allow the above, instead having a flat, consistent vision of dependencies.
Ok, so what happens with the app when packages managed by Bundler get fragmented by depending on an incompatible version of sub-dependency (commons-logging 1.1.1 vs 2.0.1 as in the example)?
Also note, even for languages and tooling supporting multiple library versions loaded side by side, there are scenarios where things break.
For example, the "libc apocalypse" situation in Rust https://github.com/rust-lang/libc/issues/547
Here after the "libc" module released a major version, the definition for the `void` C type in two versions of the lib are considered by the compiler as two different types, resulting in breakages everywhere around the library ecosystem.
There are also scenarios for dynamic languages / runtime errors.
> None of this is the responsibility of semver. In fact, semver would help the language provide tooling to detect that kind of "hey this instance is from foo-1.0 but you're trying to consume it in foo-2.0".
And what's next after it detected the dependency hell? It's too late and the person suffering is not in the position to fix it. You have to upgrade to "authentication 1.1.2" for security compliance, because the version 1.1.1 has known vulnerabilities. But that breaks the application, because the maintainer of the lower level dependency "commons-logging" follows semantic versioning.
The promise was to prevent dependency hell, not to detect it.
Quoting the ticket and reiterating the point of my first comment above:
Once again, the point of this ticket is to:
Remove the false promise that SemVer solves dependency hell by simply increasing major version.
-
Semantic Versioning 2.0.0 – Semantic Versioning
Even if coexistence of multiple library versions is supported, there are scenarios where things break.
For example, the "libc apocalypse" situation in Rust https://github.com/rust-lang/libc/issues/547
Here after the "libc" module released a major version, the definition for the `void` C type in two versions of the lib are considered by the compiler as two different types, resulting in breakages everywhere around the library ecosystem.
There are also scenarios for dynamic languages / runtime errors in statically typed languages.
My main problem with the current SemVer spec, is that it does not mention multiple lib versions problem, and promises the dependency hell issues can be solved simply by updating major version number. Thus encouraging to break backward compatibility freely.
Also note, it's not the case that SemVer is intended only for languages supporting multiple library versions. The SemVer is a product of Ruby community, and Ruby has a global namespace for classes and unable to have several versions of a lib simultaneously.
In 2000s they were breaking compatibility left and right, neglecting elementary compatibility practices. If you were working on an application, practically every time when you update dependencies, something would break.
So (in 2011 ?) they came out with this "manifesto" (Why such a big name? This scheme of versioning was well established in linkers and sonames of all Unix-like systems for decades - it goes back to at least 1987 paper "Shared Libraries in SunOS").
It's a good thing SemVer acknowledges finally that compatibility is a serious matter. Only that it's better to discourage compatibility breakages. An in cases when it's really needed (I agree such cases exists), there are things to take care of in addition to simply increase major version num.
-
Can rust be entirely written in rust and drop C usage in its code base ?
The libc crate exposes system C APIs in Rust code, and is used by the compiler and standard library. It also does not contain any C code. See for yourself.
-
7 ways to pass a string between 🦀 Rust and C
Ok, what if we are sure that our C code would use a given version of malloc/free only to allocate memory (are we ever sure about anything like that is out of the scope of the article)? Well, in this case we are brave enough to use libc crate in our rust code:
-
A generalized guide on porting std to a unix like platform?
Port libc. I recommend using bindgen for this.
-
When does the libc crate link with the build target’s libc?
While looking at the libc crate and its build script, I don’t quite understand when or how the crate’s libc definitions link to the build target’s actual libc.
-
What do you think about Zig?
For what it's worth, there's been discussion of this not only for glibc on Linux but also for BSDs which take many more liberties with API and ABI compatibility to keep their technical debt low. I can't summarise the years of discussion here but I encourage anyone interested to read through https://github.com/rust-lang/libc/issues/570
- Integrating Rust into the Android Open Source Project
-
Giving ADA a Chance
In answer to what appears to be a misunderstanding about Rust:
> Its foreign function interface seems particularly poorly implemented. The official Rust documentation suggests the use of the external third-party libc library (called a 'crate' in Rust parlance) to provide the type definitions necessary to interface with C programs. As of the time of writing, this crate has had 95 releases. Contrast this with Ada’s Interfaces.C package, which was added the language in Ada 95 and hasn’t needed to change in any fundamental way since.
Rust's libc crate isn't third-party, it's first-party, developed by the Rust project itself: https://github.com/rust-lang/libc/ . It's also not just for "type definitions necessary to interface with C programs"; here's the first heading and first paragraph of its README:
"libc - Raw FFI bindings to platforms' system libraries"
libc provides all of the definitions necessary to easily interoperate with C code (or "C-like" code) on each of the platforms that Rust supports. This includes type definitions (e.g. c_int), constants (e.g. EINVAL) as well as function headers (e.g. malloc).
The fact that this library contains low-level type definitions for every platform that Rust supports explains why it's had more than one release: new platforms get added, platforms add new interfaces, and platforms change the definitions of existing interfaces.
> It lacks basic features necessary for the task, like bitfields, and data structure packing.
The latter is achieved via the built-in `repr(packed)` attribute (https://doc.rust-lang.org/nomicon/other-reprs.html#reprpacke...) and the former is provided by the bitflags crate: https://crates.io/crates/bitflags (while unlike libc this does not live under the rust-lang org on Github, it does live under its own org which appears to be populated exclusively by Rust project team members).
-
Const-zero, a no_std crate* that acts like a const std::mem::zeroed()
It came up in this issue in the libc crate. The initializer for a static has to be const, which is why the issue submitter wanted it. He couldn't use lazy_static or once_cell, common patterns in Rust, since he was later using the static in a unix signal handler (which must be async signal safe).
rustc_codegen_cranelift
-
Cranelift code generation comes to Rust
Windows is supported. See https://github.com/rust-lang/rustc_codegen_cranelift/issues/....
- What part of Rust compilation is the bottleneck?
-
A Guide to Undefined Behavior in C and C++
> When this happens, it seems like it'll be possible to get the LLVM bits out of the bootstrap process and lead to a fully self-hosted Rust.
What do you mean by "when this happens"? GP's point is that this has already happened: the Cranelift backend is feature-complete from the perspective of the language [0], except for inline assembly and unwinding on panic. It was merged into the upstream compiler in 2020 [1], and a compiler built with only the Cranelift backend is perfectly capable of building another compiler. LLVM hasn't been a necessary component of the Rust compiler for quite some time.
[0] https://github.com/bjorn3/rustc_codegen_cranelift
[1] https://github.com/rust-lang/rust/pull/77975
-
What are some stuff that Rust isn't good at?
Note that the Cranelift codegen will eventually become standard for debug builds to speed them up.
-
Rust port of B3 from WebKit, LLVM-like backend
Maybe one day we'll have rustc b3 backend like what they did with Cranelift
-
Any alternate Rust compilers?
Additionally, there is gcc codegen for rustc (https://github.com/rust-lang/rustc_codegen_gcc), which is not a compiler per se, but an alternative code generator, with more architectures supported and other nice things. It's also coming along, but there's still a lot of work to do there too. There's also Cranelift codegen (https://github.com/bjorn3/rustc_codegen_cranelift), which is designed to make debug builds faster, but this is not as exciting/useful as the other 2.
-
Capsules, reactive state, and HSR: Perseus v0.4.0 goes stable!
For the instant reloading, that's in Sycamore, so you should speak to its devs, but as for the alternative compiler backend, it's not my project, but it uses Cranelift and works pretty well! See https://github.com/bjorn3/rustc_codegen_cranelift for details.
- Security Engineer looking for ways to see if any of my tasks could slowly be ported to Rust or should I just stick with Python.
- Rust is now officially supported on some Infineon microcontrollers! (more to come later this year)
-
Improving Rust compile times to enable adoption of memory safety
The more immediate goal of "distribute the cranelift backend as a rustup component" has been making good progress and seems like it might happen relatively soon https://github.com/bjorn3/rustc_codegen_cranelift/milestone/...
What are some alternatives?
Klib - A standalone and lightweight C library
wasmtime - A fast and secure runtime for WebAssembly
ctl - My variant of the C Template Library
gccrs - GCC Front-End for Rust
C-DataStructures-And-Algorithms - Generic data structures and algorithms implemented in c language.
sccache - Sccache is a ccache-like tool. It is used as a compiler wrapper and avoids compilation when possible. Sccache has the capability to utilize caching in remote storage environments, including various cloud storage options, or alternatively, in local storage.
rustix - Safe Rust bindings to POSIX-ish APIs
mrustc - Alternative rust compiler (re-implementation)
mustang - Rust programs written entirely in Rust
cranelift-jit-demo - JIT compiler and runtime for a toy language, using Cranelift
pottery - Pottery - A container and algorithm template library in C
tch-rs - Rust bindings for the C++ api of PyTorch.