mit-plv/koika

Build issues on macOS

PalindromeLeung opened this issue · 26 comments

I encounter the following compiling issue.

== Building OCaml library and executables ==
dune build ocaml/cuttlec.exe @install
ocamlopt ocaml/cuttlec.exe
ld: warning: directory not found for option '-L/opt/local/lib'
make: *** No rule to make target examples/_objects/collatz.lv', needed by examples'. Stop.

Did I miss some configuration in my _Coqproject file?
Any advice is welcome. Thanks!

Can you show how you cloned the repository and what commands you ran? Also, which system are you on and which versions of the tools do you use?

Sorry about the lack of environmental information.
cloning method: git clone git@github.com:mit-plv/koika.git
I already have coq 8.12.2 on my system (macOS Big Sur 11.0.1), so I continued to install dune with
opam update
opam upgrade dune
then
opam install base core stdio parsexp hashcons zarith

more version info:
opam --version
2.0.7
coqc --version
The Coq Proof Assistant, version 8.12.2 (December 2020)
compiled on Dec 11 2020 17:58:28 with OCaml 4.10.0

namin commented

I have the same issue...

That's frustrating, sorry about that! Are you using the makefile to build? I can look into this this weekend

namin commented

Thanks :) Yes, I am following the instructions in the README. Let me know if I can provide any specific info.

Here is what I see on a fresh clone on my Ubuntu machine:

$ cd /tmp
$ git clone git@github.com:mit-plv/koika.git
Cloning into 'koika'...
remote: Enumerating objects: 9431, done.        
remote: Counting objects: 100% (175/175), done.        
remote: Compressing objects: 100% (133/133), done.        
remote: Total 9431 (delta 92), reused 90 (delta 42), pack-reused 9256        
Receiving objects: 100% (9431/9431), 4.75 MiB | 7.39 MiB/s, done.
Resolving deltas: 100% (7162/7162), done.
$ cd koika
$ coqc --version
The Coq Proof Assistant, version 8.13.2 (May 2021)
compiled on May 13 2021 1:54:11 with OCaml 4.12.0
$ dune --version
2.8.5
$ make

== Building Coq library ==
dune build @@coq/all
[… Coq 8.13 warnings omitted]
                       
== Building OCaml library and executables ==
dune build ocaml/cuttlec.exe @install
etc/configure tests/cross_cycle.v tests/double_write.v tests/errors.v tests/extcall.v tests/internal_functions.v tests/large_writeset.v tests/muxelim.v tests/read1_write1_check.v tests/register_file_bypassing.v tests/shifts.v tests/struct_init.v tests/switches.v tests/trivial_state_machine.v tests/unpack.v examples/collatz.v examples/combinational_proof_tutorial.v examples/conflicts_modular.v examples/conflicts.v examples/cosimulation.v examples/datatypes.v examples/external_rule.v examples/fft.v examples/fir.v examples/function_call.v examples/gcd_machine.v examples/method_call.v examples/pipeline_tutorial.v examples/pipeline.v examples/save_restore.v examples/uart.v examples/vector.v examples/rv/rv32i.v examples/rv/rv32e.v

-- Compiling examples/collatz.lv --
dune exec -- cuttlec "examples/collatz.lv" -T all -o "examples/_objects/collatz.lv" 
make[1]: Entering directory '/tmp/koika/examples/_objects/collatz.lv'
g++   -Wall -Wextra '-DSIM_VCD_SCOPES={"TOP", "collatz",}' --std=c++14 -O3 -march=native -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fno-stack-protector collatz.cpp -o "collatz.opt"
make[1]: Leaving directory '/tmp/koika/examples/_objects/collatz.lv'

-- Compiling examples/collatz.v --
[…]
-- Compiling examples/combinational_proof_tutorial.v --
[…]
[…etc]
./etc/readme/update.py README.rst

@namin , if you see the exact same error as the OP, could you post the output of make --debug --no-builtin-rules examples/_objects/collatz.lv?

Thanks a lot!

namin commented

Thanks for taking a look. This is the output:

% make --debug --no-builtin-rules examples/_objects/collatz.lv
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0
Reading makefiles...
Updating goal targets....
 File `examples/_objects/collatz.lv' does not exist.
Must remake target `examples/_objects/collatz.lv'.
make: *** No rule to make target `examples/_objects/collatz.lv'.  Stop.

I am running older Coq and dune versions, because I took the versions from the README that have been suggested as known to work.

% coqc --version
The Coq Proof Assistant, version 8.11.1 (February 2022)
compiled on Feb 20 2022 4:37:08 with OCaml 4.09.1
% dune --version
2.5.1

I tried it on separate Mac OS X machines, and I get the same error.

Thanks!

Surprising; this is what I see:

$ make --debug --no-builtin-rules examples/_objects/collatz.lv
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating makefiles....
Updating goal targets....
 File 'examples/_objects/collatz.lv' does not exist.
   File 'ocaml' does not exist.
  Must remake target 'ocaml'.

== Building OCaml library and executables ==
dune build ocaml/cuttlec.exe @install
  Successfully remade target file 'ocaml'.
   File 'configure' does not exist.
  Must remake target 'configure'.
etc/configure tests/cross_cycle.v tests/double_write.v tests/errors.v tests/extcall.v tests/internal_functions.v tests/large_writeset.v tests/muxelim.v tests/read1_write1_check.v tests/register_file_bypassing.v tests/sel_sext.v tests/shifts.v tests/struct_init.v tests/switches.v tests/trivial_state_machine.v tests/unpack.v examples/arrays_pack_subst.v examples/collatz.v examples/combinational_proof_tutorial.v examples/conflicts_modular.v examples/conflicts.v examples/cosimulation.v examples/datatypes.v examples/external_rule.v examples/fft.v examples/fir.v examples/function_call.v examples/gcd_machine.v examples/method_call.v examples/pipeline_tutorial.v examples/pipeline.v examples/save_restore.v examples/uart.v examples/vector.v examples/rv/rv32i.v examples/rv/rv32e.v
  Successfully remade target file 'configure'.
Must remake target 'examples/_objects/collatz.lv'.

-- Compiling examples/collatz.lv --
dune exec -- cuttlec "examples/collatz.lv" -T all -o "examples/_objects/collatz.lv" 
GNU Make 4.3           
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
make[1]: Entering directory '/build/koika/examples/_objects/collatz.lv'
Updating makefiles....
Updating goal targets....
 File 'default' does not exist.
   File 'collatz.opt' does not exist.
  Must remake target 'collatz.opt'.
g++   -Wall -Wextra '-DSIM_VCD_SCOPES={"TOP", "collatz",}' --std=c++14 -O3 -march=native -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fno-stack-protector collatz.cpp -o "collatz.opt"
  Successfully remade target file 'collatz.opt'.
Must remake target 'default'.
Successfully remade target file 'default'.
make[1]: Leaving directory '/build/koika/examples/_objects/collatz.lv'
Successfully remade target file 'examples/_objects/collatz.lv'.

I wonder if there's something in the Makefile that depends on GNU Make 4? Your version of make is from 2006.

Confirmed: here's what I see with Make 3.81 built locally:

$ /build/make-3.81/make --debug --no-builtin-rules examples/_objects/collatz.lv
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-unknown-linux-gnu
Reading makefiles...
Updating goal targets....
 File `examples/_objects/collatz.lv' does not exist.
Must remake target `examples/_objects/collatz.lv'.
make: *** No rule to make target `examples/_objects/collatz.lv'.  Stop.

Can you update gnu make? Alternatively I can try to debug the makefile, but it sounds a bit more complicated ^^

namin commented

This is progress! I updated to make --version GNU Make 4.3 Built for x86_64-apple-darwin21.1.0

And now, I get a different error.

% make --debug --no-builtin-rules examples/_objects/collatz.lv
GNU Make 4.3
Built for x86_64-apple-darwin21.1.0
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating makefiles....
Updating goal targets....
   File 'ocaml' does not exist.
  Must remake target 'ocaml'.

== Building OCaml library and executables ==
dune build ocaml/cuttlec.exe @install
  Successfully remade target file 'ocaml'.
   File 'configure' does not exist.
  Must remake target 'configure'.
etc/configure tests/cross_cycle.v tests/double_write.v tests/errors.v tests/extcall.v tests/internal_functions.v tests/large_writeset.v tests/muxelim.v tests/read1_write1_check.v tests/register_file_bypassing.v tests/shifts.v tests/struct_init.v tests/switches.v tests/trivial_state_machine.v tests/unpack.v examples/collatz.v examples/combinational_proof_tutorial.v examples/conflicts.v examples/conflicts_modular.v examples/cosimulation.v examples/datatypes.v examples/external_rule.v examples/fft.v examples/fir.v examples/function_call.v examples/gcd_machine.v examples/method_call.v examples/pipeline.v examples/pipeline_tutorial.v examples/save_restore.v examples/uart.v examples/vector.v examples/rv/rv32i.v examples/rv/rv32e.v
  Successfully remade target file 'configure'.
 Prerequisite 'ocaml' of target 'examples/_objects/collatz.lv' does not exist.
Must remake target 'examples/_objects/collatz.lv'.

-- Compiling examples/collatz.lv --
dune exec -- cuttlec "examples/collatz.lv" -T all -o "examples/_objects/collatz.lv" 
GNU Make 4.3         
Built for x86_64-apple-darwin21.1.0
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
make[1]: Entering directory '/Users/namin/code/sec/koika/examples/_objects/collatz.lv'
Updating makefiles....
Updating goal targets....
 File 'default' does not exist.
   File 'collatz.opt' does not exist.
  Must remake target 'collatz.opt'.
g++   -Wall -Wextra '-DSIM_VCD_SCOPES={"TOP", "collatz",}' --std=c++14 -O3 -march=native -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fno-stack-protector collatz.cpp -o "collatz.opt"
In file included from collatz.cpp:2:
In file included from ./collatz.hpp:8:
./cuttlesim.hpp:869:24: error: implicit instantiation of undefined template 'std::basic_ostringstream<char>'
    std::ostringstream stream;
                       ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/iosfwd:136:32: note: template is declared here
    class _LIBCPP_TEMPLATE_VIS basic_ostringstream;
                               ^
In file included from collatz.cpp:2:
In file included from ./collatz.hpp:8:
./cuttlesim.hpp:1048:28: error: implicit instantiation of undefined template 'std::basic_istringstream<char>'
        std::istringstream ls(line);
                           ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/iosfwd:133:32: note: template is declared here
    class _LIBCPP_TEMPLATE_VIS basic_istringstream;
                               ^
2 errors generated.
make[1]: *** [Makefile:42: collatz.opt] Error 1
make[1]: Leaving directory '/Users/namin/code/sec/koika/examples/_objects/collatz.lv'
make: *** [Makefile:102: examples/_objects/collatz.lv] Error 2

I thought maybe that's a clang vs gcc error. I aliased gcc and g++ to non-clang, and I get the following:

% make --debug --no-builtin-rules examples/_objects/collatz.lv
GNU Make 4.3
Built for x86_64-apple-darwin21.1.0
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Updating makefiles....
Updating goal targets....
   File 'ocaml' does not exist.
  Must remake target 'ocaml'.

== Building OCaml library and executables ==
dune build ocaml/cuttlec.exe @install
  Successfully remade target file 'ocaml'.
   File 'configure' does not exist.
  Must remake target 'configure'.
etc/configure tests/cross_cycle.v tests/double_write.v tests/errors.v tests/extcall.v tests/internal_functions.v tests/large_writeset.v tests/muxelim.v tests/read1_write1_check.v tests/register_file_bypassing.v tests/shifts.v tests/struct_init.v tests/switches.v tests/trivial_state_machine.v tests/unpack.v examples/collatz.v examples/combinational_proof_tutorial.v examples/conflicts.v examples/conflicts_modular.v examples/cosimulation.v examples/datatypes.v examples/external_rule.v examples/fft.v examples/fir.v examples/function_call.v examples/gcd_machine.v examples/method_call.v examples/pipeline.v examples/pipeline_tutorial.v examples/save_restore.v examples/uart.v examples/vector.v examples/rv/rv32i.v examples/rv/rv32e.v
  Successfully remade target file 'configure'.
 Prerequisite 'ocaml' of target 'examples/_objects/collatz.lv' does not exist.
Must remake target 'examples/_objects/collatz.lv'.

-- Compiling examples/collatz.lv --
dune exec -- cuttlec "examples/collatz.lv" -T all -o "examples/_objects/collatz.lv" 
GNU Make 4.3         
Built for x86_64-apple-darwin21.1.0
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
make[1]: Entering directory '/Users/namin/code/sec/koika/examples/_objects/collatz.lv'
Updating makefiles....
Updating goal targets....
 File 'default' does not exist.
   File 'collatz.opt' does not exist.
  Must remake target 'collatz.opt'.
g++   -Wall -Wextra '-DSIM_VCD_SCOPES={"TOP", "collatz",}' --std=c++14 -O3 -march=native -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fno-stack-protector collatz.cpp -o "collatz.opt"
In file included from collatz.cpp:2:
In file included from ./collatz.hpp:8:
./cuttlesim.hpp:869:24: error: implicit instantiation of undefined template 'std::basic_ostringstream<char>'
    std::ostringstream stream;
                       ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/iosfwd:136:32: note: template is declared here
    class _LIBCPP_TEMPLATE_VIS basic_ostringstream;
                               ^
In file included from collatz.cpp:2:
In file included from ./collatz.hpp:8:
./cuttlesim.hpp:1048:28: error: implicit instantiation of undefined template 'std::basic_istringstream<char>'
        std::istringstream ls(line);
                           ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/iosfwd:133:32: note: template is declared here
    class _LIBCPP_TEMPLATE_VIS basic_istringstream;
                               ^
2 errors generated.
make[1]: *** [Makefile:42: collatz.opt] Error 1
make[1]: Leaving directory '/Users/namin/code/sec/koika/examples/_objects/collatz.lv'
make: *** [Makefile:102: examples/_objects/collatz.lv] Error 2

Thanks!

It looks like your C++ stdlib's headers don't have the same transitive includes as mine :'( I just pushed a more conservative set of headers; let's see if that fixes the issue. I also added a version test to the makefile.

Thanks a lot for your help with debugging this.

namin commented

More progress! Now, it fails later.

% make

== Building Coq library ==
dune build @@coq/all
                     
== Building OCaml library and executables ==
dune build ocaml/cuttlec.exe @install
    ocamlopt ocaml/cuttlec.exe
ld: warning: directory not found for option '-L/opt/local/lib'
etc/configure tests/cross_cycle.v tests/double_write.v tests/errors.v tests/extcall.v tests/internal_functions.v tests/large_writeset.v tests/muxelim.v tests/read1_write1_check.v tests/register_file_bypassing.v tests/shifts.v tests/struct_init.v tests/switches.v tests/trivial_state_machine.v tests/unpack.v examples/collatz.v examples/combinational_proof_tutorial.v examples/conflicts.v examples/conflicts_modular.v examples/cosimulation.v examples/datatypes.v examples/external_rule.v examples/fft.v examples/fir.v examples/function_call.v examples/gcd_machine.v examples/method_call.v examples/pipeline.v examples/pipeline_tutorial.v examples/save_restore.v examples/uart.v examples/vector.v examples/rv/rv32i.v examples/rv/rv32e.v

-- Compiling examples/collatz.lv --
dune exec -- cuttlec "examples/collatz.lv" -T all -o "examples/_objects/collatz.lv" 
make[1]: Entering directory '/Users/namin/code/sec/koika/examples/_objects/collatz.lv'
g++   -Wall -Wextra '-DSIM_VCD_SCOPES={"TOP", "collatz",}' --std=c++14 -O3 -march=native -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fno-stack-protector collatz.cpp -o "collatz.opt"
make[1]: Leaving directory '/Users/namin/code/sec/koika/examples/_objects/collatz.lv'

-- Compiling examples/collatz.v --
dune build "examples/_objects/collatz.v/collatz.ml"
dune exec -- cuttlec "_build/default/examples/_objects/collatz.v/collatz.ml" -T all -o "examples/_objects/collatz.v"
make[1]: Entering directory '/Users/namin/code/sec/koika/examples/_objects/collatz.v'
g++   -Wall -Wextra '-DSIM_VCD_SCOPES={"TOP", "collatz",}' --std=c++14 -O3 -march=native -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fno-stack-protector collatz.cpp -o "collatz.opt"
make[1]: Leaving directory '/Users/namin/code/sec/koika/examples/_objects/collatz.v'

-- Compiling examples/combinational_proof_tutorial.v --
dune build "examples/_objects/combinational_proof_tutorial.v/combinational_proof_tutorial.ml"
        coqc examples/combinational_proof_tutorial.vo
     = 28
     : nat
     = Ob~1~0~1~0~1~0~1~0~1~1~1~1~0~0~0~0
     : bits sz
     = Ob~0~0~0~0~0~1~1~0
     : bits (enum_bitsize ops)
     = Ob~0~0~0~1~0~0~0~1
     : bits (enum_bitsize ops)
     = 28
     : nat
     = Ob~1~0~1~0~1~0~1~0~1~1~1~1~0~0~0~0
     : bits_t sz
dune exec -- cuttlec "_build/default/examples/_objects/combinational_proof_tutorial.v/combinational_proof_tutorial.ml" -T all -o "examples/_objects/combinational_proof_tutorial.v"
make[1]: Entering directory '/Users/namin/code/sec/koika/examples/_objects/combinational_proof_tutorial.v'
g++   -Wall -Wextra '-DSIM_VCD_SCOPES={"TOP", "combinational_proof_tutorial",}' --std=c++14 -O3 -march=native -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fno-stack-protector combinational_proof_tutorial.cpp -o "combinational_proof_tutorial.opt"
make[1]: Leaving directory '/Users/namin/code/sec/koika/examples/_objects/combinational_proof_tutorial.v'

-- Compiling examples/conflicts.v --
dune build "examples/_objects/conflicts.v/conflicts.ml"
dune exec -- cuttlec "_build/default/examples/_objects/conflicts.v/conflicts.ml" -T all -o "examples/_objects/conflicts.v"
make[1]: Entering directory '/Users/namin/code/sec/koika/examples/_objects/conflicts.v'
g++   -Wall -Wextra '-DSIM_VCD_SCOPES={"TOP", "conflicts",}' --std=c++14 -O3 -march=native -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fno-stack-protector conflicts.cpp -o "conflicts.opt"
make[1]: Leaving directory '/Users/namin/code/sec/koika/examples/_objects/conflicts.v'

-- Compiling examples/conflicts_modular.v --
dune build "examples/_objects/conflicts_modular.v/conflicts_modular.ml"
dune exec -- cuttlec "_build/default/examples/_objects/conflicts_modular.v/conflicts_modular.ml" -T all -o "examples/_objects/conflicts_modular.v"
make[1]: Entering directory '/Users/namin/code/sec/koika/examples/_objects/conflicts_modular.v'
g++   -Wall -Wextra '-DSIM_VCD_SCOPES={"TOP", "conflicts_modular",}' --std=c++14 -O3 -march=native -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fno-stack-protector conflicts_modular.cpp -o "conflicts_modular.opt"
make[1]: Leaving directory '/Users/namin/code/sec/koika/examples/_objects/conflicts_modular.v'

-- Compiling examples/cosimulation.v --
dune build "examples/_objects/cosimulation.v/cosimulation.ml"
dune exec -- cuttlec "_build/default/examples/_objects/cosimulation.v/cosimulation.ml" -T all -o "examples/_objects/cosimulation.v"
cp: -t: No such file or directory
make: *** [Makefile:117: examples/_objects/cosimulation.v] Error 1

Thanks so much for debugging this!

namin commented

Thanks, Jason, that's helpful. I just removed the -t since it appears that doesn't change the semantics in this case. Now, I get another error further down:

-- Compiling examples/cosimulation.v --
dune build "examples/_objects/cosimulation.v/cosimulation.ml"
dune exec -- cuttlec "_build/default/examples/_objects/cosimulation.v/cosimulation.ml" -T all -o "examples/_objects/cosimulation.v"
make[1]: Entering directory '/Users/namin/code/sec/koika/examples/_objects/cosimulation.v'
make[1]: Circular blackbox.obj_dir.opt/Vblackbox.mk <- blackbox.obj_dir.opt/Vblackbox.mk dependency dropped.
verilator --cc --Mdir blackbox.obj_dir.opt/ blackbox.v
make -C blackbox.obj_dir.opt -f Vblackbox.mk Vblackbox.mk
make[2]: Entering directory '/Users/namin/code/sec/koika/examples/_objects/cosimulation.v/blackbox.obj_dir.opt'
make[2]: Nothing to be done for 'Vblackbox.mk'.
make[2]: Leaving directory '/Users/namin/code/sec/koika/examples/_objects/cosimulation.v/blackbox.obj_dir.opt'
make -C blackbox.obj_dir.opt -f Vblackbox.mk Vblackbox__ALL.a
make[2]: Entering directory '/Users/namin/code/sec/koika/examples/_objects/cosimulation.v/blackbox.obj_dir.opt'
/usr/bin/perl /usr/local/Cellar/verilator/4.218/share/verilator/bin/verilator_includer -DVL_INCLUDE_OPT=include Vblackbox.cpp Vblackbox___024root__DepSet_h027b497e__0.cpp Vblackbox___024root__Slow.cpp Vblackbox___024root__DepSet_h027b497e__0__Slow.cpp Vblackbox__Syms.cpp > Vblackbox__ALL.cpp
clang++  -I.  -MMD -I/usr/local/Cellar/verilator/4.218/share/verilator/include -I/usr/local/Cellar/verilator/4.218/share/verilator/include/vltstd -DVM_COVERAGE=0 -DVM_SC=0 -DVM_TRACE=0 -DVM_TRACE_FST=0 -faligned-new -fbracket-depth=4096 -fcf-protection=none -Qunused-arguments -Wno-bool-operation -Wno-tautological-bitwise-compare -Wno-parentheses-equality -Wno-sign-compare -Wno-uninitialized -Wno-unused-parameter -Wno-unused-variable -Wno-shadow      -std=gnu++14 -Os -c -o Vblackbox__ALL.o Vblackbox__ALL.cpp
echo "" > Vblackbox__ALL.verilator_deplist.tmp
Archive ar -rcs Vblackbox__ALL.a Vblackbox__ALL.o
rm Vblackbox__ALL.verilator_deplist.tmp
make[2]: Leaving directory '/Users/namin/code/sec/koika/examples/_objects/cosimulation.v/blackbox.obj_dir.opt'
make -C blackbox.obj_dir.opt -f Vblackbox.mk verilated.o
make[2]: Entering directory '/Users/namin/code/sec/koika/examples/_objects/cosimulation.v/blackbox.obj_dir.opt'
make[2]: 'verilated.o' is up to date.
make[2]: Leaving directory '/Users/namin/code/sec/koika/examples/_objects/cosimulation.v/blackbox.obj_dir.opt'
g++ -I /usr/local/Cellar/verilator/4.218/share/verilator/include -Wl,--start-group blackbox.obj_dir.opt/verilated.o blackbox.obj_dir.opt/Vblackbox__ALL.a  -Wall -Wextra '-DSIM_VCD_SCOPES={"TOP", "cosimulation",}' --std=c++14 -O3 -march=native -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fno-stack-protector cosimulation.cpp -o "cosimulation.opt"
ld: unknown option: --start-group
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [Makefile:42: cosimulation.opt] Error 1
make[1]: Leaving directory '/Users/namin/code/sec/koika/examples/_objects/cosimulation.v'
make: *** [Makefile:119: examples/_objects/cosimulation.v] Error 2

I think --start-group is not available on Mac OS X, even for gcc.

Woohoo! Thanks @JasonGross and thanks @namin for your infinite patience :)

This last one is not too bad: it's the only example that uses --start-group. --start-group is a linker parameter that is in the GNU linker ld and presumably not in macOS ld.

Just skipping the example should be safe; either with make -k or you can delete examples/cosimulation.v and examples/cosimulation.v.etc.

namin commented

I removed the cosimulation example, and now there's a problem with another example:

-- Compiling examples/datatypes.v --
dune build "examples/_objects/datatypes.v/datatypes.ml"
dune exec -- cuttlec "_build/default/examples/_objects/datatypes.v/datatypes.ml" -T all -o "examples/_objects/datatypes.v"
make[1]: Entering directory '/Users/namin/code/sec/koika/examples/_objects/datatypes.v'
g++   -Wall -Wextra '-DSIM_VCD_SCOPES={"TOP", "datatypes",}' --std=c++14 -O3 -march=native -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fno-stack-protector datatypes.cpp -o "datatypes.opt"
In file included from datatypes.cpp:2:
In file included from ./datatypes.hpp:10:
In file included from ./cuttlesim.hpp:5:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/algorithm:688:67: error: no viable conversion from returned value of type 'bits<1>' to function return type 'bool'
    bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
                                                                  ^~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/algorithm:1272:14: note: in instantiation of member function 'std::__equal_to<prims::bits<8>>::operator()' requested here
        if (!__pred(*__first1, *__first2))
             ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/algorithm:1285:19: note: in instantiation of function template specialization 'std::equal<const prims::bits<8> *, const prims::bits<8> *, std::__equal_to<prims::bits<8>>>' requested here
    return _VSTD::equal(__first1, __last1, __first2, __equal_to<__v1, __v2>());
                  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/array:375:19: note: in instantiation of function template specialization 'std::equal<const prims::bits<8> *, const prims::bits<8> *>' requested here
    return _VSTD::equal(__x.begin(), __x.end(), __y.begin());
                  ^
./cuttlesim.hpp:598:66: note: in instantiation of function template specialization 'std::__1::operator==<prims::bits<8>, 4>' requested here
    return bits<1>::mk(static_cast<const std::array<T, len>&>(x) ==
                                                                 ^
./datatypes.hpp:74:34: note: in instantiation of function template specialization 'prims::operator==<prims::bits<8>, 4>' requested here
                     bool(v1.src == v2.src) && bool(v1.dst == v2.dst));
                                 ^
./cuttlesim.hpp:231:14: note: explicit conversion function is not a candidate
    explicit operator bool() const {
             ^
1 error generated.
make[1]: *** [Makefile:42: datatypes.opt] Error 1
make[1]: Leaving directory '/Users/namin/code/sec/koika/examples/_objects/datatypes.v'
make: *** [Makefile:119: examples/_objects/datatypes.v] Error 2

I'll report on any other after that.

namin commented
-- Compiling tests/arrays.lv --
dune exec -- cuttlec "tests/arrays.lv" -T all -o "tests/_objects/arrays.lv" 
make[1]: Entering directory '/Users/namin/code/sec/koika/tests/_objects/arrays.lv'
g++   -Wall -Wextra '-DSIM_VCD_SCOPES={"TOP", "arrays",}' --std=c++14 -O3 -march=native -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fno-stack-protector arrays.cpp -o "arrays.opt"
In file included from arrays.cpp:2:
In file included from ./arrays.hpp:10:
In file included from ./cuttlesim.hpp:5:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/algorithm:688:67: error: no viable conversion from returned value of type 'bits<1>' to function return type 'bool'
    bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
                                                                  ^~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/algorithm:1272:14: note: in instantiation of member function 'std::__equal_to<prims::bits<1>>::operator()' requested here
        if (!__pred(*__first1, *__first2))
             ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/algorithm:1285:19: note: in instantiation of function template specialization 'std::equal<const prims::bits<1> *, const prims::bits<1> *, std::__equal_to<prims::bits<1>>>' requested here
    return _VSTD::equal(__first1, __last1, __first2, __equal_to<__v1, __v2>());
                  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/array:375:19: note: in instantiation of function template specialization 'std::equal<const prims::bits<1> *, const prims::bits<1> *>' requested here
    return _VSTD::equal(__x.begin(), __x.end(), __y.begin());
                  ^
./cuttlesim.hpp:598:66: note: in instantiation of function template specialization 'std::__1::operator==<prims::bits<1>, 4>' requested here
    return bits<1>::mk(static_cast<const std::array<T, len>&>(x) ==
                                                                 ^
./arrays.hpp:134:26: note: in instantiation of function template specialization 'prims::operator==<prims::bits<1>, 4>' requested here
    prims::display((arr0 == prims::replace<1>(prims::replace<0>(arr, 1'1_b), 1'0_b)),
                         ^
./arrays.hpp:274:5: note: in instantiation of member function 'module_arrays<extfuns>::rule_init' requested here
    rule_init();
    ^
./arrays.hpp:284:7: note: in instantiation of member function 'module_arrays<extfuns>::cycle' requested here
      cycle();
      ^
./cuttlesim.hpp:1293:51: note: in instantiation of member function 'module_arrays<extfuns>::run' requested here
    return simulator(std::forward<Args>(args)...).run(ncycles).snapshot();
                                                  ^
./cuttlesim.hpp:1363:21: note: in instantiation of function template specialization 'cuttlesim::init_and_run<simulator>' requested here
    auto snapshot = init_and_run<simulator>(
                    ^
arrays.cpp:10:53: note: in instantiation of function template specialization 'cuttlesim::main<simulator>' requested here
int main(int argc, char **argv) { return cuttlesim::main<simulator>(argc, argv); }
                                                    ^
./cuttlesim.hpp:231:14: note: explicit conversion function is not a candidate
    explicit operator bool() const {
             ^
1 error generated.
make[1]: *** [Makefile:42: arrays.opt] Error 1
make[1]: Leaving directory '/Users/namin/code/sec/koika/tests/_objects/arrays.lv'
make: *** [Makefile:116: tests/_objects/arrays.lv] Error 2
namin commented

And that is all. :)

So here are the steps to compile for mac os x:

  • brew install make
  • export PATH="/usr/local/opt/make/libexec/gnubin:$PATH"
  • remove -t from the two cp lines in the Makefile (I suppose this change can be committed.)
  • remove the three files that don't compile (see above)
  • then make works!

Thanks so much for making this possible. :)

Phew, thanks a lot! These last two problems are a bit surprising but should be straightforward to fix.
Quick question to make sure I understand the issue: if you have time, could you confirm that the following small program doesn't compile either? You can place it in test.cpp in the root of the repo.

#include "ocaml/backends/resources/cuttlesim.hpp"

int main() {
  prims::array<bits<3>, 2> a = { 3'0_b, 3'1_b };
  bits<1> b = a == a;
  return (int)(b.v);
}

On my (GNU) machine it compiles and returns 1, but it looks like Apple's libstdc++ picks up our == overload and isn't happy with it returning bit<1> (if that's the right explanation then this small program will also fail).

Regarding this one:

remove -t from the two cp lines in the Makefile (I suppose this change can be committed.)

I'm not sure it's 100% safe. The problem is that cp a/ b/ creates b/ if b/ doesn't exist, but creates b/a/ if b/ already exists; -t prevents the latter from happening.

I will update the readme, and hopefully we can fix the == problem. For the other two issues (-t and the linker) I need to look a bit deeper :)

namin commented

I am not sure about what is the command to compile the test file, but this is what I've got:

% g++   -Wall -Wextra '-DSIM_VCD_SCOPES={"TOP", "test",}' --std=c++14 -O3 -march=native -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0 -fno-stack-protector test.cpp -o "test.opt"

In file included from test.cpp:1:
In file included from ./ocaml/backends/resources/cuttlesim.hpp:5:
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/algorithm:688:67: error: no viable conversion from returned value of type 'bits<1>' to function return type 'bool'
    bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
                                                                  ^~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/algorithm:1272:14: note: in instantiation of member function 'std::__equal_to<prims::bits<3>>::operator()' requested here
        if (!__pred(*__first1, *__first2))
             ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/algorithm:1285:19: note: in instantiation of function template specialization 'std::equal<const prims::bits<3> *, const prims::bits<3> *, std::__equal_to<prims::bits<3>>>' requested here
    return _VSTD::equal(__first1, __last1, __first2, __equal_to<__v1, __v2>());
                  ^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/array:375:19: note: in instantiation of function template specialization 'std::equal<const prims::bits<3> *, const prims::bits<3> *>' requested here
    return _VSTD::equal(__x.begin(), __x.end(), __y.begin());
                  ^
./ocaml/backends/resources/cuttlesim.hpp:598:66: note: in instantiation of function template specialization 'std::__1::operator==<prims::bits<3>, 2>' requested here
    return bits<1>::mk(static_cast<const std::array<T, len>&>(x) ==
                                                                 ^
test.cpp:5:17: note: in instantiation of function template specialization 'prims::operator==<prims::bits<3>, 2>' requested here
  bits<1> b = a == a;
                ^
./ocaml/backends/resources/cuttlesim.hpp:231:14: note: explicit conversion function is not a candidate
    explicit operator bool() const {
             ^
1 error generated.

Thanks.

Super helpful, thanks a lot. What's happening is that your libstdc++ implements std::equal differently from mine. Mine uses this algorithm to compare arrays:

	  for (; __first1 != __last1; ++__first1, (void) ++__first2)
	    if (!(*__first1 == *__first2))
	      return false;
	  return true;

Yours uses this algorithm to compare arrays:

template
struct __equal_to<_T1, const _T1>
{
  bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
};

template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
bool equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred)
{
  for (; __first1 != __last1; ++__first1, (void) ++__first2)
    if (!__pred(*__first1, *__first2))
      return false;
  return true;
}

The difference is that in mine the call to operator== is directly under a call to operator!. In yours the comparison goes through a parameter __pred (the operator() of the equal structure).

This matters because in cuttlesim operator== returns a bits<1> value. bits<1> has an explicit operator bool() cast defined, and in C++11 this sort of casts are called when passing a convertible value to operator! or operator==, but not when returning (as in operator() of struct equal in your libstdc++).

I'm not sure who to blame ^^ It would be relatively safe to make the convertion to bool implicit for bit<1>, but I'm not sure how to do that (C++20 has explicit(bool), but C++14 doesn't). I asked on stackoverflow at https://stackoverflow.com/questions/71347981/is-there-a-c14-alternative-to-explicitexpr-introduced-in-c20

Could you try the gh-18-macos branch? I tried to fix the -t issue and the three compilation issues there, but I don't have a macOS computer to confirm the fix.

(Your first two bullet points about make will remain (the fix would be to extend the existing configure script to be able to use a simpler makefile), though with an early exit if the wrong version of make is used, but the rest should be fixed.)

but I don't have a macOS computer to confirm the fix.

Do you want to add a MacOS CI job? (GitHub actions supports Windows and Mac jobs too)

namin commented

I confirm that it works :) Thank you!!!

Do you want to add a MacOS CI job? (GitHub actions supports Windows and Mac jobs too)

That would be lovely, but we would need to add a GNU CI job first :) At the moment we have no CI jobs at all ^^

I confirm that it works :) Thank you!!!

Wonderful, thanks a lot for all your help!