rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Fix source order sorting.

Open reitermarkus opened this issue 1 year ago • 20 comments

Fixes https://github.com/rust-lang/rust-bindgen/issues/2556.

Previously, headers included with -include were not added to the includes map since they don't have a source file. This is now fixed.

Also, some wrong match arms were removed/fixed.

reitermarkus avatar Jun 16 '23 12:06 reitermarkus

cc @glandium @emilio

Please have a look.

reitermarkus avatar Jun 16 '23 12:06 reitermarkus

:umbrella: The latest upstream changes (presumably ee980e1afeedc2afadafa6d8bdface54b5027e2d) made this pull request unmergeable. Please resolve the merge conflicts.

bors-servo avatar Jun 17 '23 16:06 bors-servo

I refactored SourceLocation to be an enum and the sorting is now split between SourceLocation and IncludeLocation. In my opinion it is a bit easier to follow that way.

reitermarkus avatar Jun 20 '23 20:06 reitermarkus

@pvdrz, I fixed the edge case you gave and added a test for it.

reitermarkus avatar Jun 21 '23 21:06 reitermarkus

I changed all file names from String to PathBuf since we need to absolutize them before comparing them, e.g. running your example with cargo run -- a.h would actually try to compare the strings "a.h" and "./a.h" before.

reitermarkus avatar Jun 21 '23 21:06 reitermarkus

@emilio, do you have an alternative? The status quo is simply incorrect in some cases.

The only alternative I can see is to never generate constants for variable-like macros and only ever generate Rust macros instead. That way there is never a naming or ordering conflict.

Note that this is also needed for the same reason for function-like macros and functions in https://github.com/rust-lang/rust-bindgen/pull/2369.

reitermarkus avatar Jun 29 '23 15:06 reitermarkus

@reitermarkus I'm confused, my understanding is that this sorting fixes some cases but breaks others, is that not the case?

emilio avatar Jul 11 '23 10:07 emilio

No, it only broke some cases due to the sorting being wrong/incomplete previously. Otherwise nothing should break, except for some auto-generated names having a different index.

reitermarkus avatar Jul 11 '23 19:07 reitermarkus

Confirmed that this works for one of my projects.

alex avatar Aug 08 '23 21:08 alex

Thanks for testing, @alex.

@emilio, @pvdrz, can you have another look at this?

reitermarkus avatar Aug 15 '23 16:08 reitermarkus

@pvdrz, @emilio, please have another look here, thank you.

reitermarkus avatar Oct 28 '23 00:10 reitermarkus

@pvdrz, @emilio, another ping here.

reitermarkus avatar Nov 29 '23 15:11 reitermarkus

:umbrella: The latest upstream changes (presumably 5ff913ab3349db1905cfbbf44a9121cbc223249d) made this pull request unmergeable. Please resolve the merge conflicts.

bors-servo avatar Dec 18 '23 09:12 bors-servo

@pvdrz, @emilio, can you have another look at this?

reitermarkus avatar Jan 06 '24 12:01 reitermarkus

turn it off by default

This is a prerequisite for supporting complex macros (https://github.com/rust-lang/rust-bindgen/pull/2369), so it can't be optional.

reitermarkus avatar Jan 13 '24 14:01 reitermarkus

:umbrella: The latest upstream changes (presumably 46c06e5ef11c01680edd9ca250ed0c32b6cdc9e9) made this pull request unmergeable. Please resolve the merge conflicts.

bors-servo avatar Jan 15 '24 17:01 bors-servo

:umbrella: The latest upstream changes (presumably 285eb56cf5a02ee778880b8e1b7bb2e8118a5a88) made this pull request unmergeable. Please resolve the merge conflicts.

bors-servo avatar Feb 19 '24 16:02 bors-servo

@pvdrz, @emilio please have another look.

I'd rather keep the CXFile rather than reading the path and doing IO to absolutize it eagerly for most callers that don't need that...

I have re-added the File struct as SourceFile now to avoid eagerly absolutizing every path.

reitermarkus avatar Feb 20 '24 09:02 reitermarkus

:umbrella: The latest upstream changes (presumably 3b5ce9c5861cd2e97e9789f5b686238656abd2d6) made this pull request unmergeable. Please resolve the merge conflicts.

bors-servo avatar Mar 19 '24 22:03 bors-servo