Add xdg_basedir API - #157518
Conversation
|
r? @aapoalas rustbot has assigned @aapoalas. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
cc @BurntSushi (+1 on ACP) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Might be interesting to @rami3l. |
|
@Kobzol Thanks for the ping! Our current plan with @Cloud0310 regarding rust-lang/rustup#247 is slightly more complicated than this because it involves handling both old and new |
There was a problem hiding this comment.
Looks good to me - I had a bunch of comments here and there but nothing that I'd consider blocking.
Let me know your thoughts on the comments and one we've handled them one way or another (made changes or decided to ignore) then we can put this on the train.
There was a problem hiding this comment.
The bit of the doc comments that touch on installation rather than normal program execution are the last bit I'm not super confident in. Installation is a entirely separate can of worms that I'm not qualified to speak to, so the best I can do is try to recontectualize the GNU Make assuming spec to the Cargo build system here. (Which doesn't even have a concept of build or installation artifacts other than the executable bundle.)
| /// | ||
| /// If an application defines a data file to be at `$XDG_DATA_DIRS/appid/file.name`, this means that: | ||
| /// | ||
| /// - The initial data file should be installed to `{system_data_dir}/appid/file.name`. |
There was a problem hiding this comment.
{system_data_dir} here is our version of the XDG spec's
$datadir[...] with$datadirdefaulting to/usr/share.
AIUI, $datadir doesn't refer to an environment variable like the other $XDG_* variables, but to a conventional GNU Make variable for installation directories. The build-system agnostic version of this would be "program installation data directory base" or similar.
It feels like a cop-out to provide the XDG paths API but still leave an undefined template variable here, but I don't know how we could do better. This specifically is a concern of the installer, not of the installed program, as a properly configured system will ensure that this path is in $XDG_DATA_DIRS so that the installed data is actually found during lookup.
There was a problem hiding this comment.
Does this suggest that there should be an API to create an installer datadir path, given a $datadir template variable value?
There was a problem hiding this comment.
The current API surface is deliberately not giving app-specific paths, only the base directories that the app-specific folders go in. So such an API would just spit $datadir back out unchanged. $sysconfdir would just append /xdg. In any case, installation isn't really part of the XDG basedir spec, and if application file lookup is a contentious floating target, installers is even more so.
Another way to put the difference is that only the program that creates installable packages or whatever delivery mechanism needs to understand the conventions for installation, whereas every program that isn't just a single stateless executable needs to understand how to access auxiliary files.
| /// | ||
| /// If an application defines a configuration file to be at `$XDG_CONFIG_DIRS/appid/file.name`, this means that: | ||
| /// | ||
| /// - The initial configuration file should be installed to `{system_config_dir}/xdg/appid/file.name`. |
There was a problem hiding this comment.
{system_config_dir} here is our version of the XDG spec's
$sysconfdir[...] with$sysconfdirdefaulting to/etc.
AIUI, $sysconfdir doesn't refer to an environment variable like the other $XDG_* variables, but to a conventional GNU Make variable for installation directories. The build-system agnostic version of this would be "program installation configuration directory base" or similar.
It feels like a cop-out to provide the XDG paths API but still leave an undefined template variable here, but I don't know how we could do better. This specifically is a concern of the installer, not of the installed program, as a properly configured system will ensure that this path is in $XDG_CONFIG_DIRS so that the installed data is actually found during lookup.
|
Reminder, once the PR becomes ready for a review, use |
|
@aapoalas My main concerns I expressed earlier are still unaddressed.
Typically inclusion in the standard library is motivated through one of four forms (note, my observation - not official policy):
I just don't see this functionality really falling under any of the four categories. It doesn't form a common language, it's not fundamental, it doesn't provide an abstraction and isn't used all that commonly. The closest is nr. 4, but it's not really an API, more a convention, and it's not all that platform-specific even. |
That is misleading. The thing added in 0.8 is |
|
@ChrisDenton XDG Base Directory specification 0.8 also changed the separator of |
That is not in the published specification. It is in the repository but is explicitly noted as not being a breaking change: https://gitlab.freedesktop.org/xdg/xdg-specs/-/commit/22a6d100a1c28d5fb725fb1d3d2f872cf4308769
And this definitely won't be a breaking change for the rust standard library because the API lives in |
|
Is https://specifications.freedesktop.org/basedir/ not "published"? It's there and marked as version 0.8... If that's not version 0.8 it should be marked as 0.9-draft or whatever. |
|
Oh huh, "0.8" and "latest" are different. Interesting. My other points still stands though. |
As I think I said in one comment, I believe these are worthwhile concerns for blocking stabilisation of the API but I don't see them as worthwhile blockers for this PR: now, I'm just a first-time libs reviewer and my understanding and "feel" for this is lacking indeed, but the way I see it is:
I do have some points that I agree with you on: if the eventual point is for the std to offer an OS-independent "minimal API", it does not necessarily mean that each As a long-time Linux user, I'm personally also quite happy to see this stuff proposed: we'll make The Year of the Linux Desktop yet! :D @bors r+ rollup |
|
⌛ Testing commit 378da80 with merge 876e334... Workflow: https://github.com/rust-lang/rust/actions/runs/27469971600 |
Add xdg_basedir API Implements an API providing easy access to the XDG Base Directories. I chose to defer `runtime_dir` (`XDG_RUNTIME_DIR`) since the lack of a specified default (but specified expectation for applications to determine an alternative option somehow) makes the correct usage (and thus ideal API) less obvious. - Accepted ACP: rust-lang/libs-team#805 - Tracking issue: #157515
|
@bors yield |
|
Auto build was cancelled. Cancelled workflows: The next pull request likely to be tested is #157863. |
…uwer Rollup of 5 pull requests Successful merges: - #157518 (Add xdg_basedir API) - #157752 (Rename `errors.rs` file to `diagnostics.rs` (6/N)) - #157769 (Match expressions had not been updated to also show the match_source,…) - #157825 (Emit retags in codegen to support BorrowSanitizer (part 3)) - #157861 (Rename `errors.rs` file to `diagnostics.rs` (7/N))
Rollup merge of #157518 - CAD97:xdg_basedir, r=aapoalas Add xdg_basedir API Implements an API providing easy access to the XDG Base Directories. I chose to defer `runtime_dir` (`XDG_RUNTIME_DIR`) since the lack of a specified default (but specified expectation for applications to determine an alternative option somehow) makes the correct usage (and thus ideal API) less obvious. - Accepted ACP: rust-lang/libs-team#805 - Tracking issue: #157515
Revert "Rollup merge of rust-lang#157518 - CAD97:xdg_basedir, r=aapoalas" This reverts commit ac80064, reversing changes made to 8d6b380. <!-- homu-ignore:start --> - rust-lang#157515 is superseded - This includes just the revert that's the first commit in rust-lang#158936
Rollup of 5 pull requests Successful merges: - #162270 (Update `windows-bindgen` to 0.100.0) - #162492 (Revert "Rollup merge of #157518 - CAD97:xdg_basedir, r=aapoalas") - #162607 (Basic cleanup in `rustc_transmute`) - #162514 (Simplify diagnostic levels) - #162613 (iter::repeat_with, iter::successors, iter::from_fn added as diagnostic items)
Revert "Rollup merge of rust-lang#157518 - CAD97:xdg_basedir, r=aapoalas" This reverts commit ac80064, reversing changes made to 8d6b380. <!-- homu-ignore:start --> - rust-lang#157515 is superseded - This includes just the revert that's the first commit in rust-lang#158936
Rollup of 10 pull requests Successful merges: - #162270 (Update `windows-bindgen` to 0.100.0) - #162492 (Revert "Rollup merge of #157518 - CAD97:xdg_basedir, r=aapoalas") - #162607 (Basic cleanup in `rustc_transmute`) - #162619 (Add test for the missing Clone requirement for Cow slices) - #162172 (mention the opaque when its hidden type cannot be inferred) - #162514 (Simplify diagnostic levels) - #162546 (Use lld by default on `loongarch64-unknown-linux-gnu` nightly) - #162564 (yeet StabilityLevel) - #162613 (iter::repeat_with, iter::successors, iter::from_fn added as diagnostic items) - #162616 (regression test for async main diagnostic)
Rollup merge of #162492 - CAD97:rm-xdg, r=ChrisDenton Revert "Rollup merge of #157518 - CAD97:xdg_basedir, r=aapoalas" This reverts commit ac80064, reversing changes made to 8d6b380. <!-- homu-ignore:start --> - #157515 is superseded - This includes just the revert that's the first commit in #158936
View all comments
Implements an API providing easy access to the XDG Base Directories.
I chose to defer
runtime_dir(XDG_RUNTIME_DIR) since the lack of a specified default (but specified expectation for applications to determine an alternative option somehow) makes the correct usage (and thus ideal API) less obvious.std::os::unix::xdglibs-team#805xdg_basedir#157515