djg / verilated-rs

Verilator Porcelain
Apache License 2.0
36 stars 14 forks source link

Build failure on macOS Mojave #5

Closed tommythorn closed 3 years ago

tommythorn commented 3 years ago

I was looking for a simple example of how to use Rust with Verilog, via Verilator and found this. It isn't clear to me how to use it, but cargo build seems to fail, ending in

  = note: Undefined symbols for architecture x86_64:
            "Vtop::final()", referenced from:
                _top_final in libVtop__ALL.a(top.o)
            "Vtop::~Vtop()", referenced from:
                _top_delete in libVtop__ALL.a(top.o)
            "Vtop::Vtop(char const*)", referenced from:
                _top_new in libVtop__ALL.a(top.o)
            "Vtop::_eval_initial(Vtop__Syms*)", referenced from:
                Vtop::_eval_initial_loop(Vtop__Syms*) in libVtop__ALL.a(Vtop.o)
            "Vtop::_eval_settle(Vtop__Syms*)", referenced from:
                Vtop::_eval_initial_loop(Vtop__Syms*) in libVtop__ALL.a(Vtop.o)
          ld: symbol(s) not found for architecture x86_64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

This is after applying the attached patch for trivial issues.

I don't know if this is still maintained, but I figured I'd point this out.

minor-build-issues.patch.txt

djg commented 3 years ago

Thanks for the report, I haven't used this crate in a long time. Can you tell me what platform you tried to compile on and I'll see if I can reproduce? (I assume it's latest Mojave with all the latest Xcode, etc)

djg commented 3 years ago

I pulled the latest master and:

djg in ~/Work/verilated-rs on master!
$ cargo run -p example
   Compiling unicode-xid v0.1.0
   Compiling fnv v1.0.7
   Compiling cc v1.0.66
   Compiling proc-macro2 v0.3.8
   Compiling quote v0.5.2
   Compiling syn v0.13.11
   Compiling verilator v0.1.4 (/Users/djg/Work/verilated-rs/verilator)
   Compiling verilated v0.1.1 (/Users/djg/Work/verilated-rs/verilated)
   Compiling example v0.0.0 (/Users/djg/Work/verilated-rs/example)
   Compiling verilated-module v0.1.1 (/Users/djg/Work/verilated-rs/verilated-module)
warning: warning: unknown warning option '-Wno-unused-but-set-variable'; did you mean '-Wno-unused-const-variable'? [-Wunknown-warning-option]
warning: 1 warning generated.
warning: warning: unknown warning option '-Wno-unused-but-set-variable'; did you mean '-Wno-unused-const-variable'? [-Wunknown-warning-option]
warning: 1 warning generated.
warning: warning: unknown warning option '-Wno-unused-but-set-variable'; did you mean '-Wno-unused-const-variable'? [-Wunknown-warning-option]
warning: 1 warning generated.
warning: warning: unknown warning option '-Wno-unused-but-set-variable'; did you mean '-Wno-unused-const-variable'? [-Wunknown-warning-option]
warning: 1 warning generated.
warning: warning: unknown warning option '-Wno-unused-but-set-variable'; did you mean '-Wno-unused-const-variable'? [-Wunknown-warning-option]
warning: 1 warning generated.
warning: warning: unknown warning option '-Wno-unused-but-set-variable'; did you mean '-Wno-unused-const-variable'? [-Wunknown-warning-option]
warning: 1 warning generated.
warning: warning: unknown warning option '-Wno-unused-but-set-variable'; did you mean '-Wno-unused-const-variable'? [-Wunknown-warning-option]
warning: 1 warning generated.
warning: warning: unknown warning option '-Wno-unused-but-set-variable'; did you mean '-Wno-unused-const-variable'? [-Wunknown-warning-option]
warning: 1 warning generated.
warning: warning: unknown warning option '-Wno-unused-but-set-variable'; did you mean '-Wno-unused-const-variable'? [-Wunknown-warning-option]
warning: 1 warning generated.
warning: warning: unknown warning option '-Wno-unused-but-set-variable'; did you mean '-Wno-unused-const-variable'? [-Wunknown-warning-option]
warning: 1 warning generated.
warning: warning: unknown warning option '-Wno-unused-but-set-variable'; did you mean '-Wno-unused-const-variable'? [-Wunknown-warning-option]
warning: 1 warning generated.
warning: warning: unknown warning option '-Wno-unused-but-set-variable'; did you mean '-Wno-unused-const-variable'? [-Wunknown-warning-option]
warning: 1 warning generated.
warning: warning: unknown warning option '-Wno-unused-but-set-variable'; did you mean '-Wno-unused-const-variable'? [-Wunknown-warning-option]
warning: 1 warning generated.
    Finished dev [unoptimized + debuginfo] target(s) in 13.10s
     Running `target/debug/example`
0: count_o = 0
1: count_o = 0
2: count_o = 1
3: count_o = 2
4: count_o = 3
5: count_o = 4
6: count_o = 5
7: count_o = 6
8: count_o = 7
9: count_o = 8
10: count_o = 9
11: count_o = 10

I have the following version of verilator:

djg in ~/Work/verilated-rs on master!
[1] $ verilator --version                                                                                                         ⤬
Verilator 4.030 2020-03-08 rev v4.028-50-g95c4b6aa
tommythorn commented 3 years ago

I'm on an iMac 5K, running macOS 10.14.6 (Mojave), but otherwise up-to-date. Rust is up-to-date and Verilator is from Mac Home Brew and is also fresh:

$ rustc --version
rustc 1.48.0 (7eac88abb 2020-11-16)
$ verilator --version
Verilator 4.106 2020-12-02 rev v4.104-91-gb350b6a0f

My repo is up-to-date at

commit fb8922a68f686071aa1b0db5fbe60bbeb0fc7522 (HEAD -> master, origin/master, origin/HEAD)
Author: Dan Glastonbury <dan.glastonbury@gmail.com>
Date:   Tue Apr 21 15:05:16 2020 +1000

    Bump version to 0.1.4

If I clean all and run cargo run -p example I get cargo-run.output.txt

tommythorn commented 3 years ago

Slightly unrelated, but I'm trying to make the example standalone and could use a hint. My Cargo.toml of

[package]
name = "example"
version = "0.0.0"
authors = ["Dan Glastonbury <dan.glastonbury@gmail.com>"]
edition = "2018"
build = "build.rs"

[dependencies]
verilated = "*"

[build-dependencies]
verilator = "*"

clearly isn't right as it complains that

  cargo build
   Compiling example v0.0.0 (/Users/tommy/projects/Rust/verilated-example)
   Compiling verilated v0.1.1
error[E0432]: unresolved import `verilator::module`
 --> build.rs:6:16
  |
6 | use verilator::module::ModuleGenerator;
  |                ^^^^^^ could not find `module` in `verilator`

error: aborting due to previous error

but I'm setting the feature didn't work either.

djg commented 3 years ago

If I clean all and run cargo run -p example I get cargo-run.output.txt

Thanks for the info. I pulled that latest verilator from homebrew and have the same issues, so something major changed between version 4.030 and 4.106. I hand wrote the bindings to verilator. Perhaps it's time to invest in rust-bindgen to generate the bindings?

djg commented 3 years ago

clearly isn't right as it complains that

  cargo build
   Compiling example v0.0.0 (/Users/tommy/projects/Rust/verilated-example)
   Compiling verilated v0.1.1
error[E0432]: unresolved import `verilator::module`
 --> build.rs:6:16
  |
6 | use verilator::module::ModuleGenerator;
  |                ^^^^^^ could not find `module` in `verilator`

error: aborting due to previous error

That is odd. I'll take a look once I finish updating the crates to edition 2018.

adamwalker commented 3 years ago

I've hacked together a version that compiles with Verilator 4.108 here: https://github.com/adamwalker/verilated-rs

tommythorn commented 3 years ago

FWIW, @adamwalker I don't appear to be able to file issues so I'll report it here: your version doesn't build for me on Ubuntu (I realize that this this was intended for the newer verilator):

$ cargo run -p example
   Compiling verilated v0.1.1 (/home/tommy/projects/verilated-rs/verilated)
The following warnings were emitted during compilation:

warning: src/verilated_shim.cpp: In function ‘void verilated_flush_call()’:
warning: src/verilated_shim.cpp:92:14: error: ‘flushCall’ is not a member of ‘Verilated’
warning:    92 |   Verilated::flushCall();
warning:       |              ^~~~~~~~~

error: failed to run custom build command for `verilated v0.1.1 (/home/tommy/projects/verilated-rs/verilated)`
...
$ verilator --version
Verilator 4.038 2020-07-11 rev v4.036-114-g0cd4a57ad
$ rustc --version
rustc 1.50.0 (cb75ad5db 2021-02-10)
djg commented 3 years ago

I did start reworking verilator over the Christmas break. I'll see if I can get some time tonight to just this working with version 4.038 of Verilator instead of rewriting the entire world.

On Tue, 16 Feb 2021 at 04:14, Tommy Thorn notifications@github.com wrote:

@adamwalker https://github.com/adamwalker I don't appear to be able to file issues so I'll report it here: your version doesn't build for me either:

$ cargo run -p example

Compiling verilated v0.1.1 (/home/tommy/projects/verilated-rs/verilated)

The following warnings were emitted during compilation:

warning: src/verilated_shim.cpp: In function ‘void verilated_flush_call()’:

warning: src/verilated_shim.cpp:92:14: error: ‘flushCall’ is not a member of ‘Verilated’

warning: 92 | Verilated::flushCall();

warning: | ^~~~~

error: failed to run custom build command for verilated v0.1.1 (/home/tommy/projects/verilated-rs/verilated)

...

$ verilator --version

Verilator 4.038 2020-07-11 rev v4.036-114-g0cd4a57ad

$ rustc --version

rustc 1.50.0 (cb75ad5db 2021-02-10)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/djg/verilated-rs/issues/5#issuecomment-779382997, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABGDLPWAJLFPQW3ILJT5LLS7FP6ZANCNFSM4UPW75GQ .

-- Dan Glastonbury, Dan dot Glastonbury at gmail dot com `Pour encourjay lays ortras'

djg commented 3 years ago

I did some work to get the example compiling in PR #6.

tommythorn commented 3 years ago

Thanks!