KS project consists of several subprojects, each of which has its own repository:
-
compiler — everything starts here, this is the core of the project that everything uses
-
tests — used to prove that compiler behaves as expected and there are no regressions introduced by the changes
-
runtimes, one per each target language — used by the code generated by a compiler
-
documentation — keeps users informed about the language and all new features
Technically, one can download and work with each of these subprojects individually, but most people just download everything by checking out our main umbrella project that includes (almost) everything:
git clone --recursive https://github.com/kaitai-io/kaitai_struct.git
Note the --recursive
option, which would download all the
submodules. If you forgot it and cloned without it, you can still do
it manually after cloning:
git submodule update --init --recursive
KS compiler is written in Scala language and 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
.class
files, 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
.js
file, 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
-
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://dl.bintray.com/sbt/debian /" | sudo tee -a /etc/apt/sources.list.d/sbt.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823
sudo apt-get update
sudo apt-get install sbt
Manual 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.
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=3128
Unfortunately, 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 sbt
run all dependencies will be downloaded and access to the internet not required anymore.
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.
-
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
-
-
sbt compilerJVM/debian:packageBin
-
Get result in
jvm/target/kaitai-struct-compiler_*_all.deb
-
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 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
-
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 $VERSION
-
git 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
-
-
-
Publish them all
-
Verify that one has OSS Sonatype login/password for
iokaitai
org. -
Preliminary setup (needs to be done once per machine — verified for sbt 1.1)
-
Set up credentials: create
$HOME/.sbt/.credentials
with 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.sbt
with the following contents:credentials += Credentials(Path.userHome / ".sbt" / ".credentials")
-
Make sure GPG keys are present
-
-
sbt publishSigned
-
Continue to follow Java runtime publishing instructions
-
Pump version, set version to
$VERSION
, without-SNAPSHOT
-
mvn deploy
-
Scroll to the very end of list, seek
iokaitai-…
repositories -
Select our staging repository
-
Press "Close" toolbar button
-
Confirm
-
Wait for checks to complete
-
-
Press "Release" toolbar button
-
Enter release message
-
Confirm
-
-
After some time, check https://search.maven.org/#search%7Cga%7C1%7Ca%3A%22kaitai-struct-runtime%22 to have new version
-
Pump version in
package.json
andpackage-lock.json
(search for"version":
) toX.Y.Z
format (e.g.0.9.0
for 0.9 release) -
Make a commit with the changes and tag it
$VERSION
-
npm login
- fill npmjs.org login credentials -
npm publish --tag latest
-
Install/update the needed Python packaging tools:
python3 -m pip install --upgrade setuptools twine wheel
-
If this gives you permission errors, don’t use
sudo
to runpip
. Instead use your system package manager (e. g.apt
) to install/update the tools, or add the--user
option topip install
.
-
-
Pump version in
kaitaistruct.py
, seek__version__ =
-
Delete the
dist
directory (if it exists), so that built files from previous or development versions don’t get uploaded by accident. -
python3 setup.py sdist bdist_wheel
-
twine check dist/*
-
twine upload dist/*
-
This will prompt for your PyPI credentials. See the Twine docs for info on how to preset/permanently configure the credentials.
-
To upload to TestPyPI instead:
twine upload --repository=testpypi dist/*
-
-
Check that new version appears under https://pypi.org/project/kaitaistruct/#history
-
git tag $VERSION
-
git push origin $VERSION
-
Pump version in
lib/kaitai/struct/struct.rb
, seek `VERSION = ` -
gem build kaitai-struct.gemspec
-
Test gem (i.e. by installing it to a live system)
-
gem push kaitai-struct-$VERSION.gem
-
git tag $VERSION
-
git push --tags
-
Pump versions in
kaitai_struct_runtime_csharp.csproj
, commit and put$VERSION
tag on it -
dotnet build
-
dotnet pack
→ get resulting.nupkg
file inbin/Debug/
folder -
Create API key on https://www.nuget.org/account/apikeys
-
dotnet nuget push bin/Debug/*.nupkg -k <API key> -s https://api.nuget.org/v3/index.json
Overall routine for adding new language is described in Adding support for new target language.
After addition, don’t forget to update lists of languages:
-
/build.sbt - supportedLanguages
-
https://github.com/kaitai-io/kaitai_struct — project description
-
https://github.com/kaitai-io/kaitai_struct_compiler — project description
-
https://github.com/kaitai-io/kaitai_struct_compiler/blob/master/README.md —
-t
option documentation -
http://kaitai.io — everywhere
-
https://bintray.com/kaitai-io/debian/kaitai-struct-compiler/view — package description
-
https://twitter.com/kaitai_io — profile