Major Changes
Portable Types
In #1266, we added support for transpiling portable integer types like size_t and uint64_t. Previously, these were translated in a platform-dependent way, as C defines these portable types as typedefs of the platform-dependent primitive types like int and long.
Now we special case these portable integer types and make sure to translate them as the equivalent Rust portable types, so size_t becomes usize and uint64_t becomes u64, for example.
These still often go through multiple typedefs in C, which become multiple type aliases in Rust, so the definitions are not always textually identical in Rust, but the underlying types should always be portable now.
Const Macros
We previously had an unstable and often broken --translate-const-macros option, which translated const/object-like C macros as Rust consts. This has now been significantly improved and --translate-const-macros conservative is enabled by default. The option has been split into none, conservative, and experimental, so we still allow the previous more experimental translations under experimental, but conservative should generally work and thus is enabled by default. However, some const macros are not yet translatable, like macros referencing other variables, functions, etc., which conservative skips, while some const macros can never be properly translated as a Rust const, such as when it references a variable that is not yet defined. We're still working on improving these cases so that more const macros can be successfully translated, but the current version should capture most usages in the wild. For tmux, 98% of const macro definitions and expansions are successfully translated, for example.
One area in particular we're still working on is the combination of const macros and portable types. The features don't yet work together seamlessly, with const macro types using the old non-portable types and then casting to the portable type at use sites.
SrcLoc Sorting
On stable, sorting now panics when a non-total order is discovered, which was the case in fn compare_src_locs. We had previously tried to fix this, and fixed it in a bunch of cases, but it was still cropping up sometimes, like when transpiling libxml2.
We've now fixed the root cause of incorrect SrcLoc::fileids when we calculate #include paths. Besides fixing any panics, this should improve the sorting of items, which was sometimes buggy before, likely due to this.
cmake 4.0 Support
#1214 adds support for cmake 4.0 by increasing the minimum to cmake 3.5. This should fix any installation issues due to using a new cmake.
LLVM/Clang Support
Misc. Bug Fixes
- (#1265) Handle all cases of extra braces in string initializers.
- (#1340) Remove extraneous
::separators in paths with arguments (e.g.::core::mem::size_of::<libc::c_int>::()). - (#1359) Store
allocavector at function-level scope, matching C. - (#1360) Avoid mutable transmutes (UB) for string literals (
mem::transmute::<[u8; N], [c_char; N]>(*b"")instead of*mem::transmute::<&[u8; N], &mut [c_char; N]>(b"")). - (#1361) Support anonymous
struct/union/enums withinstructs andunions. - (#1374) Inline asm fixes for
ioq3.
Misc. Improvements
- (#1221, #1222, #1229, #1381) Prefer
core::overlibc::andstd::, fixing--emit-no-std. - (#1218) Prefer
[x; N]over[x, ..., x]. - (#1344) Skip redundant expressions for
++and--(i += 1; i;vs.i += 1;). - (#1373)
use libconly when needed.
New Instrinsics Added
- (#814) C11 atomics
- (#1342)
_Static_assert - (#1235)
__float128 - (#1259, #1260)
__builtin_rotateright* - (#1263, #1292)
__builtin_ia32_pause - (#1263, #1292)
__builtin_arm_yield - (#1129)
__builtin_ia32_vperm2f128_pd256 - (#1129)
_mm256_permute2f128_pd
Changelog
- docs/readme: Update
beararguments by @javierhonduco in #1206 - GH Actions: bump tagged versions of actions/cache by @brk in #1212
- build: support cmake 4.0 by @chenrui333 in #1214
- CI updates (Ubuntu 22, LLVM 15, pinned
once_cell) by @folkertdev in #1219 - Remove some
libcdependencies. by @nnethercote in #1221 - Fixes to
rust-toolchain.tomlhandling by @joshtriplett in #1225 - Reduce
libcusage inc2rust-transpileby @nnethercote in #1222 - Remove more unnecessary
libcusage by @nnethercote in #1229 - Make
test_translator.pytests pass on LLVM 19 by @nnethercote in #1230 - Support
__float128, which shows up in clang headers on some systems by @joshtriplett in #1235 - Allow running multiple transpiles in parallel by @jameysharp in #1241
- transpile: remove invalid
Punct::new(' ')infn convert_asmand updateproc-macro2by @kkysen in #1244 - Move Linux CI from Azure Pipelines to GitHub Actions by @joshtriplett in #1232
- Bump bindgen to be able to handle CXCursor_LinkageSpec in LLVM18+ by @spastorino in #1243
- Fix getBitWidthValue compilation error on LLVM 20+ by @shirok1 in #1248
- Introduce some snapshot tests of c2rust-transpile by @jameysharp in #1246
transpile: some snapshot test fixes by @kkysen in #1258- Support C11 atomics required by dav1d by @thedataking in #814
transpile: impl__builtin_ia32_pauseand__builtin_arm_yieldby @thedataking in #1263- Various small cleanups by @fw-immunant in #1267
- More driveby cleanups by @fw-immunant in #1268
transpile: Add SIMD intrinsic__builtin_ia32_vperm2f128_pd256/_mm256_permute2f128_pdby @Kriskras99 in #1129- transpile: fix doc tests on aarch64 (
c_charis unsigned there) by @kkysen in #1255 transpile: impl__builtin_rotateright*ascore::intrinsics::rotate_rightby @kkysen in #1259transpile: emit.rotate_{left,right}instead ofcore::intrinsics::rotate_{left,right}by @kkysen in #1260- Add
tests/requirements.txtdependencies into nix python environment by @Chobbes in #1269 - ci: allow reusing testsuite workflow by @fw-immunant in #1272
- Allow platform-dependent snapshot test results by @fw-immunant in #1270
- transpile: operators: resolve type when checking for unsignedness by @fw-immunant in #1273
- fix compilation error on clang/llvm 21 by @bungcip in #1274
- ci: switch python to use
uvby @kkysen in #1276 - ci: move macOS
azure-pipelines.ymlto GitHub Actions with a matrix by @kkysen in #1275 - ci: add
archto the matrix for clarity by @kkysen in #1284 - Fix skipping of Paren expressions in typed AST iterators by @fw-immunant in #1286
- ci: run on both Ubuntu 22.04 and ubuntu-latest by @fw-immunant in #1288
- Revert "transpile: snapshot: build to stdout rather than creating+deleting rlib" by @kkysen in #1287
- ci: reorder some steps to cache more (
rustup) and run fast checks earlier by @kkysen in #1289 - transpile: handle all cases of extra braces in string initializers by @kkysen in #1265
- transpile: do not allow f128::new in const contexts by @fw-immunant in #1294
- A couple testing tweaks by @fw-immunant in #928
- test_translator: remove
#![feature(nll)], stabilized in 1.63 by @kkysen in #1290 - scripts: restore
provision_mac.sh(removed in #1275) and remove docker scripts by @kkysen in #1299 - transpile: save platform-specific
.rsfiles, too by @kkysen in #1291 - ci: test on aarch64 macOS by @kkysen in #1280
- transpile: add arch-specific snapshots by @kkysen in #1293
- transpile: revert
__builtin_ia32_pause/__builtin_arm_yieldto emit_mm_pauseand__yieldinstead of cross-platformspin_loopby @kkysen in #1292 - Upgrade to Syn 2 by @bungcip in #1271
- ci: use
awalsh128/cache-apt-pkgs-action@latestto cacheapt installby @kkysen in #1277 - Remove snapshot .rs files by @fw-immunant in #1300
- transpile: use a repeat expression for arrays with a single zero initializer by @folkertdev in #1218
- transpile: syntax highlight
*transpile*.c.snaps as Rust by @kkysen in #1301 - transpile: add docs and some renames/refactors for code related to macros by @kkysen in #1303
- Translate C integer types to portable Rust types by @fw-immunant in #1266
- transpile: tests: snapshots: hard-code nightly toolchain for now by @kkysen in #1310
- tests: fix out-of-bounds UB in
test_casts.rsandcast_funptr.cby @kkysen in #1309 - transpile: add
macros.csnapshot by @kkysen in #1304 - transpile: add
--translate-const-macros conservativeby @kkysen in #1305 - Revert "transpile: make
--translate-{const,fn}-macros conservativethe default for the CLI, too" by @kkysen in #1313 - ci: run
c2rust-testsuiteon all PRs, not just those intomasterby @kkysen in #1312 - transpile: fix some mistakes in
macros.csnapshot by @kkysen in #1314 - Apply clippy fixes to stable crates by @brk in #1308
- Add libzstd-dev to internal testsuite dependencies by @thedataking in #1318
- transpile: update
fn convert_exprdocs and remove unused code by @kkysen in #1323 - transpile: insert casts at const macro expansion sites to their portable
override_tys by @kkysen in #1322 - readme: add known uses of
c2rust transpileby @kkysen in #1327 - transpile: remove unused function in builder by @bungcip in #1316
- ci: remove x86_64 macOS by @kkysen in #1337
- transpile: some doc improvements from #1306 by @kkysen in #1336
- transpile: make
TypedAstContext::macro_{invocations,expansions,expansion_test}intoIndexMaps instead ofHashMaps by @kkysen in #1334 - transpile: refactor
single_attrandcall_attrto just usemk().meta_namevalue()andmk().meta_path()instead of creating structure itself by @bungcip in #1343 - ci: don't install
cmakeon macOS as it's already installed by @kkysen in #1351 - Remove extraneous separator from paths with arguments by @brk in #1340
- transpile: unconditionally make
consts useunsafeblocks for--translate-const-macros conservativeby @kkysen in #1335 - properly handle
ASTEntryTag::TagStaticAssertDeclconversion by @bungcip in #1342 - transpile: expand
--translate-const-macros conservativeto a lot moreCExprKinds by @kkysen in #1306 - Dont write unused unary expr when operator is increment/decrement by @bungcip in #1344
- scripts/test_translator.py: restore '[ OK ]' prints by @fw-immunant in #1358
- Change VisitEnumDecl to TraverseDecl by @bungcip in #1357
- Run rustfmt on the tests by @Rua in #1363
- transpile: expand
--translate-const-macros conservativeto handle statements by @kkysen in #1338 - transpile: add support for
CTypeKind::UnaryTypes in--translate-const-macros conservativeby @kkysen in #1346 - transpile: support
CastKind::ArrayToPointerDecays in--translate-const-macros conservativeby @kkysen in #1349 - transpile: some simplifications before adding
override_tysto const macros by @kkysen in #1370 - Include libc dependency only when needed by @Rua in #1373
- Avoid
unsafein const macro translations except where necessary by @fw-immunant in #1339 - Ensure crate name is a valid identifier by @Rua in #1375
- Store
allocavectors in top function scope by @Rua in #1359 - Avoid mutable transmute in string literals by @Rua in #1360
- Fix inline assembly translation in ioq3 by @fw-immunant in #1374
- transpile: tests: snapshots: fix vm_x86.c snapshot test by @fw-immunant in #1378
- transpile: update
instato1.43.2for the fix toINSTA_GLOB_FILTERso that the snapshot file is correctly resolved by @kkysen in #1377 - transpile: const macros: strip implicit casts from macro expansion sites by @fw-immunant in #1311
- transpile: support anonymous
struct/union/enums withinstructs andunions by @bungcip in #1361 - cleanup AST builder functionality by @bungcip in #1350
- pdg: use mutex around
cargo runs to avoid file race conditions by @kkysen in #1380 - transpile: use
core::ffi::c_*instead ofstd::ffi::c_*by @kkysen in #1381 - transpile: update
records.csnapshot test to include #1381 after #1361 merged by @kkysen in #1383 - ci: enable
libxml2by @kkysen in #1385 - transpile: const macros: skip
DeclRefs by @kkysen in #1387 - ci: don't cache apt pkgs for
c2rust-testsuitesincedpkg-querydoesn't work correctly by @kkysen in #1389 - disable warning from clang in snapshot test by @bungcip in #1393
- ci: run testsuite python2 transpilation by @fw-immunant in #1384
- transpile: separate top-level decl converting and emitting by @kkysen in #1371
- transpile: some docs/refactoring improvements made while fixing
SrcLocsorting by @kkysen in #1401 - transpile: actually fix
SrcLocsorting by fixing include pathfileids by @kkysen in #1400 - Prepare for 0.21.0 release by @kkysen in #1402
New Contributors
- @javierhonduco made their first contribution in #1206
- @brk made their first contribution in #1212
- @chenrui333 made their first contribution in #1214
- @nnethercote made their first contribution in #1221
- @joshtriplett made their first contribution in #1225
- @spastorino made their first contribution in #1243
- @shirok1 made their first contribution in #1248
- @Chobbes made their first contribution in #1269
- @Rua made their first contribution in #1363
Also, many thanks to @Rua and @bungcip for helping us fix a ton of bugs!
Full Changelog: v0.20.0...v0.21.0