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. |
|
The ACP being accepted means that at least one T-libs-api member has +1'd the inclusion of this API unstably in std. It does not necessarily confer intent to stabilize. What it says is more along the lines that the given problem statement is interesting enough to experiment and learn what a solution provided inside std would look like, and if there are any unforeseen issues. But to at least partially address some of your points with my reasoning for opening the ACP, @orip:
I, personally, believe that there isn't a one-size-fits-all solution to application paths. Existing applications each have their own unique backwards-compatibility considerations, and even brand new ones have widely different constraints and expectations. But the standard library absolutely can and should provide the pieces that each application can assemble into their domain-appropriate solution. Aside: your point 4 allows for platform-specific API to be put into std. Does this not qualify because its an interface defined in terms of environment variables, which are technically platform-independent? Does that mean that an API providing the value of the |
There was a problem hiding this comment.
I do believe this is reasonable to merge as-is. I also understand that this might get reverted, depending on what T-libs-api decides w.r.t. this problem space. But I don't see any benefit in holding back this PR. It's completely fine to remove unstable API if we determine it's not a good fit for std.
@rustbot ready
I think it is. It was version 0.6 in 2003, and then in 2010 0.7 came out, and in 2021 0.8 came out. There is no indication the standard is finalized. The standard has changed multiple times after appearing stable for a couple years.
The stability story with it therefore is "it literally cannot change". Again, not a good fit for the standard library if you predict changes to this could occur in the future.
I think that's a strong indicator it doesn't belong in the standard library then, unless you can abstract all possible choices into a one-configured-sized-fits-all solution.
Yes, that falls under category 3 "provides abstraction". I would not be concerned for fit-for-purpose in that case for the stdlib (although my other concerns around stability would remain). I don't buy the argument that "because this functionality would be part of an abstraction, it should be provided as a piece". You could apply that for literally all the platform-specific implementations of
I don't want to use libraries that directly look in specific configuration file locations rather than having their configuration through their API in the first place. If that is the code pattern this is supposed to enable I even more strongly oppose to it.
Essentially, yes. The point of nr. 4 is to provide nice safe Rust abstractions and avoid having to write FFI or inline assembly. If there's a clear, safe and portable (to all relevant platforms) alternative I don't think you qualify under nr. 4.
I don't know enough about the precise definition of Windows folders to answer this. The latter method sounds safer against accidental environment pollution though. |
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
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