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

Support Verilator target build to static library #5062

Merged
merged 1 commit into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions tests/projects/embed/verilator/static/src/main.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module hello;
initial begin
$display("hello world!");
$finish ;
end
endmodule
12 changes: 12 additions & 0 deletions tests/projects/embed/verilator/static/src/sim_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "hello.h"
#include "verilated.h"

int main(int argc, char** argv) {
VerilatedContext* contextp = new VerilatedContext;
contextp->commandArgs(argc, argv);
hello* top = new hello{contextp};
while (!contextp->gotFinish()) { top->eval(); }
delete top;
delete contextp;
return 0;
}
9 changes: 9 additions & 0 deletions tests/projects/embed/verilator/static/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
add_requires("verilator")
target("hello")
add_rules("verilator.static")
set_toolchains("@verilator")
add_files("src/*.v")

target("test")
add_deps("hello")
add_files("src/*.cpp")
10 changes: 5 additions & 5 deletions xmake/rules/verilator/verilator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ endmodule]])
if not os.isfile(autogendir) then
os.mkdir(autogendir)
end
target:add("includedirs", autogendir)
target:add("includedirs", path.join(verilator_root, "include"))
target:add("includedirs", path.join(verilator_root, "include", "vltstd"))
target:add("includedirs", autogendir, {public = true})
target:add("includedirs", path.join(verilator_root, "include"), {public = true})
target:add("includedirs", path.join(verilator_root, "include", "vltstd"), {public = true})

-- set languages
local languages = target:get("languages")
Expand All @@ -188,12 +188,12 @@ endmodule]])
end
end
if not cxxlang then
target:add("languages", "c++20")
target:add("languages", "c++20", {public = true})
end

-- add definitions for switches
for k, v in table.orderpairs(switches) do
target:add("defines", "VM_" .. k .. "=" .. v)
target:add("defines", "VM_" .. k .. "=" .. v, {public = true})
end

-- add syslinks
Expand Down
28 changes: 28 additions & 0 deletions xmake/rules/verilator/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

-- @see https://github.com/xmake-io/xmake/issues/3257
rule("verilator.binary")
add_deps("c++")
set_extensions(".v", ".sv")
on_load(function (target)
target:set("kind", "binary")
Expand All @@ -45,3 +46,30 @@ rule("verilator.binary")
import("verilator").buildcmd_cppfiles(target, batchcmds, sourcebatch, opt)
end)

rule("verilator.static")
add_deps("c++")
set_extensions(".v", ".sv")
on_load(function (target)
target:set("kind", "static")
end)

on_config(function (target)
import("verilator").config(target)
end)

before_build_files(function (target, sourcebatch)
-- Just to avoid before_buildcmd_files being executed at build time
end)

on_build_files(function (target, batchjobs, sourcebatch, opt)
import("verilator").build_cppfiles(target, batchjobs, sourcebatch, opt)
end, {batch = true, distcc = true})

before_buildcmd_files(function(target, batchcmds, sourcebatch, opt)
import("verilator").buildcmd_vfiles(target, batchcmds, sourcebatch, opt)
end)

on_buildcmd_files(function (target, batchcmds, sourcebatch, opt)
import("verilator").buildcmd_cppfiles(target, batchcmds, sourcebatch, opt)
end)

Loading