Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verilator: switch to cmake #5680

Merged
merged 23 commits into from
Dec 13, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 29 additions & 35 deletions packages/v/verilator/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,57 @@ package("verilator")
set_kind("toolchain")
set_homepage("https://verilator.org")
set_description("Verilator open-source SystemVerilog simulator and lint system")
set_license("LGPL-3.0")

add_urls("https://github.com/verilator/verilator/archive/refs/tags/$(version).tar.gz")
add_urls("https://github.com/verilator/verilator.git")
add_urls("https://github.com/verilator/verilator/archive/refs/tags/$(version).tar.gz",
"https://github.com/verilator/verilator.git")

add_versions("v5.016", "66fc36f65033e5ec904481dd3d0df56500e90c0bfca23b2ae21b4a8d39e05ef1")
add_versions("v5.030", "b9e7e97257ca3825fcc75acbed792b03c3ec411d6808ad209d20917705407eac")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新版本 verilator 内部改了很多东西,对 VERILATOR_ROOT 的行为都变了,会 break 目前 xmake 内置的 verilator rules 。。要切到新版本,还得在 xmake 端做适配,估计要改很多的东西,还没空细看。。

建议先保留低版本


add_deps("cmake")

on_load(function (package)
if not package:is_precompiled() then
if package:is_plat("windows") then
package:add("deps", "cmake")
package:add("deps", "winflexbison", {kind = "library"})
else
package:add("deps", "flex", {kind = "library"})
package:add("deps", "bison")
package:add("deps", "autoconf", "automake", "libtool")
end
package:add("deps", "python 3.x", {kind = "binary"})
end
package:mark_as_pathenv("VERILATOR_ROOT")
package:addenv("VERILATOR_ROOT", ".")
end)

on_install("windows", function (package)
on_install(function (package)
import("package.tools.cmake")
local configs = {}
local cxflags = {}
local winflexbison = package:dep("winflexbison")
local flex = winflexbison:fetch()
if flex then
local includedirs = flex.sysincludedirs or flex.includedirs
for _, includedir in ipairs(includedirs) do
table.insert(cxflags, "-I" .. includedir)
end

io.replace("src/CMakeLists.txt", "MSVC_RUNTIME_LIBRARY MultiThreaded$<IF:$<CONFIG:Release>,,DebugDLL>", "", {plain = true})

local configs = {"-DOBJCACHE_ENABLED=OFF", "-DDEBUG_AND_RELEASE_AND_COVERAGE=OFF"}
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))

local opt = {}
opt.envs = cmake.buildenvs(package)
if package:is_plat("windows") then
table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''")
opt.envs.WIN_FLEX_BISON = package:dep("winflexbison"):installdir("include")
end
local envs = cmake.buildenvs(package)
envs.VERILATOR_ROOT = nil
envs.WIN_FLEX_BISON = winflexbison:installdir()
io.replace("src/CMakeLists.txt", '${ASTGEN} -I"${srcdir}"', '${ASTGEN} -I "${srcdir}"', {plain = true})
cmake.install(package, configs, {envs = envs, cxflags = cxflags})
os.cp(path.join(package:installdir("bin"), "verilator_bin.exe"), path.join(package:installdir("bin"), "verilator.exe"))
end)
cmake.install(package, configs, opt)

on_install("linux", "macosx", function (package)
import("package.tools.autoconf")
local configs = {}
local cxflags = {}
local flex = package:dep("flex"):fetch()
if flex then
local includedirs = flex.sysincludedirs or flex.includedirs
for _, includedir in ipairs(includedirs) do
table.insert(cxflags, "-I" .. includedir)
local bindir = package:installdir("bin")
local subfix = (is_host("windows") and ".exe" or "")
local verilator = path.join(bindir, "verilator" .. subfix)
if not os.isfile(verilator) then
local verilator_bin = "verilator_bin"
if package:is_debug() then
verilator_bin = verilator_bin .. "_dbg"
end
verilator_bin = path.join(bindir, verilator_bin .. subfix)
os.trycp(verilator_bin, verilator)
end
os.vrun("autoconf")
local envs = autoconf.buildenvs(package, {cxflags = cxflags})
envs.VERILATOR_ROOT = nil
autoconf.install(package, configs, {envs = envs})
end)

on_test(function (package)
Expand Down
Loading