diff options
| author | ruki <[email protected]> | 2023-01-12 00:43:47 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-01-13 20:50:56 +0800 |
| commit | 2dc422359767bf0bf325e1f0b7bf05ea9de9334c (patch) | |
| tree | a82752527e9d6eff12e1e06409f32eba564729b4 | |
| parent | 628e035d9bf70fee96226606585ab658283cb859 (diff) | |
add iverilog rules
| -rw-r--r-- | tests/projects/embed/iverilog/hello/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_vvp.lua | 62 | ||||
| -rw-r--r-- | xmake/rules/c51/xmake.lua | 22 | ||||
| -rw-r--r-- | xmake/rules/iverilog/xmake.lua | 63 | ||||
| -rw-r--r-- | xmake/toolchains/iverilog/xmake.lua | 54 |
5 files changed, 201 insertions, 2 deletions
diff --git a/tests/projects/embed/iverilog/hello/xmake.lua b/tests/projects/embed/iverilog/hello/xmake.lua index a59478b51..c876de531 100644 --- a/tests/projects/embed/iverilog/hello/xmake.lua +++ b/tests/projects/embed/iverilog/hello/xmake.lua @@ -1,5 +1,5 @@ add_requires("iverilog") target("hello") - add_rules("iverilog.binary") + add_rules("iverilog.wave") set_toolchains("@iverilog") add_files("src/*.v") diff --git a/xmake/modules/detect/tools/find_vvp.lua b/xmake/modules/detect/tools/find_vvp.lua new file mode 100644 index 000000000..c13cbcf1a --- /dev/null +++ b/xmake/modules/detect/tools/find_vvp.lua @@ -0,0 +1,62 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_vvp.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find vvp +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local vvp = find_vvp() +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + opt.check = opt.check or "-V" + opt.command = opt.command or "-V" + + -- find it from some logical drives paths + if is_host("windows") then + opt.paths = opt.paths or {} + for _, logical_drive in ipairs(winos.logical_drives()) do + table.insert(opt.paths, path.join(logical_drive, "iverilog", "bin")) + end + end + + -- find program + local program = find_program(opt.program or "vvp", opt) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, opt) + end + return program, version +end + diff --git a/xmake/rules/c51/xmake.lua b/xmake/rules/c51/xmake.lua index 6e4654082..da12b0922 100644 --- a/xmake/rules/c51/xmake.lua +++ b/xmake/rules/c51/xmake.lua @@ -1,3 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + rule("c51.binary") on_load(function (target) -- we disable checking flags for cross toolchain automatically @@ -20,4 +40,4 @@ rule("c51.binary") os.iorunv(oh.program, {target:targetfile()}) progress.show(opt.progress, "${color.build.target}generating.$(mode) %s", target:targetfile() .. ".hex") end, {files = {target:targetfile()}}) - end)
\ No newline at end of file + end) diff --git a/xmake/rules/iverilog/xmake.lua b/xmake/rules/iverilog/xmake.lua new file mode 100644 index 000000000..c12e0169b --- /dev/null +++ b/xmake/rules/iverilog/xmake.lua @@ -0,0 +1,63 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +rule("iverilog.wave") + set_extensions(".v", ".vhd") + on_load(function (target) + target:set("kind", "binary") + if not target:get("extension") then + target:set("extension", ".lxt") + end + end) + + on_buildcmd_files(function(target, batchcmds, sourcebatch, opt) + local toolchain = assert(target:toolchain("iverilog"), 'we need set_toolchains("iverilog") in target("%s")', target:name()) + local iverilog = assert(toolchain:config("iverilog"), "iverilog not found!") + + -- compile wave file + local wavefile = target:targetfile() .. ".wave" + local argv = {"-o", wavefile} + local sourcefiles = sourcebatch.sourcefiles + for _, sourcefile in ipairs(sourcefiles) do + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.iverilog %s", path.filename(sourcefile)) + table.insert(argv, path(sourcefile)) + batchcmds:add_depfiles(sourcefile) + end + batchcmds:mkdir(path.directory(wavefile)) + batchcmds:vrunv(iverilog, argv) + batchcmds:set_depmtime(os.mtime(wavefile)) + batchcmds:set_depcache(target:dependfile(wavefile)) + end) + + on_linkcmd(function (target, batchcmds, opt) + local toolchain = assert(target:toolchain("iverilog"), 'we need set_toolchains("iverilog") in target("%s")', target:name()) + local vvp = assert(toolchain:config("vvp"), "vvp not found!") + + -- generate wave.lxt + local targetfile = target:targetfile() + local wavefile = targetfile .. ".wave" + batchcmds:show_progress(opt.progress, "${color.build.target}linking.iverilog %s", path.filename(targetfile)) + batchcmds:mkdir(path.directory(targetfile)) + batchcmds:vrunv(vvp, {"-n", wavefile, "-lxt2"}) + batchcmds:cp(wavefile .. ".vcd", targetfile) + batchcmds:add_depfiles(wavefile) + batchcmds:set_depmtime(os.mtime(targetfile)) + batchcmds:set_depcache(target:dependfile(targetfile)) + end) diff --git a/xmake/toolchains/iverilog/xmake.lua b/xmake/toolchains/iverilog/xmake.lua new file mode 100644 index 000000000..30f83fabc --- /dev/null +++ b/xmake/toolchains/iverilog/xmake.lua @@ -0,0 +1,54 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +toolchain("iverilog") + set_homepage("https://steveicarus.github.io/iverilog/") + set_description("Icarus Verilog") + + set_kind("standalone") + + on_check(function (toolchain) + import("lib.detect.find_tool") + local paths = {} + for _, package in ipairs(toolchain:packages()) do + local envs = package:get("envs") + if envs then + table.join2(paths, envs.PATH) + end + end + local iverilog = find_tool("iverilog", {paths = paths}) + if iverilog and iverilog.program then + toolchain:config_set("iverilog", iverilog.program) + cprint("${dim}checking for iverilog ... ${color.success}%s", path.filename(iverilog.program)) + else + cprint("${dim}checking for iverilog ... ${color.nothing}${text.nothing}") + raise("iverilog not found!") + end + local vvp = find_tool("vvp", {paths = paths}) + if vvp and vvp.program then + toolchain:config_set("vvp", vvp.program) + cprint("${dim}checking for vvp ... ${color.success}%s", path.filename(vvp.program)) + else + cprint("${dim}checking for vvp ... ${color.nothing}${text.nothing}") + raise("iverilog not found!") + end + toolchain:configs_save() + return true + end) |
