Skip to content

refactor: add cfg aliases - #11016

Draft
xtqqczze wants to merge 3 commits into
uutils:mainfrom
xtqqczze:cfg_aliases/selinux
Draft

xtqqczze wants to merge 3 commits into
uutils:mainfrom
xtqqczze:cfg_aliases/selinux

Conversation

@xtqqczze

@xtqqczze xtqqczze commented Feb 18, 2026 •

Copy link
Copy Markdown
Collaborator

USe cfg-aliases crate for selinux and smack features.

@xtqqczze xtqqczze mentioned this pull request Feb 18, 2026
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/date/resolution. tests/date/resolution is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/rm/isatty. tests/rm/isatty is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/tail/retry. tests/tail/retry is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/pr/bounded-memory (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/cp/link-heap is now being skipped but was previously passing.
Note: The gnu test tests/printf/printf-surprise is now being skipped but was previously passing.

@xtqqczze
xtqqczze force-pushed the cfg_aliases/selinux branch from b98f746 to bf4239f Compare February 18, 2026 19:02
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Congrats! The gnu test tests/date/date-locale-hour is no longer failing!
Note: The gnu test tests/cp/link-heap is now being skipped but was previously passing.
Note: The gnu test tests/dd/no-allocate is now being skipped but was previously passing.
Note: The gnu test tests/seq/seq-epipe is now being skipped but was previously passing.
Note: The gnu test tests/tail/pipe-f is now being skipped but was previously passing.

@xtqqczze
xtqqczze force-pushed the cfg_aliases/selinux branch from bf4239f to 0fcde2d Compare February 18, 2026 19:13
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Note: The gnu test tests/cut/cut-huge-range is now being skipped but was previously passing.

@xtqqczze
xtqqczze marked this pull request as ready for review February 18, 2026 19:54

@sylvestre sylvestre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry
i really don't like the duplication of src/uu/*/build.rs

@xtqqczze

Copy link
Copy Markdown
Collaborator Author

I don’t like the duplication either, but I’m not sure how to avoid it. Do you have suggestions on how we could factor this out?

@sylvestre

Copy link
Copy Markdown
Contributor

i prefer the current state than this duplication, sorry

@xtqqczze

xtqqczze commented Feb 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

I guess we could include!("../../common/common_cfg.rs") in each build.rs?

@sylvestre

Copy link
Copy Markdown
Contributor

if it works, it would be better

@xtqqczze

Copy link
Copy Markdown
Collaborator Author

I've tried specifying the cfg in .cargo/config.toml but it doesn't support expressions like all(...) or any(...).

The only alternative I can think of is introducing a small common_cfg helper crate to centralize the cfg_aliases logic, but that feels a bit heavy-handed.

@xtqqczze

xtqqczze commented Feb 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

I guess we could include!("../../common/common_cfg.rs") in each build.rs?

@sylvestre If this works, would you approve the changes?

@oech3

oech3 commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Cannot we use workespace's toplevel build.rs?

@sylvestre

Copy link
Copy Markdown
Contributor

Cannot we use workespace's toplevel build.rs?

i don't think it works. i tried too and failed

@sylvestre

Copy link
Copy Markdown
Contributor

I guess we could include!("../../../common/common_cfg.rs") in each build.rs?

@sylvestre If this works, would you approve the changes?

yes
thanks

@xtqqczze

xtqqczze commented Apr 3, 2026 •

Copy link
Copy Markdown
Collaborator Author

I guess we could include!("../../common/common_cfg.rs") in each build.rs?

Annoyingly, this didn't work.

@github-actions

github-actions Bot commented Apr 3, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/cp/cp-a-selinux. tests/cp/cp-a-selinux is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/cp/link-heap is now being skipped but was previously passing.
Note: The gnu test tests/env/env-signal-handler was skipped on 'main' but is now failing.

@sylvestre
sylvestre force-pushed the cfg_aliases/selinux branch from 945a586 to 5d3b4fd Compare April 4, 2026 11:03
@github-actions

github-actions Bot commented Apr 4, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/cp/cp-a-selinux. tests/cp/cp-a-selinux is passing on 'main'. Maybe you have to rebase?
Note: The gnu test tests/cut/cut-huge-range is now being skipped but was previously passing.

@xtqqczze
xtqqczze force-pushed the cfg_aliases/selinux branch from 5d3b4fd to 971a907 Compare April 4, 2026 18:06
@github-actions

github-actions Bot commented Apr 4, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/cp/cp-a-selinux. tests/cp/cp-a-selinux is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/tail/pipe-f is now passing!

@oech3

oech3 commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

I don't like symlink since it breaks tarball extraction on Windows, but can you symlink build.rs?

@xtqqczze

Copy link
Copy Markdown
Collaborator Author

I don't like symlink since it breaks tarball extraction on Windows, but can you symlink build.rs?

Can't do this because some utilities already have a build.rs.

@xtqqczze

This comment was marked as outdated.

@xtqqczze
xtqqczze marked this pull request as ready for review September 27, 2026 09:04
@xtqqczze

Copy link
Copy Markdown
Collaborator Author

@sylvestre Actually, I don't think we should move the alias definitions to a common location. They depend on features defined by each crate (e.g. selinux), so a shared definition would have to assume those features exist everywhere. That would couple the common layer to crate-specific feature names.

@xtqqczze
xtqqczze force-pushed the cfg_aliases/selinux branch 2 times, most recently from 6140912 to 39cf1c6 Compare September 28, 2026 14:02
@xtqqczze
xtqqczze requested a review from sylvestre September 28, 2026 17:39
@xtqqczze
xtqqczze force-pushed the cfg_aliases/selinux branch from 39cf1c6 to 42dd93a Compare October 5, 2026 10:54
@xtqqczze
xtqqczze force-pushed the cfg_aliases/selinux branch 3 times, most recently from 49e4675 to 3a61a24 Compare October 16, 2026 16:54
@xtqqczze
xtqqczze force-pushed the cfg_aliases/selinux branch from 3a61a24 to a997a68 Compare October 18, 2026 03:10
@oech3

oech3 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

@zicklag Is there any way to share one config given by cfg_aliases at workspace?

@zicklag

zicklag commented Oct 22, 2026

Copy link
Copy Markdown

Oh, that's a great question! I need to double-check the way that cargo handles the custom cfgs before I know for sure.

You might be able to just put the cfg aliases in a crate that is included in all your other crates and they might be inherited, but I haven't verified yet.

If that doesn't work then it would be reasonable to add a feature to cfg_aliases specifically for that.

I'll try to test it out today and let you know.

@xtqqczze

xtqqczze commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator Author

I guess we could include!("../../common/common_cfg.rs") in each build.rs?

This actually works, but rust-analyzer has an issue and shows a macro error: rust-lang/rust-analyzer#20129

@zicklag When I last looked into this, that approach turned out to be non-viable due to a rust-analyzer issue.

@zicklag

zicklag commented Oct 22, 2026

Copy link
Copy Markdown

Oh, interesting.

I just confirmed that the cfgs are not inherited from dependencies' build scripts ( which makes sense, otherwise there could be namespacing issues ).

I'll experiment with options and share what I find.

@zicklag

zicklag commented Oct 22, 2026 •

Copy link
Copy Markdown

OK, I think I found something that works pretty nicely.

In your workspace you can create a file like cfgs.rs:

pub fn activate() {
    cfg_aliases::cfg_aliases! {
        sixtyfour: { target_arch = "x86_64" },
        thirtytwo: { target_arch = "x86" }
    }
}

Then in each crate that will need to use the aliases you can do this in the build.rs:

#[path = "../cfgs.rs"]
mod cfgs;

fn main() {
    cfgs::activate();
}

Rust analyzer seems happy with it for me.

Let me know if that doesn't work for you for some reason. 🫡

@xtqqczze
xtqqczze marked this pull request as draft October 22, 2026 16:21
@xtqqczze

Copy link
Copy Markdown
Collaborator Author

@zicklag Thanks! That approach worked well. As a first step, I’ve opened #15634.

@xtqqczze xtqqczze self-assigned this Oct 30, 2026
@xtqqczze

Copy link
Copy Markdown
Collaborator Author

Depends on #15634.

@xtqqczze xtqqczze closed this Oct 30, 2026
@xtqqczze

Copy link
Copy Markdown
Collaborator Author

@zicklag With your approach, I occasionally encounter a rust-analyzer E0583 error:

unresolved module, can't find module file: ../../../cfg_aliases.rs

However, as described in rust-lang/rust-analyzer#20129, this can be worked around by explicitly adding the file to rust-analyzer's VFS includes:

"rust-analyzer.vfs.extraIncludes": ["${workspaceFolder}/cfg_aliases.rs"]

@xtqqczze xtqqczze reopened this Oct 31, 2026
@xtqqczze
xtqqczze force-pushed the cfg_aliases/selinux branch from a997a68 to 07a5e95 Compare October 31, 2026 11:45

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants