Skip to content

Latest commit

 

History

History
219 lines (198 loc) · 11.5 KB

UBUNTU_WSL.md

File metadata and controls

219 lines (198 loc) · 11.5 KB

Playing with Scala 3 in Ubuntu WSL

Flix project This document presents one Scala 3 code example we work on in the Ubuntu WSL environment.

In the following we assume the Ubuntu WSL 1 is installed on the user's Windows machine.

We open a Ubuntu terminal and navigate to directory dotty-examples/ which contains our local checkout of the GitHub project dotty-examples :

$ pwd
/home/michelou
$ cd /mnt/c/Users/michelou/workspace-perso/dotty-examples/

Then we execute our Bash script setenv.sh to set up our Unix environment :

$ . ./setenv.sh
$ which bash gradle make mvn
/bin/bash
/opt/gradle/bin/gradle
/usr/bin/make
/opt/apache-maven/bin/mvn
$ env | grep _HOME
JAVA_HOME=/opt/jdk-temurin-11
MAVEN_HOME=/opt/apache-maven
SCALA_HOME=/opt/scala-2.13.12
SCALA3_HOME=/opt/scala3-3.3.2-RC1
GRADLE_HOME=/opt/gradle
SBT_HOME=/opt/sbt
ANT_HOME=/opt/apache-ant

🔎 We install additional software tools such as Ant 2, Gradle or Scala into root directory /opt/:

$ find /opt -maxdepth 1 -type d -print | sort | xargs -i sh -c 'du -sh {}'
44M     /opt/apache-ant
9.9M    /opt/apache-maven
2.4G    /opt/archives
2.2M    /opt/cfr-0.152
36M     /opt/flix-0.43.0
51M     /opt/git
129M    /opt/gradle
308M    /opt/jdk-11.0.21_9
103M    /opt/ktlint
61M     /opt/mill
81M     /opt/sbt
25M     /opt/scala-2.13.12
36M     /opt/scala3-3.3.2-RC1
15M     /opt/wabt-1.0.23

And finally we build and run one of our Scala code examples, for instance enum-Planet, with either a Bash script, a Ant script, a Gradle script or a Make script :

$ cd examples/enum-Planet/
$ ./build.sh -verbose clean run
Delete directory "target"
Compile 1 Scala source files to directory "target/classes"
Execute Scala main class "Planet"
Mass of earth is 0.1020132025669991
Your weight on MERCURY (0) is 0.37775761520093526
Your weight on VENUS (1) is 0.9049990998410455
Your weight on EARTH (2) is 0.9999999999999999
Your weight on MARS (3) is 0.37873718403712886
Your weight on JUPITER (4) is 2.5305575254957406
Your weight on SATURN (5) is 1.0660155388115666
Your weight on URANUS (6) is 0.9051271993894251
Your weight on NEPTUNE (7) is 1.1383280724696578
 
$ ant clean run 2>/dev/null | awk '/^run:$/{n=1}{if(n==1)print}'
run:
     [java] Mass of earth is 0.1020132025669991
     [java] Your weight on MERCURY (0) is 0.37775761520093526
     [java] Your weight on VENUS (1) is 0.9049990998410455
     [java] Your weight on EARTH (2) is 0.9999999999999999
     [java] Your weight on MARS (3) is 0.37873718403712886
     [java] Your weight on JUPITER (4) is 2.5305575254957406
     [java] Your weight on SATURN (5) is 1.0660155388115666
     [java] Your weight on URANUS (6) is 0.9051271993894251
     [java] Your weight on NEPTUNE (7) is 1.1383280724696578
 
BUILD SUCCESSFUL
Total time: 9 seconds
 
$ gradle -q clean run
Mass of earth is 0.1020132025669991
Your weight on MERCURY (0) is 0.37775761520093526
Your weight on VENUS (1) is 0.9049990998410455
Your weight on EARTH (2) is 0.9999999999999999
Your weight on MARS (3) is 0.37873718403712886
Your weight on JUPITER (4) is 2.5305575254957406
Your weight on SATURN (5) is 1.0660155388115666
Your weight on URANUS (6) is 0.9051271993894251
Your weight on NEPTUNE (7) is 1.1383280724696578
 
$ make clean run
rm -rf "target"
[ -d "target/classes" ] || "mkdir" -p "target/classes"
"/opt/scala3-3.3.2-RC1/bin/scalac" "@target/scalac_opts.txt" "@target/scalac_sources.txt"
"/opt/scala3-3.3.2-RC1/bin/scala" -classpath "target/classes" Planet 1
Mass of earth is 0.1020132025669991
Your weight on MERCURY (0) is 0.37775761520093526
Your weight on VENUS (1) is 0.9049990998410455
Your weight on EARTH (2) is 0.9999999999999999
Your weight on MARS (3) is 0.37873718403712886
Your weight on JUPITER (4) is 2.5305575254957406
Your weight on SATURN (5) is 1.0660155388115666
Your weight on URANUS (6) is 0.9051271993894251
Your weight on NEPTUNE (7) is 1.1383280724696578

Footnotes

[1] Updating our packages with apt

We run command apt to keep the packages of our Ubuntu WSL installation up-to-date :
$ uname -a
Linux DESKTOP-U9DCNVQ 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ sudo apt update
[sudo] password for michelou:
Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease
Get:2 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]
[...]]
Get:23 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [18.1 kB]
Get:24 http://archive.ubuntu.com/ubuntu bionic-backports/universe Translation-en [8668 B]
Fetched 12.6 MB in 12s (1085 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
153 packages can be upgraded. Run 'apt list --upgradable' to see them.
$ sudo apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
  dbus-user-session
The following packages will be upgraded:
  apport bash bind9-host ca-certificates cloud-init cron curl
  [...]
  vim-runtime vim-tiny xxd xz-utils zlib1g zlib1g-dev
153 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
127 standard security updates
Need to get 419 MB of archives.
After this operation, 60.2 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 bash amd64 4.4.18-2ubuntu1.3 [615 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libc6-dev amd64 2.27-3ubuntu1.6 [2587 kB]
[...]
Get:152 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 unzip amd64 6.0-21ubuntu1.2 [168 kB]
Get:153 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 cloud-init all 22.3.4-0ubuntu1~18.04.1 [510 kB]
Get:154 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 open-vm-tools amd64 2:11.0.5-4ubuntu0.18.04.2 [543 kB]
Fetched 419 MB in 5min 46s (1212 kB/s)
Extracting templates from packages: 100%
Preconfiguring packages ...
(Reading database ... 63334 files and directories currently installed.)
Preparing to unpack .../bash_4.4.18-2ubuntu1.3_amd64.deb ...
Unpacking bash (4.4.18-2ubuntu1.3) over (4.4.18-2ubuntu1.2) ...
Setting up bash (4.4.18-2ubuntu1.3) ...
[...]
Setting up libisccfg160:amd64 (1:9.11.3+dfsg-1ubuntu1.18) ...
Setting up snapd (2.57.5+18.04) ...
Installing new version of config file /etc/apparmor.d/usr.lib.snapd.snap-confine.real ...
Installing new version of config file /etc/profile.d/apps-bin-path.sh ...
Created symlink /etc/systemd/system/multi-user.target.wants/snapd.aa-prompt-listener.service → /lib/systemd/system/snapd.aa-prompt-listener.service.
Setting up dpkg-dev (1.19.0.5ubuntu2.4) ...
Processing triggers for mime-support (3.60ubuntu1) ...
Processing triggers for ureadahead (0.100.0-21) ...
Running hooks in /etc/ca-certificates/update.d...1-2) ...1) ...
Processing triggers for initramfs-tools (0.130ubuntu3.13) ...
done.ssing triggers for ca-certificates (20211016~18.04.1) ...
done.ing certificates in /etc/ssl/certs.../cloud/cloud.cfg ...

[2] Modifying our Ant installation

$ sudo cp /mnt/c/opt/apache-ant/lib/ivy-2.5.2.jar /opt/apache-ant/lib/

mics/December 2024