如何排除在 OS X 上构建的文件? [英] How do I exclude a file from being built on OS X?

查看:44
本文介绍了如何排除在 OS X 上构建的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 src/bin/linux-only.rs 它做了一些只在 Linux 上工作的事情(例如只存在于 Linux 上的 libc 绑定).我想排除在 OS X 上构建的文件.

I have src/bin/linux-only.rs which does some things which work on Linux only (e.g. libc bindings which only exist on Linux). I want to exclude that file from being built on OS X.

我开始将 #[cfg(target_os = "linux")] 放在 linux-only.rs 的每个块上,但这使源代码变得杂乱无章原因.

I started putting #[cfg(target_os = "linux")] on every block in linux-only.rs but that is cluttering up the source code beyond any reason.

有没有更好的方法来做到这一点?

Is there a nicer way to do this?

推荐答案

Writing #![cfg(target_os = "linux")](注意感叹号)为整个文件工作(只要它包含一个模块),而不仅仅是为下一个块(项目)工作.来源:Rust 参考.

Writing #![cfg(target_os = "linux")] (note the exclamation mark) at the top of the file will work for the whole file (as long as it contains a single module), not just for the next block (item). Source: Rust reference.

编辑:如果您可以将该文件移动到自己的 crate 中,则可以利用 Cargo 的 特定于平台的依赖项.

Edit: if you can move that file into its own crate, you could take advantage of Cargo's platform-specific dependencies.

这篇关于如何排除在 OS X 上构建的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆