Developers memo (original) (raw)
KS compiler is written in Scala languageand thus uses SBT for building. It can be compiled in one of 2 ways, each of which can be packaged in one of several ways:
- generating Java
.classfiles, to be run in JVM- not packaged, ready to be ran from a build dir (so called "stage build")
- packaged as universal (.zip) package
- packaged as Debian (.deb) package
- packaged as Windows (.msi) installer package
- generating JavaScript
.jsfile, to be run either inside a browser or in node.js environment- not packaged, used as a source JS file on a website
- packaged as npm package
Prerequisites
To build the compiler, one generally needs just these two things:
- Java Runtime Environment (JRE)
- Scala Build Tool (sbt)
For Debian/Ubuntu, this should be enough to download every prerequisite (JRE is pulled automatically by sbt):
echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | sudo tee /etc/apt/sources.list.d/sbt.list
echo "deb https://repo.scala-sbt.org/scalasbt/debian /" | sudo tee /etc/apt/sources.list.d/sbt_old.list
curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | sudo apt-key add
sudo apt-get update
sudo apt-get install sbtFor RedHat-based systems, use the following:
curl -L https://www.scala-sbt.org/sbt-rpm.repo > sbt-rpm.repo
sudo mv sbt-rpm.repo /etc/yum.repos.d/
sudo yum install sbtManual installation:
| Note | You don’t need whole Java Development Kit (JDK), unless you want to test & develop for Java target — just JRE is enough for KS compiler. |
|---|
All other dependencies (including Scala runtimes, compilers, etc) required for the compiler are downloaded and installed by sbt automatically. It shouldn’t really matter even which version of sbt you use for bootstrap, as sbt will pull relevant sbt update packages automatically as well.
Configuring proxy
Note, that if you behind proxy, you need to run sbt with flags
-Dhttp.proxyHost=<your proxy server>
-Dhttp.proxyPort=<your proxy server port>
-Dhttps.proxyHost=<your proxy server>
-Dhttps.proxyPort=<your proxy server port>For example
sbt -Dhttp.proxyHost=proxy.com -Dhttp.proxyPort=3128 -Dhttps.proxyHost=proxy.com -Dhttps.proxyPort=3128Unfortunately, sbt doesn’t understand http(s)_proxy environment variable properly, if it contains address of proxy server in host:port format, so flags is necessary.
This flags needed only on first run or when you want to check and upgrade dependencies. After first sbtrun all dependencies will be downloaded and access to the internet not required anymore.
Building for JVM
We use sbt-native-packager to build deployable formats. Note that in order to perform the following builds, one must be in the kaitai_struct/compiler directory.
Building an universal (.zip) package
sbt compilerJVM/universal:packageBin- Get result in
jvm/target/universal/kaitai-struct-compiler-*.zip
Building Debian package
- Install prerequisites:
- On Debian/Ubuntu host:
sudo -i apt-get install dpkg dpkg-sig dpkg-dev lintian fakeroot - On RedHat host:
sudo dnf install dpkg fakeroot
- On Debian/Ubuntu host:
sbt compilerJVM/debian:packageBin- Get result in
jvm/target/kaitai-struct-compiler_*_all.deb
Building RedHat package
- Install prerequisites:
- On RedHat host:
sudo dnf install rpm rpm-build
- On RedHat host:
sbt compilerJVM/rpm:packageBin- Get result in
jvm/target/rpm/RPMS/noarch/kaitai-struct-compiler-*.noarch.rpm
Building Windows package
- Install WIX
sbt compilerJVM/windows:packageBin- Get result in
jvm/target/windows/kaitai-struct-compiler.msi - Rename to add version to
kaitai-struct-compiler-$VERSION.msi
Building for JavaScript platform
Building to JavaScript platform is done using a Scala.js project. Note that it uses a somewhat different set of dependencies, as they must actually be JavaScript libraries, not Java jars.
- Run
sbt fastOptJS - Get result in
js/target/scala-2.11/kaitai-struct-compiler-fastopt.js - Use this JavaScript file on a website
Publishing a new version
- Choose a new version number (WIX imposes harsh requirements for version to look like
x.x.x.x) and update it inbuild.sbt,version := …, commit - Prepare an entry in RELEASE_NOTES.md, commit
- Create version tag:
git tag $VERSIONgit push --tags
- Update main repository
- Create new version at:
- Upload:
- https://bintray.com/kaitai-io/debian/kaitai-struct-compiler/$VERSION/upload
* Debian distribution:jessie
* Debian component:main
* Debian architecture:all
* Attached file:jvm/target/kaitai-struct-compiler_*_all.deb - https://bintray.com/kaitai-io/universal/kaitai-struct-compiler/$VERSION/upload
* Target path:$VERSION
* Attached file:jvm/target/universal/kaitai-struct-compiler-*.zip - https://bintray.com/kaitai-io/universal/kaitai-struct-compiler/$VERSION/upload
* Target path:$VERSION
* Attached file:jvm/target/windows/kaitai-struct-compiler-*.msi
- https://bintray.com/kaitai-io/debian/kaitai-struct-compiler/$VERSION/upload
- Publish them all
Publishing new version to oss.sonatype.org
- Verify that one has OSS Sonatype login/password for
iokaitaiorg. - Preliminary setup (needs to be done once per machine — verified for sbt 1.1)
- Enable the sbt-pgp plugin globally by adding this line to
~/.sbt/1.0/plugins/gpg.sbt:
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")- Set up credentials: create
$HOME/.sbt/.credentialswith the following contents (replacing XXX with username and password):
realm=Sonatype Nexus Repository Manager
host=oss.sonatype.org
user=XXX
password=XXX - Set up
$HOME/.sbt/1.0/plugins/credentials.sbtwith the following contents:
credentials += Credentials(Path.userHome / ".sbt" / ".credentials")- For publishing the Java runtime library: set up
~/.m2/settings.xmlwith the following contents:
<settings> <servers> <server> <id>ossrh</id> <username>XXX</username> <password>XXX</password> </server> </servers> </settings>- Make sure GPG keys are present
- Enable the sbt-pgp plugin globally by adding this line to
sbt publishSigned- Go to https://oss.sonatype.org/#stagingRepositories
- Continue to follow Java runtime publishing instructions