我有一个程序,如果在 Windows 上运行,需要访问 Windows API,如果在 Linux 上运行,则需要访问 Linux 的
libsecret
。
目前我正在使用
windows
板条箱来实现特定于 Windows 的功能。
有没有一种方法可以在 Linux 构建盒上编译 Windows API 功能?我不想依赖
windows
箱来为 Windows 构建。我希望任何人都能够构建该软件,并且我希望它能够在 Windows 上运行。有什么解决方案支持这个?
我不想为此使用功能标志。如果可能的话,我希望相同的可执行文件可以在所有平台上运行。
Rust 具有
cfg
宏,仅包含取决于操作系统和许多其他相关条件的代码。在这里深入阅读:https://doc.rust-lang.org/reference/conditional-compilation.html
简短示例(取自该链接^)
#[cfg(target_os = "linux")]
fn linux_only() {
// do linux stuff
}