- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个非常特殊的依赖情况,我想打包在一个 Stack/Cabal 包中:我需要构建并运行我的程序以获取代码生成器的输入,该代码生成器生成需要链接到的输出。 ..我的程序。
好的,更具体地说,以下是手动步骤:
stack build
安装所有依赖项,并构建所有非 Verilator 使用的可执行文件。 stack exec phase1
运行第一阶段,除其他外,生成一个 Verilog 文件和一个 Clash .manifest
文件。 .manifest
步骤 2 中的文件,并生成 C++ 代码和 Makefile
可用于驱动 Verilator。 Makefile
在步骤 3 中生成:Makefile
Makefile
,生成二进制库 stack build --flag phase2
构建第二个可执行文件。该可执行文件包括 .hsc
处理步骤 2 中生成的 header 的文件,并链接到步骤 4/2 中生成的 C++ 库。 stack build
而这一切都将在幕后发生。我什至从哪里开始?!
package.yaml
name: clashilator-model
version: 0
category: acme
dependencies:
- base
- directory
source-dirs:
- src
flags:
phase2:
manual: True
default: False
executables:
phase1:
main: phase1.hs
phase2:
main: phase2.hs
when:
- condition: flag(phase2)
then:
source-dirs:
- src
- _build/generated
extra-libraries: stdc++
extra-lib-dirs: _build/compiled
ghc-options:
-O3 -fPIC -pgml g++
-optl-Wl,--allow-multiple-definition
-optl-Wl,--whole-archive -optl-Wl,-Bstatic
-optl-Wl,-L_build/compiled -optl-Wl,-lImpl
-optl-Wl,-Bdynamic -optl-Wl,--no-whole-archive
build-tools: hsc2hs
include-dirs: _build/generated
else:
buildable: false
src/phase1.hs
import System.Directory
main :: IO ()
main = do
createDirectoryIfMissing True "_build/generated"
writeFile "_build/generated/Interface.hsc" hsc
writeFile "_build/generated/Impl.h" h
writeFile "_build/generated/Impl.c" c
writeFile "_build/Makefile" makeFile
makeFile = unlines
[ "compiled/libImpl.a: compiled/Impl.o"
, "\trm -f $@"
, "\tmkdir -p compiled"
, "\tar rcsT $@ $^"
, ""
, "compiled/Impl.o: generated/Impl.c generated/Impl.h"
, "\tmkdir -p compiled"
, "\t$(COMPILE.c) $(OUTPUT_OPTION) $<"
]
hsc = unlines
[ "module Interface where"
, "import Foreign.Storable"
, "import Foreign.Ptr"
, ""
, "data FOO = FOO Int deriving Show"
, ""
, "#include \"Impl.h\""
, ""
, "foreign import ccall unsafe \"bar\" bar :: Ptr FOO -> IO ()"
, "instance Storable FOO where"
, " alignment _ = #alignment FOO"
, " sizeOf _ = #size FOO"
, " peek ptr = FOO <$> (#peek FOO, fd1) ptr"
, " poke ptr (FOO x) = (#poke FOO, fd1) ptr x"
]
h = unlines
[ "#pragma once"
, ""
, "typedef struct{ int fd1; } FOO;"
]
c = unlines
[ "#include \"Impl.h\""
, "#include <stdio.h>"
, ""
, "void bar(FOO* arg)"
, "{ printf(\"bar: %d\\n\", arg->fd1); }"
]
src/phase2.hs
import Interface
import Foreign.Marshal.Utils
main :: IO ()
main = with (FOO 42) bar
stack build
stack run phase1
make -C _build
stack build --flag clashilator-model:phase2
stack exec phase2
最佳答案
牦牛全裸 : 我设法用自定义 Setup.hs
解决了它.
buildHook
,我基本上什么都做phase1
应该这样做(而不是将其留在 phase1
可执行文件中),将所有生成的文件放在 buildDir
下面的位置的LocalBuildInfo
争论。这些生成的文件是 C++ 源文件和 .hsc
文件。make
在正确的目录中,产生一些 libFoo.a
.buildHook
,现在有趣的部分开始了:编辑 Executable
s 在 PackageDescription
.hsc
文件的位置到 hsSourceDirs
, 和模块本身到 otherModules
.由于hsc2hs
需要访问生成的 C++ 头文件,我还将正确的目录添加到 includeDirs
.对于图书馆本身,我添加到 extraLibDirs
并编辑 options
静态链接到 libFoo.a
,通过将标志直接传递给链接器。Executable
s,我把它放回 PackageDescription
在将其传递给默认值 buildHook
之前.然后运行 hsc2hs
和 ghc
编译和链接phase2
可执行文件。Setup.hs
和
clashilator/src/Clash/Clashilator/Setup.hs
看到这个在行动;特别是,这里是
Executable
的编辑s 在
PackageDescription
:
-- TODO: Should we also edit `Library` components?
buildVerilator :: LocalBuildInfo -> BuildFlags -> [FilePath] -> String -> IO (Executable -> Executable)
buildVerilator localInfo buildFlags srcDir mod = do
let outDir = buildDir localInfo
(verilogDir, manifest) <- clashToVerilog localInfo buildFlags srcDir mod
let verilatorDir = "_verilator"
Clashilator.generateFiles (".." </> verilogDir) (outDir </> verilatorDir) manifest
-- TODO: bake in `pkg-config --cflags verilator`
() <- cmd (Cwd (outDir </> verilatorDir)) "make"
let incDir = outDir </> verilatorDir </> "src"
libDir = outDir </> verilatorDir </> "obj"
lib = "VerilatorFFI"
let fixupOptions f (PerCompilerFlavor x y) = PerCompilerFlavor (f x) (f y)
linkFlags =
[ "-fPIC"
, "-pgml", "g++"
, "-optl-Wl,--whole-archive"
, "-optl-Wl,-Bstatic"
, "-optl-Wl,-l" <> lib
, "-optl-Wl,-Bdynamic"
, "-optl-Wl,--no-whole-archive"
]
fixupExe = foldr (.) id $
[ includeDirs %~ (incDir:)
, extraLibDirs %~ (libDir:)
, options %~ fixupOptions (linkFlags++)
, hsSourceDirs %~ (incDir:)
, otherModules %~ (fromString lib:)
]
return fixupExe
关于haskell - 如何使用 Stack/Cabal 构建早期部分的程序输出作为同一构建后续部分的源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61572353/
我正在为从 API 级别 8 到 14 的 android 开发一个应用程序。我正在尝试在早期版本中获得与 android 4(请参阅联系人应用程序)相同的快速滚动行为(右侧固定的时尚滚动条)边)。有
早期(编译期)优化 jvm的编译器可以分为三个编译器: 前端编译器:把*.java转变为*.class的过程。如sun的javac、eclipse jdt中的增量式编译器(ecj)
苹果终于推出了所谓的auto-renewable subscriptions昨天。由于我在应用内购买方面的经验很少(仅限沙盒),所以我不确定我在这里是否一切顺利。似乎需要对收据进行服务器端验证。找出订
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 要求代码的问题必须表明对正在解决的问题的最低理解。包括尝试的解决方案、它们为什么不起作用以及预期结果。另
在 Wagner 的“Effective C#”第 23 项中,他解释说 interface methods are not virtual...they are a declaration of a
我最近遵循了本指南 Installing a Git Server using Apache (WebDAV) on Ubuntu Server 12.04使用 Apache (WebDAV) 设置本
这是我之前的问题 jQuery UI hiding not taking effect for early DOM elements 的后续问题。我几乎刚刚编辑了那个,但不想使 the accepte
我正在尝试替换 ZonedDateTime.toInstant方法,因为它仅从 API 26 for Android 开始可用。 但我的应用程序应该支持 API 19。 我想将 ZonedDateTi
我的电脑正确配置了 SSH,我在尝试克隆存储库时遇到了这个错误: 我运行这个命令来克隆存储库 git clone ssh://git-codecommit.us-west-2.amazonaws.co
我是一名优秀的程序员,十分优秀!