bsansouci / bsb-native

Build system for OCaml/Reason
Other
245 stars 10 forks source link

Check if opam is installed when having any ocamlfind-dependencies #15

Open bsansouci opened 6 years ago

bsansouci commented 6 years ago

Right now, if you have reason-cli you'll get this error

❯ ./node_modules/.bin/bsb -make-world
ninja: Entering directory `lib/bs/bytecode'
[2/2] Building src/index.mlast.d
[1/2] Building src/index.cmo
FAILED: src/index.cmo src/index.cmi
ocamlfind ocamlc    -I src -package lwt.ppx -package lwt.unix  -passopt -thread -passopt -color -passopt always -o src/index.cmo -w -30-40+6+7+27+32..39+44+45+101-31 -g -c -intf-suffix .mliast_simple -impl src/index.mlast_simple
ocamlc.opt: unknown option '-color'.
Usage: ocamlc <options> <files>
Options are:
  -a  Build a library
  -absname  Show absolute filenames in error messages
  -annot  Save information in <filename>.annot
  -bin-annot  Save typedtree in <filename>.cmt
  -c  Compile only (do not link)
  -cc <command>  Use <command> as the C compiler and linker
  -cclib <opt>  Pass option <opt> to the C linker
  -ccopt <opt>  Pass option <opt> to the C compiler and linker
  -compat-32  Check that generated bytecode can run on 32-bit platforms
  -config  Print configuration values and exit
  -custom  Link in custom mode
  -custom  Link in custom mode
...

This is obviously terrible. We could detect if opam is installed by simply running which opam using some utility that bsb has to run commands and get the output (see Bsb_build_utils).

tonyhb commented 6 years ago

Ahh so ocamlc.opt: unknown option '-color'. is purely related to reason-cli? I have opam installed - using → 4.02.3+buckle-master ocaml-variants.4.02.3+buckle-master 4.02.3+buckle-master and I'm still seeing this error :/

I'll try and dig into this some but I'm really not sure where to get started :)

bsansouci commented 6 years ago

Oh really? If you run which ocamlfind what do you get? I'm guessing having opam isn't enough, you need to opam install ocamlfind as well, so shadow the ocamlfind that comes with reason-cli. Could you try that and see if you still get that error?

tonyhb commented 6 years ago

thanks for replying so quickly!

which ocamlfind returns the bin from opam (running inside a debian vm):

vagrant@debian ~/projects/ocamlserver % which ocamlfind                                                                                                       
/home/vagrant/.opam/4.02.3+buckle-master/bin/ocamlfind

if i opam install ocamlfind i get this:

vagrant@debian ~/projects/ocamlserver % opam install ocamlfind
[NOTE] Package ocamlfind is already installed (current version is 1.7.3-1).

Everything compiles fine to any backend without ocamlfind-dependencies. As soon as I include this with any dependency I get errors.

bsansouci commented 6 years ago

No problem :)

Can you run which ocamlc.opt and ocamlc.opt --help?

tonyhb commented 6 years ago
vagrant@debian ~/projects/ocamlserver % which ocamlc.opt
/home/vagrant/.opam/4.02.3+buckle-master/bin/ocamlc.opt
vagrant@debian ~/projects/ocamlserver % ocamlc.opt -version
4.02.3+BS
vagrant@debian ~/projects/ocamlserver % ocamlc.opt --help
Usage: ocamlc <options> <files>
Options are:
  -a  Build a library
  -absname  Show absolute filenames in error messages
  -annot  Save information in <filename>.annot
  -bin-annot  Save typedtree in <filename>.cmt
  -c  Compile only (do not link)
  -cc <command>  Use <command> as the C compiler and linker
  -cclib <opt>  Pass option <opt> to the C linker
  -ccopt <opt>  Pass option <opt> to the C compiler and linker
  -compat-32  Check that generated bytecode can run on 32-bit platforms
  -config  Print configuration values and exit
  -custom  Link in custom mode
  -custom  Link in custom mode
  -dllib <lib>  Use the dynamically-loaded library <lib>
  -dllpath <dir>  Add <dir> to the run-time search path for shared libraries
  -dtypes  (deprecated) same as -annot
  -for-pack <ident>  Generate code that can later be `packed' with
     ocamlc -pack -o <ident>.cmo
  -g  Save debugging information
  -i  Print inferred interface
  -I <dir>  Add <dir> to the list of include directories
  -impl <file>  Compile <file> as a .ml file
  -intf <file>  Compile <file> as a .mli file
  -intf-suffix <string>  Suffix for interface files (default: .mli)
  -intf_suffix <string>  (deprecated) same as -intf-suffix
  -keep-docs  Keep documentation strings in .cmi files
  -keep-locs  Keep locations in .cmi files
  -labels  Use commuting label mode
  -linkall  Link all modules, even unused ones
  -make-runtime  Build a runtime system with given C objects and libraries
  -make_runtime  (deprecated) same as -make-runtime
  -modern  (deprecated) same as -labels
  -no-alias-deps  Do not record dependencies for module aliases
  -no-app-funct  Deactivate applicative functors
  -no-check-prims  Do not check runtime for primitives
  -noassert  Do not compile assertion checks
  -noautolink  Do not automatically link C libraries specified in .cma files
  -nolabels  Ignore non-optional labels in types
  -nostdlib  Do not add default directory to the list of include directories
  -o <file>  Set output file name to <file>
  -open <module>  Opens the module <module> before typing
  -output-obj  Output an object file instead of an executable
  -output-complete-obj  Output an object file, including runtime, instead of an executable
  -pack  Package the given .cmo files into one .cmo
  -pp <command>  Pipe sources through preprocessor <command>
  -ppx <command>  Pipe abstract syntax trees through preprocessor <command>
  -principal  Check principality of type inference
  -rectypes  Allow arbitrary recursive types
  -runtime-variant <str>  Use the <str> variant of the run-time system
  -safe-string  Make strings immutable
  -short-paths  Shorten paths in types
  -strict-sequence  Left-hand part of a sequence must have type unit
  -strict-formats  Reject invalid formats accepted by legacy implementations
     (Warning: Invalid formats may behave differently from
      previous OCaml versions, and will become always-rejected
      in future OCaml versions. You should use this flag
      to detect and fix invalid formats.)
  -thread  Generate code that supports the system threads library
  -unsafe  Do not compile bounds checking on array and string access
  -unsafe-string  Make strings mutable (default)
  -use-runtime <file>  Generate bytecode for the given runtime system
  -use_runtime <file>  (deprecated) same as -use-runtime
  -v  Print compiler version and location of standard library and exit
  -verbose  Print calls to external commands
  -version  Print version and exit
  -vmthread  Generate code that supports the threads library with VM-level
     scheduling
  -vnum  Print version number and exit
  -w <list>  Enable or disable warnings according to <list>:
        +<spec>   enable warnings in <spec>
        -<spec>   disable warnings in <spec>
        @<spec>   enable warnings in <spec> and treat them as errors
     <spec> can be:
        <num>             a single warning number
        <num1>..<num2>    a range of consecutive warning numbers
        <letter>          a predefined set
     default setting is "+a-4-6-7-9-27-29-32..39-41..42-44-45-48-50"
  -warn-error <list>  Enable or disable error status for warnings according
     to <list>.  See option -w for the syntax of <list>.
     Default setting is "-a"
  -warn-help  Show description of warning numbers
  -where  Print location of standard library and exit
  - <file>  Treat <file> as a file name (even if it starts with `-')
  -nopervasives  (undocumented)
  -use-prims <file>  (undocumented)
  -dsource  (undocumented)
  -dparsetree  (undocumented)
  -dtypedtree  (undocumented)
  -drawlambda  (undocumented)
  -dlambda  (undocumented)
  -dinstr  (undocumented)
  -help  Display this list of options
  --help  Display this list of options

Trying a bunch of different configurations and might end up nuking the system to go from scratch so that I know what's going on. Sorry for not being more helpful - trying to dig into ReasonML cross compilation for the first time. May switch to jbuilder then back to this to get a better understanding, too. Lots of things to learn!

bsansouci commented 6 years ago

This is very strange... Thanks for reporting, I'll see what I can do.

Just wondering, what package are you using from opam? Also what's your compilation target?

tonyhb commented 6 years ago

I'm trying to get opium to work, which failed with this error. So I also cloned your example repo using alcotest which also errors. I don't necessarily have to use the imports in the entrypoint - just including any package as an ocamlfind dependency in bsconfig produces these errors.

I tried both bytecode and native; they both fail.

Sorry for dumping this on you too. I'm digging around trying to find out what's up also. Wonder what's wrong with my setup on this system.