问题描述
假设我有一个具有以下结构的简单项目:
.├── 沙丘项目└── src└── 斌├── 沙丘└── main.ml沙丘项目
(lang dune 2.7)(命名我的项目)(包裹(命名我的项目)(剧情简介我的项目")(描述基本项目"))
沙丘
(可执行(姓名主要)(public_name myproject))
当使用 dune build
编译时,我有一个新目录 _build
,其结构如下:
_build├── 默认│ ├── 沙丘项目│ ├── META.myproject│ ├── myproject.dune-package│ ├── myproject.install│ └── src│ └── 斌│ ├──沙丘│ ├── main.exe│ └── main.ml├── 安装│ └── 默认│ ├── bin│ │ └── myproject ->../../../default/src/bin/main.exe│ └── lib│ └── 我的项目│ ├── dune-package ->../../../../default/myproject.dune-package│ └── META ->../../../../default/META.myproject└── 日志
所以沙丘能够创建从 main.exe
到 myproject
的符号链接,但我实际上希望 myproject
在 中.
而不是在 _build/install/default/bin
我尝试了三件事:
在我的
dune
文件中添加规则(promote (into ../../))
.它实际上复制源目录中的main.exe
而不是myproject
并且dune clean
不会删除main.exe
> 在根目录中在我的
dune
文件中添加以下规则:(规则(目标我的项目)(deps ../../myproject)(动作(复制 %{target} %{deps})))
这给了我以下错误:
❯ 沙丘建造文件src/bin/dune",第 6 行,字符 0-88:6 |(规则7 |(目标我的项目)8 |(deps ../../myproject)9 |(动作(复制 %{target} %{deps}))10 |)错误:未找到适用于 myproject 的规则错误:以下文件之间的依赖循环:_build/default/src/bin/myproject完成:0/0(工作:0)%
在我的
dune
文件中添加以下规则:(规则(目标 main.exe)(deps ../../myproject)(动作(复制 %{target} %{deps})))
这给了我以下错误:
❯ 沙丘建造错误:为 _build/default/src/bin/main.exe 生成了多个规则:- src/bin/沙丘:6- src/bin/沙丘:2完成:0/0(工作:0)%
老实说,我不知道我还能做什么.我阅读了手册,但找不到解决方案.我不介意我是否可以只输入 dune run
但由于 dune 允许构建多个可执行文件,我知道这不是一个选项.我希望能够编写 dune run myproject
,因为我使用的是可执行文件的公共名称,但 dune 找不到它.所以我只想在我的根目录中有 myproject
这样我就可以输入 ./myproject
并且很高兴.
你知道 dune exec
吗?这就是你所说的 dune run
我相信.
从你的项目根目录,你可以执行dune exec ./bin/main.exe
.
Let's say I have a simple project with the following structure:
.
├── dune-project
└── src
└── bin
├── dune
└── main.ml
dune-project
(lang dune 2.7)
(name myproject)
(package
(name myproject)
(synopsis "myproject")
(description "Basic project")
)
dune
(executable
(name main)
(public_name myproject)
)
When compiling with dune build
I have a new directory _build
with the following structure:
_build
├── default
│ ├── dune-project
│ ├── META.myproject
│ ├── myproject.dune-package
│ ├── myproject.install
│ └── src
│ └── bin
│ ├── dune
│ ├── main.exe
│ └── main.ml
├── install
│ └── default
│ ├── bin
│ │ └── myproject -> ../../../default/src/bin/main.exe
│ └── lib
│ └── myproject
│ ├── dune-package -> ../../../../default/myproject.dune-package
│ └── META -> ../../../../default/META.myproject
└── log
So dune is able to create a symlink from main.exe
to myproject
but I actually want myproject
to be in .
and not in _build/install/default/bin
I tried three things:
Add the rule
(promote (into ../../))
in mydune
file. It actually copiesmain.exe
and notmyproject
in the source directory anddune clean
doesn't deletemain.exe
in the root dirAdd the following rule in my
dune
file:(rule (target myproject) (deps ../../myproject) (action (copy %{target} %{deps})) )
which gives me the following error:
❯ dune build File "src/bin/dune", line 6, characters 0-88: 6 | (rule 7 | (target myproject) 8 | (deps ../../myproject) 9 | (action (copy %{target} %{deps})) 10 | ) Error: No rule found for myproject Error: Dependency cycle between the following files: _build/default/src/bin/myproject Done: 0/0 (jobs: 0)%
Add the following rule in my
dune
file:(rule (target main.exe) (deps ../../myproject) (action (copy %{target} %{deps})) )
which gives me the following error:
❯ dune build Error: Multiple rules generated for _build/default/src/bin/main.exe: - src/bin/dune:6 - src/bin/dune:2 Done: 0/0 (jobs: 0)%
And honestly I don't know what else I can do. I read the manual and can't find a solution. I wouldn't mind if I could just type dune run
but since dune allows to build multiple executables, I understand it's not an option. I'd like to be able to write dune run myproject
since I'm using the public name of my executables but dune can't find it. So I just want to have myproject
in my root directory so I can just type ./myproject
and be happy.
Do you know about dune exec
? It is what you call dune run
I believe.
From the root of your project, you can do dune exec ./bin/main.exe
.
这篇关于使用 dune 将生成的可执行文件复制到我的根目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!