有没有办法优雅地拒绝在不受支持的 OS 上安装 opam 包?

Is there a way to gracefully refuse to install an opam package on an unsupported OS?

我正在开发一个 opam 包,虽然将来有望在所有操作系统上运行,但目前仅基于 Linux。我想告诉尝试在 MacOS 上安装的用户,该过程不会成功。我在 opam 包描述中看到过这样的东西:

opam-version: "2.0"
authors: "Person Maintainerson"
maintainer: "Person Maintainerson"
build: [
  ["./configure"
  "amd64-linux" {os = "linux"}
  "amd64-macosx" {os = "macos"}
  "amd64-cygwin" {os = "cygwin"}]
  [make]
]
install: [
  [make "install"]
]
synopsis: "A one-line description"
url {
  src: "proto://path/to/source.tar.gz"
}

但我不知道如何告诉 opam 不要做某事。

opam manual 中有关于如何为失败打印特定消息的描述,但是从示例中我不清楚 <filter>.[=16= 的语法是什么]

post-messages: [ <string> { <filter> } ... ]: allows one to print specific messages to the user after the end of installation. The special boolean variable failure is defined in the scope of the filter, and can be used to print messages in case there was an error (typically, a hint on how it can be resolved, or a link to an open issue). success is also defined as syntactic sugar for !failure.

有一个 available: 字段应该适用于此:http://opam.ocaml.org/doc/Packaging.html#Advanced-usage

OS constraints: The available field is a formula that determines your package's availability based on the operating system or other global opam variables. For example:

available: [ os != "macos" ]

在你的情况下,我认为应该是 [ os = "linux" ]

顺便说一句,如果您决定使用 dune-project 文件生成 opam 文件,您将需要一个模板,如下所示:https://github.com/yawaramin/ocaml-decimal/blob/2907175c02ca1bb117ee9703b8d642b721a3d6e8/decimal.opam.template

这是因为 dune-project 文件(还)不支持 available: opam 字段,所以他们需要这个额外的模板文件来传递它。