COMMUNITY

Opam switch?

#1

Hiya,

Trying to set up haxe source compilation (yes, still trying), this time on Ubuntu (on Windows Subsystem for Linux).

When I follow https://github.com/HaxeFoundation/haxe/blob/development/extra/BUILDING.md and get to:

opam pin add haxe path/to/haxe --no-action

I get the error message:

[ERROR] No switch is currently set. Please use 'opam switch' to set or install a switch

I’ve tried various things, but since I don’t know what I’m doing, I’ve had no success getting past this error message.

Anyone knows what’s going on?

Many thanks

0 Likes

How can I add a target language
(Valentin Lemière) #2

Did you run opam init?

If the command still doesn’t run after that then try the opam switch as mentioned in the error message.

0 Likes

(Simon Krajewski) #3

Is that opam 2? In that case my recommendation would be to launch it into the sun and install opam 1.

0 Likes

#4

2.0.2

How do I go about installing version 1?

Many thanks!

0 Likes

#5

Yes, I did.

But with what options?
As I already said, I have no idea what I’m actually doing…

Many thanks

0 Likes

(Andy Li) #6

What Ubuntu version are you using?
How did you install opam?
Did you spot any error/warning message during opam init?
It would be useful if you post the complete opam setup log here.

0 Likes

#7

Hi Andy,

18.04, Windows Subsystem for Linux.

Through these steps, initially:

add-apt-repository ppa:avsm/ppa
apt update
apt install opam

Because of the version 2 vs 1 remark, I later removed opam 2 again, and installed version 1 instead.
I put it on hold via

sudo apt-mark hold opam 

I’ve gotten somewhat further now.
Current state:

So it;s still not working, but I’ve at least gotten rid of the “switch” problem.

Any ideas on how to proceed from here?

Many thanks!

0 Likes

(Andy Li) #8

The funny thing is that you actually have to use opam 2 instead of 1 (due to https://github.com/HaxeFoundation/haxe/pull/8028).

Please switch it back to opam 2 and post your log…

0 Likes

#9

Oh, okay.

What will probably bring back the “switch” problem, won’t it?

0 Likes

#10
heeb@HeebLenovo:~$ opam --version
1.2.2
heeb@HeebLenovo:~$ sudo su
[sudo] password for heeb:
root@HeebLenovo:/home/heeb# apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages were automatically installed and are no longer required:
  aspcud clasp darcs gringo liblua5.3-0 libpthread-stubs0-dev
  libpython-stdlib libpython2.7-minimal libpython2.7-stdlib
  libx11-dev libx11-doc libxau-dev libxcb1-dev libxdmcp-dev
  mercurial mercurial-common ocaml ocaml-base opam-docs python
  python-minimal python2.7 python2.7-minimal x11proto-core-dev
  x11proto-dev xorg-sgml-doctools xtrans-dev
Use 'sudo apt autoremove' to remove them.
The following packages will be upgraded:
  opam
1 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 2304 kB of archives.
After this operation, 5104 kB disk space will be freed.
Do you want to continue? [Y/n]
Get:1 http://ppa.launchpad.net/avsm/ppa/ubuntu bionic/main amd64 opam amd64 2.0.2-0ppa2~bionic [2304 kB]
Fetched 2304 kB in 1s (1729 kB/s)
(Reading database ... 40348 files and directories currently installed.)
Preparing to unpack .../opam_2.0.2-0ppa2~bionic_amd64.deb ...
Unpacking opam (2.0.2-0ppa2~bionic) over (1.2.2-6) ...
Replacing files in old package opam-docs (1.2.2-6) ...
Setting up opam (2.0.2-0ppa2~bionic) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
root@HeebLenovo:/home/heeb# exit
exit
heeb@HeebLenovo:~$ opam --version
2.0.2
heeb@HeebLenovo:~$ cd haxe/dev
heeb@HeebLenovo:~/haxe/dev$ cd haxe
heeb@HeebLenovo:~/haxe/dev/haxe$ opam pin add haxe ./ --no-action
This version of opam requires an update to the layout of
/home/heeb/.opam from version 1.2 to version 2.0, which can't be
reverted.
You may want to back it up before going further.
Perform the update and continue? [Y/n] y
Format upgrade done.

<><> Rerunning init and update ><><><><><><><><><><><><><><><><><>Checking for available remotes: rsync and local, git, mercurial, darcs. Perfect!
[WARNING] Recommended dependencies -- most packages rely on
          these:
  - m4
A hook can be added to opam's init scripts to ensure that the
shell remains in sync with the opam environment when they are
loaded. Set that up? [y/N] n

<><> Updating repositories ><><><><><><><><><><><><><><><><><><><>Processing  1/1: [default: http]
[default] synchronised from https://opam.ocaml.org/1.2.2
[NOTE] The repository 'default' will be *permanently* redirected
       to https://opam.ocaml.org/ (opam-version < "1.2.0" |
       opam-version >= "2.0~")
[default] Initialised
Update done, please now retry your command.
heeb@HeebLenovo:~/haxe/dev/haxe$ opam install haxe --deps-only

<><> Synchronising pinned packages ><><><><><><><><><><><><><><><>[haxe.4.0.0] synchronised from file:///mnt/c/HaxeToolkit/dev/haxe
[WARNING] Failed checks in opam file from upstream of haxe:
    error 57: Synopsis and description must not be both empty

The following actions will be performed:
  ∗ install ocaml-config            1
  ∗ install conf-m4                 1
  ∗ install conf-pkg-config         1.1
  ∗ install conf-neko               1
  ∗ install ocaml                   4.05.0
  ∗ install conf-zlib               1
  ∗ install conf-libpcre            1
  ∗ install ocamlfind               1.8.0
  ∗ install obuild                  0.1.10
  ∗ install dune                    1.8.2
  ∗ install camlp4                  4.05+system
  ∗ install xml-light               2.4
  ∗ install base-bytes              base
  ∗ install ptmap                   2.0.3
  ∗ install jbuilder                transition
  ∗ install sha                     1.12
  ∗ install result                  1.3
  ∗ install ppx_derivers            1.0
  ∗ install gen                     0.5.1
  ∗ install cppo                    1.6.5
  ∗ install ocaml-migrate-parsetree 1.2.0
  ∗ install extlib                  1.7.6
  ∗ install ppx_tools_versioned     5.2
  ∗ install sedlex                  1.99.4
===== ∗ 24 =====
Do you want to continue? [Y/n] y

<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><>[camlp4.4.05+system] downloaded from cache at https://opam.ocaml.org/cache
[cppo.1.6.5] downloaded from cache at https://opam.ocaml.org/cache[dune.1.8.2] downloaded from cache at https://opam.ocaml.org/cache[extlib.1.7.6] downloaded from cache at https://opam.ocaml.org/cache
[gen.0.5.1] downloaded from cache at https://opam.ocaml.org/cache
[obuild.0.1.10] downloaded from cache at https://opam.ocaml.org/cache
[ocaml-migrate-parsetree.1.2.0] downloaded from cache at https://opam.ocaml.org/cache
[ocamlfind.1.8.0] downloaded from cache at https://opam.ocaml.org/cache
[ppx_derivers.1.0] downloaded from cache at https://opam.ocaml.org/cache
[ppx_tools_versioned.5.2] downloaded from cache at https://opam.ocaml.org/cache
[ptmap.2.0.3] downloaded from cache at https://opam.ocaml.org/cache
[result.1.3] downloaded from cache at https://opam.ocaml.org/cache[sedlex.1.99.4] downloaded from cache at https://opam.ocaml.org/cache
[sha.1.12] downloaded from cache at https://opam.ocaml.org/cache
[xml-light.2.4] downloaded from cache at https://opam.ocaml.org/cache

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><>∗ installed ocaml-config.1
[ERROR] The compilation of conf-m4 failed at
        "/home/heeb/.opam/opam-init/hooks/sandbox.sh build sh
        -exc echo | m4".
[ERROR] The compilation of conf-neko failed at
        "/home/heeb/.opam/opam-init/hooks/sandbox.sh build neko
        -version".
[ERROR] The compilation of conf-pkg-config failed at
        "/home/heeb/.opam/opam-init/hooks/sandbox.sh build
        pkg-config --help".
[ERROR] The compilation of ocaml failed at
        "/home/heeb/.opam/opam-init/hooks/sandbox.sh build ocaml
        /home/heeb/.opam/system/share/ocaml-config/gen_ocaml_config.ml
        4.05.0 ocaml".

#=== ERROR while compiling ocaml.4.05.0 =========================## context     2.0.2 | linux/x86_64 | base-bigarray.base base-threads.base base-unix.base ocaml-system.4.05.0 | https://opam.ocaml.org/#a4d2989b
# path        ~/.opam/system/.opam-switch/build/ocaml.4.05.0
# command     ~/.opam/opam-init/hooks/sandbox.sh build ocaml /home/heeb/.opam/system/share/ocaml-config/gen_ocaml_config.ml 4.05.0 ocaml
# exit-code   1
# env-file    ~/.opam/log/ocaml-334-80bbd8.env
# output-file ~/.opam/log/ocaml-334-80bbd8.out
### output ###
# bwrap: Creating new namespace failed, likely because the kernel does not support user namespaces.  bwrap must be installed setuid on such systems.


#=== ERROR while compiling conf-pkg-config.1.1 ==================## context     2.0.2 | linux/x86_64 | base-bigarray.base base-threads.base base-unix.base ocaml-system.4.05.0 | https://opam.ocaml.org/#a4d2989b
# path        ~/.opam/system/.opam-switch/build/conf-pkg-config.1.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build pkg-config --help
# exit-code   1
# env-file    ~/.opam/log/conf-pkg-config-334-3c35aa.env
# output-file ~/.opam/log/conf-pkg-config-334-3c35aa.out
### output ###
# bwrap: Creating new namespace failed, likely because the kernel does not support user namespaces.  bwrap must be installed setuid on such systems.


#=== ERROR while compiling conf-neko.1 ==========================## context     2.0.2 | linux/x86_64 | base-bigarray.base base-threads.base base-unix.base ocaml-system.4.05.0 | https://opam.ocaml.org/#a4d2989b
# path        ~/.opam/system/.opam-switch/build/conf-neko.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build neko -version
# exit-code   1
# env-file    ~/.opam/log/conf-neko-334-b639e0.env
# output-file ~/.opam/log/conf-neko-334-b639e0.out
### output ###
# bwrap: Creating new namespace failed, likely because the kernel does not support user namespaces.  bwrap must be installed setuid on such systems.


#=== ERROR while compiling conf-m4.1 ============================## context     2.0.2 | linux/x86_64 | base-bigarray.base base-threads.base base-unix.base ocaml-system.4.05.0 | https://opam.ocaml.org/#a4d2989b
# path        ~/.opam/system/.opam-switch/build/conf-m4.1
# command     ~/.opam/opam-init/hooks/sandbox.sh build sh -exc echo | m4
# exit-code   1
# env-file    ~/.opam/log/conf-m4-334-47e100.env
# output-file ~/.opam/log/conf-m4-334-47e100.out
### output ###
# bwrap: Creating new namespace failed, likely because the kernel does not support user namespaces.  bwrap must be installed setuid on such systems.



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><>┌─ The following actions failed
│ λ build conf-m4         1
│ λ build conf-neko       1
│ λ build conf-pkg-config 1.1
│ λ build ocaml           4.05.0
└─
┌─ The following changes have been performed (the rest was aborted)
│ ∗ install ocaml-config 1
└─

The packages you requested declare the following system
dependencies. Please make sure they are installed before
retrying:
    m4 neko neko-dev pkg-config

# Run eval $(opam env) to update the current shell environment

The former state can be restored with:
    opam switch import
"/home/heeb/.opam/system/.opam-switch/backup/state-20190401215256.export"
heeb@HeebLenovo:~/haxe/dev/haxe$ make
make -C libs/extlib-leftovers native && make -C libs/extc native && make -C libs/neko native && make -C libs/javalib native && make -C libs/swflib native && make -C libs/ttflib native && make -C libs/ilib native && make -C libs/objsize native && make -C libs/pcre native && make -C libs/ziplib native && true
make[1]: Entering directory '/mnt/c/HaxeToolkit/dev/haxe/libs/extlib-leftovers'
make[1]: Nothing to be done for 'native'.
make[1]: Leaving directory '/mnt/c/HaxeToolkit/dev/haxe/libs/extlib-leftovers'
make[1]: Entering directory '/mnt/c/HaxeToolkit/dev/haxe/libs/extc'
ocamlfind ocamlopt -safe-string -a -o extc.cmxa -package extlib extc.ml process.ml
ocamlfind: Package `extlib' not found
Makefile:16: recipe for target 'extc.cmxa' failed
make[1]: *** [extc.cmxa] Error 2
make[1]: Leaving directory '/mnt/c/HaxeToolkit/dev/haxe/libs/extc'
Makefile:114: recipe for target 'libs' failed
make: *** [libs] Error 2
heeb@HeebLenovo:~/haxe/dev/haxe$
0 Likes

(Andy Li) #11

A few things here.

First of all, try to clean up the opam 1 stuff (or any broken opam setup) by removing ~/.opam, which contains the ocaml switches (ocaml compilers and libraries). Just run rm -rf ~/.opam. It will be recreated when doing opam init (don’t run it yet, see below).

Secondly, opam 2 on Linux will try to use bubblewrap, which uses some Linux namespacing feature which is not implemented in WSL. So, we have to disable the use of bubblewrap during opam init. Let’s run opam init --disable-sandboxing. Run eval $(opam env) afterward as it is suggested by the opam init output.

Thirdly, the errors about conf-* can be solved by installing the related packages. The conf-* packages are opam’s way of stating system dependencies that should be installed outside of opam. So, sudo apt install m4 for conf-m4, sudo apt install neko neko-dev for conf-neko, sudo apt install pkg-config for conf-pkg-config.

2 Likes

#12

Thanks.
Done exactly as you said.

make still gives:

heeb@HeebLenovo:~/haxe/dev/haxe$ make
make -C libs/extlib-leftovers native && make -C libs/extc native && make -C libs/neko native && make -C libs/javalib native && make -C libs/swflib native && make -C libs/ttflib native && make -C libs/ilib native && make -C libs/objsize native && make -C libs/pcre native && make -C libs/ziplib native && true
make[1]: Entering directory '/mnt/c/HaxeToolkit/dev/haxe/libs/extlib-leftovers'
make[1]: Nothing to be done for 'native'.
make[1]: Leaving directory '/mnt/c/HaxeToolkit/dev/haxe/libs/extlib-leftovers'
make[1]: Entering directory '/mnt/c/HaxeToolkit/dev/haxe/libs/extc'
ocamlfind ocamlopt -safe-string -a -o extc.cmxa -package extlib extc.ml process.ml
ocamlfind: Package `extlib' not found
Makefile:16: recipe for target 'extc.cmxa' failed
make[1]: *** [extc.cmxa] Error 2
make[1]: Leaving directory '/mnt/c/HaxeToolkit/dev/haxe/libs/extc'
Makefile:114: recipe for target 'libs' failed
make: *** [libs] Error 2
heeb@HeebLenovo:~/haxe/dev/haxe$

So, exactly the same as before…

Any ideas?

Many thanks!

0 Likes

(Andy Li) #13

What’ the output of opam list?

0 Likes

(Andy Li) #14

BTW, running opam install haxe --deps-only should tell you to run eval $(opam env) again. Do it as it says.

0 Likes

#15
heeb@HeebLenovo:~/haxe/dev/haxe$ opam list
# Packages matching: installed
# Name        # Installed # Synopsis
base-bigarray base
base-threads  base
base-unix     base
ocaml         4.05.0      The OCaml compiler (virtual package)
ocaml-config  1           OCaml Switch Configuration
ocaml-system  4.05.0      The OCaml compiler (system version, from
heeb@HeebLenovo:~/haxe/dev/haxe$
0 Likes

(Andy Li) #16

Those are only the base OCaml compiler installation. There are no OCaml libraries installed. Did you run opam pin add haxe path/to/haxe --no-action and opam install haxe --deps-only? Any error message when running those?

0 Likes

#17

Yay, it looks like it’s actually building now… :grinning:

0 Likes

#18

Success!!!

Thanks sooooooo much!!!

heeb@HeebLenovo:~/haxe/dev/haxe$ ls -al
total 31736
drwxrwxrwx 1 heeb heeb     4096 Apr  2 01:12 .
drwxrwxrwx 1 heeb heeb     4096 Mar 31 21:33 ..
drwxrwxrwx 1 heeb heeb     4096 Apr  1 21:53 .git
-rwxrwxrwx 1 heeb heeb      193 Mar 22 14:02 .gitattributes
-rwxrwxrwx 1 heeb heeb     2340 Mar 22 14:02 .gitignore
-rwxrwxrwx 1 heeb heeb      260 Mar 22 14:02 .gitmodules
-rwxrwxrwx 1 heeb heeb      172 Mar 22 14:02 .merlin
-rwxrwxrwx 1 heeb heeb     7531 Mar 22 14:02 .travis.yml
drwxrwxrwx 1 heeb heeb     4096 Mar 22 14:02 .vscode
-rwxrwxrwx 1 heeb heeb     4260 Mar 22 14:02 CONTRIBUTING.md
-rwxrwxrwx 1 heeb heeb    10980 Mar 22 14:02 Makefile
-rwxrwxrwx 1 heeb heeb    60600 Apr  2 01:09 Makefile.dependencies
-rwxrwxrwx 1 heeb heeb     5548 Apr  2 01:09 Makefile.modules
-rwxrwxrwx 1 heeb heeb      448 Mar 22 14:02 Makefile.version_extra
-rwxrwxrwx 1 heeb heeb     3916 Mar 22 14:02 Makefile.win
-rwxrwxrwx 1 heeb heeb     5608 Mar 22 14:02 README.md
drwxrwxrwx 1 heeb heeb     4096 Apr  2 01:09 _build
-rwxrwxrwx 1 heeb heeb     4145 Mar 22 14:02 appveyor.yml
-rwxrwxrwx 1 heeb heeb  1224211 Mar 22 17:08 cygwin-setup.exe
drwxrwxrwx 1 heeb heeb     4096 Mar 22 14:02 extra
-rwxrwxrwx 1 heeb heeb 21034944 Apr  2 01:12 haxe
-rwxrwxrwx 1 heeb heeb   233327 Apr  2 01:12 haxelib
drwxrwxrwx 1 heeb heeb     4096 Mar 22 14:03 libs
-rwxrwxrwx 1 heeb heeb      993 Mar 22 14:02 opam
-rwxrwxrwx 1 heeb heeb  9873436 Mar 22 17:41 opam.tar.xz
drwxrwxrwx 1 heeb heeb     4096 Mar  4  2017 opam64
drwxrwxrwx 1 heeb heeb     4096 Mar 22 14:02 src
drwxrwxrwx 1 heeb heeb     4096 Apr  1 17:07 std
drwxrwxrwx 1 heeb heeb     4096 Mar 22 14:02 tests
-rwxrwxrwx 1 heeb heeb        0 Apr  2 01:12 tmp.tmp
heeb@HeebLenovo:~/haxe/dev/haxe$ ./haxe
Haxe Compiler 4.0.0-rc.2 - (C)2005-2019 Haxe Foundation
Usage: haxe <target> [options] [hxml files...]

Target:
  --js <file>                 compile code to JavaScript file
  --lua <file>                compile code to Lua file
  --swf <file>                compile code to Flash SWF file
  --as3 <directory>           generate AS3 code into target directory
  --neko <file>               compile code to Neko Binary
  --php <directory>           generate PHP code into target directory
  --cpp <directory>           generate C++ code into target directory
  --cppia <file>              generate Cppia code into target file
  --cs <directory>            generate C# code into target directory
  --java <directory>          generate Java code into target directory
  --python <file>             generate Python code as target file
  --hl <file>                 compile HL code as target file
  --interp                    interpret the program using internal macro system

Compilation:
  -p, --class-path <path>     add a directory to find source files
  -m, --main <class>          select startup class
  -L, --library <name[:ver]>  use a haxelib library
  -D, --define <var[=value]>  define a conditional compilation flag

Debug:
  -v, --verbose               turn on verbose mode
  --debug                     add debug information to the compiled code

Miscellaneous:
  --version                   print version and exit
  -h, --help                  show extended help information
  --help-defines              print help for all compiler specific defines
  --help-metas                print help for all compiler metadatas
  --run <module> [args...]    compile and execute a Haxe module with command line arguments
heeb@HeebLenovo:~/haxe/dev/haxe$
3 Likes

(Simon Krajewski) #19

Uhm, does that mean opam 2 is a hard requirement for building Haxe now? Because I don’t think that would be good…

0 Likes

(Kyliathy) #20

@Matt you are one persistent bada55! :slight_smile: Happy to have you here and happy you got things working! Congratulations! :slight_smile:

@Simn why?

1 Like