|
| 1 | +--- |
| 2 | +layout: blog |
| 3 | +post-type: blog |
| 4 | +by: Martin Duhem, Guillaume Massé and Denys Shabalin |
| 5 | +title: "What's new with Scala Native?" |
| 6 | +--- |
| 7 | + |
| 8 | +It has been a little bit more than two months since Scala Native 0.1 has been |
| 9 | +released. What's new in Scala Native? What should you expect for future |
| 10 | +releases? |
| 11 | + |
| 12 | +## Scala Native 0.2 |
| 13 | + |
| 14 | +In April, [Scala Native 0.2 was released][scala-native-0.2-release]. The main |
| 15 | +focus of this release was to increase the coverage of classes from |
| 16 | +the JDK, such that that more programs can be ported to Scala Native without any further |
| 17 | +effort. |
| 18 | + |
| 19 | +### Improvements to the standard library |
| 20 | + |
| 21 | +* Support for file I/O APIs from `java.io` was added by [@Duhemm][@Duhemm] |
| 22 | + from the Scala Center with help from [@cedricviaccoz][@cedricviaccoz] and |
| 23 | + [@Korf74][@Korf74] in [#574][#574]. Scala Native now supports enough to read |
| 24 | + and write files. |
| 25 | + |
| 26 | + ```scala |
| 27 | + import java.io.{DataInputStream, File, FileInputStream} |
| 28 | + val fis = new FileInputStream(new File("hello.txt")) |
| 29 | + val dis = new DataInputStream(fis) |
| 30 | + println(dis.readLine()) |
| 31 | + ``` |
| 32 | + |
| 33 | +* In [#588][#588], [@MasseGuillaume] from the Scala Center added support for |
| 34 | + regular expressions. This implementation relies on Google's RE2 engine and |
| 35 | + [uses a syntax slightly different from the JDK][scala-native-doc-regular-expressions]. |
| 36 | + |
| 37 | + ```scala |
| 38 | + import java.io.{DataInputStream, File, FileInputStream} |
| 39 | + val fis = new FileInputStream(new File("hello.txt")) |
| 40 | + val dis = new DataInputStream(fis) |
| 41 | + println(dis.readLine()) |
| 42 | + ``` |
| 43 | + |
| 44 | +* [@densh][@densh] added initial support for Scala's Futures in [#618][#618], |
| 45 | + using an implementation similar to that of Scala.js, where Futures will be |
| 46 | + completed after the `main` method is executed. |
| 47 | + |
| 48 | + ```scala |
| 49 | + import java.util.concurrent.Future |
| 50 | + import scala.concurrent.ExecutionContext.Implicits.global |
| 51 | + |
| 52 | + object Test { |
| 53 | + def main(args: Array[String]): Unit = { |
| 54 | + println("Start") |
| 55 | + Future { |
| 56 | + println("Hello from the Future") |
| 57 | + }.foreach(_ => ()) |
| 58 | + println("End") |
| 59 | + } |
| 60 | + } |
| 61 | + ``` |
| 62 | + |
| 63 | +* Scala Native now supports pointer subtraction. This work has been |
| 64 | + contributed by [@jonas][@jonas] in [#624][#624]. |
| 65 | + |
| 66 | + ```scala |
| 67 | + val carr: Ptr[CChar] = toCString("abcdefg") |
| 68 | + val cptr: Ptr[CChar] = string.strchr(carr, 'd') |
| 69 | + println(cptr - carr) // prints '3' |
| 70 | + ``` |
| 71 | + |
| 72 | +* [@ekrich][@ekrich] extended Scala Native's implementation of `String` to |
| 73 | + support `toUpperCase` and `toLowerCase` in [#573][#573]. |
| 74 | +* The implementation of `java.lang.Character` was extended to support |
| 75 | + `Character.Subset` and `Character.UnicodeBlock` by [@densh][@densh] in |
| 76 | + [#651][#651]. |
| 77 | +* [@asoltysik][@asoltysik] implemented support for system properties in |
| 78 | + [#591][#591]. |
| 79 | + |
| 80 | + ```scala |
| 81 | + println(System.getProperty("java.version")) // prints '1.8' |
| 82 | + println(System.getProperty("file.separator")) // '\' on Windows, |
| 83 | + // '/' elsewhere |
| 84 | + ``` |
| 85 | +* Scala Native can now read environment variables using `System.getEnv`, |
| 86 | + thanks to [@jonas][@jonas]' efforts in [#606][#606]. |
| 87 | +* `stdin` and `stdout` can reliably be read from and written to, thanks to |
| 88 | + [@fduraffourg][@fduraffourg] and [@densh][@densh] in [#622][#622] and |
| 89 | + [#659][#659]. |
| 90 | + |
| 91 | +### Bugfixes |
| 92 | + |
| 93 | +* A bugfix has been contributed by [@jonas][@jonas] to `String.replace`, |
| 94 | + fixing one broken benchmark at the same time. His work can be found in |
| 95 | + [#616][#616]. |
| 96 | +* `System.nanoTime` was fixed by [@brad-rathke][@brad-rathke] in [#549][#549]. |
| 97 | +* [@xuwei-k][@xuwei-k] fixed `nativeAvailableDependencies` which didn't work |
| 98 | + in the `test` configuration in [#565][#565]. |
| 99 | + |
| 100 | +### Improvements to the tooling and integration |
| 101 | + |
| 102 | +* [@MasseGuillaume][@MasseGuillaume] and [@densh][@densh] |
| 103 | + worked on refactoring Scala Native's sbt plugin to make it more idiomatic in |
| 104 | + [#568][#568] and [#630][#630], which lead to fixing [#562][#562]. |
| 105 | +* Follow up fixes were contributed by [@jonas][@jonas], and include [#639][#639] |
| 106 | + and [#653][#653]. |
| 107 | + |
| 108 | +### Preparing for a better garbage collector |
| 109 | + |
| 110 | +In this release, [@LukasKellenberger][@LukasKellenberger] introduced in |
| 111 | +[#539][#539] a new setting in the sbt plugin that lets users select what |
| 112 | +implementation of the garbage collector should be used. Currently, BoehGC |
| 113 | +and no GC are supported. |
| 114 | + |
| 115 | +This work was done in preparation for [the improved GC that will be shipped |
| 116 | +with Scala Native 0.3][#726]! |
| 117 | + |
| 118 | + |
| 119 | +## A community effort |
| 120 | + |
| 121 | +As shown, many of the improvements that were brought by Scala Native 0.2 have |
| 122 | +been contributed by members of the vibrant community that is developing itself |
| 123 | +around Scala Native. Thank you! |
| 124 | + |
| 125 | +The combination of these improvements was enough to get a prototype of |
| 126 | +`scalafmt` running on Scala Native by [@olafurpg][@olafurpg], showing a blazing |
| 127 | +fast startup time! |
| 128 | + |
| 129 | +<blockquote class="twitter-tweet" data-conversation="none" data-lang="en"> |
| 130 | + <p lang="en" dir="ltr"> |
| 131 | + <a href="https://twitter.com/adriaanm">@adriaanm</a> |
| 132 | + <a href="https://twitter.com/den_sh">@den_sh</a> |
| 133 | + <a href="https://twitter.com/scala_native">@scala_native</a> OMG IT WORKS :D 30x faster! |
| 134 | + <a href="https://t.co/M7V9udU5bT">pic.twitter.com/M7V9udU5bT</a> |
| 135 | + </p> |
| 136 | + — Ólafur Páll Geirsson (@olafurpg) |
| 137 | + <a href="https://twitter.com/olafurpg/status/857559907876433920">April 27, 2017</a> |
| 138 | +</blockquote> |
| 139 | +<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script> |
| 140 | + |
| 141 | +## What to expect for Scala Native 0.3? |
| 142 | + |
| 143 | +The plans for the next release of Scala Native include a new garbage collector, |
| 144 | +a better integration with sbt and more addition to the standard library. |
| 145 | + |
| 146 | +### Improved garbage collector |
| 147 | + |
| 148 | +The first releases of Scala Native use Boehm GC. A new and improved garbage |
| 149 | +collector has been under development by [@LukasKellenberger][@LukasKellenberger] |
| 150 | +and will be presented at Scala Days during Denys' talk. Stay tuned! |
| 151 | + |
| 152 | +The pull request introducing the new garbage collector can be found in |
| 153 | +[#726][#726]. |
| 154 | + |
| 155 | +### Running tests from sbt |
| 156 | + |
| 157 | +Currently, testing frameworks such as utest or scalacheck cannot be used with |
| 158 | +Scala Native. An effort to enable support for sbt-compatible testing |
| 159 | +frameworks has been undertaken by [@Duhemm][@Duhemm] from the Scala Center and |
| 160 | +is expected to land in Scala Native's third release. |
| 161 | + |
| 162 | +### Support for `java.nio`, `java.util.{jar, zip}` |
| 163 | + |
| 164 | +The existing I/O capabilities of Scala Native have been extended in this |
| 165 | +release by adding support for the classes defined in the packages `java.nio`, |
| 166 | +`java.util.jar` and `java.util.zip`. |
| 167 | + |
| 168 | +### Smaller binaries |
| 169 | + |
| 170 | +In [#686][#686], [@densh][@densh] started work to reduce the size of the |
| 171 | +binaries compiled by Scala Native, using a technique called selector-based |
| 172 | +row displacement. |
| 173 | + |
| 174 | +These improvements make the dispatch table 10 times smaller. |
| 175 | + |
| 176 | +## 0.4 and beyond |
| 177 | + |
| 178 | +Some features are already in the works for Scala Native 0.4. |
| 179 | + |
| 180 | +### Windows support |
| 181 | + |
| 182 | +[@muxanick][@muxanick] has been working on a port of Scala Native to Windows. |
| 183 | +The advancement of his work can be consulted in [#691][#691]. |
| 184 | + |
| 185 | +### Automatic binding generation |
| 186 | + |
| 187 | +A prototype of [automatic binding generation][#642] is in development by |
| 188 | +[@jonas][@jonas]. The goal is to be able to generate automatically bindings |
| 189 | +for C libraries. For instance, given the following C header `test.h`: |
| 190 | + |
| 191 | +```C |
| 192 | +enum color { |
| 193 | + RED = 1, |
| 194 | + GREEN, |
| 195 | + BLUE = 100 |
| 196 | +}; |
| 197 | +typedef int SomeInt; |
| 198 | +char *strchr(const char *s, int c); |
| 199 | +``` |
| 200 | +
|
| 201 | +We want to generate the following definitions: |
| 202 | +
|
| 203 | +```scala |
| 204 | +@extern |
| 205 | +object Test { |
| 206 | + object color { |
| 207 | + val RED = 1 |
| 208 | + val GREEN = 2 |
| 209 | + val BLUE = 100 |
| 210 | + } |
| 211 | + type SomeInt = CInt |
| 212 | + def strchr(s: CString, c: CInt): CString = extern |
| 213 | +} |
| 214 | +``` |
| 215 | + |
| 216 | +Ultimately, this tool will make it much easier to providing bindings for C's |
| 217 | +stdlib and external libraries. |
| 218 | + |
| 219 | +[scala-native-0.2-release]: https://github.com/scala-native/scala-native/releases/tag/v0.2.0 |
| 220 | +[@asoltysik]: https://github.com/asoltysik |
| 221 | +[@brad-rathke]: https://github.com/brad-rathke |
| 222 | +[@cedricviaccoz]: https://github.com/cedricviaccoz |
| 223 | +[@densh]: https://github.com/densh |
| 224 | +[@Duhemm]: https://github.com/Duhemm |
| 225 | +[@ekrich]: https://github.com/ekrich |
| 226 | +[@fduraffourg]: https://github.com/fduraffourg |
| 227 | +[@jonas]: https://github.com/jonas |
| 228 | +[@Korf74]: https://github.com/Korf74 |
| 229 | +[@LukasKellenberger]: https://github.com/LukasKellenberger |
| 230 | +[@MasseGuillaume]: https://github.com/MasseGuillaume |
| 231 | +[@muxanick]: https://github.com/muxanick |
| 232 | +[@olafurpg]: https://github.com/olafurpg |
| 233 | +[@xuwei-k]: https://github.com/xuwei-k |
| 234 | + |
| 235 | +[scala-native-doc-regular-expressions]: http://scala-native.readthedocs.io/en/latest/lib/javalib.html?highlight=regex#regular-expressions-java-util-regex |
| 236 | + |
| 237 | +[#539]: https://github.com/scala-native/scala-native/pull/539 |
| 238 | +[#549]: https://github.com/scala-native/scala-native/pull/549 |
| 239 | +[#562]: https://github.com/scala-native/scala-native/pull/562 |
| 240 | +[#565]: https://github.com/scala-native/scala-native/pull/565 |
| 241 | +[#568]: https://github.com/scala-native/scala-native/pull/568 |
| 242 | +[#573]: https://github.com/scala-native/scala-native/pull/573 |
| 243 | +[#574]: https://github.com/scala-native/scala-native/pull/574 |
| 244 | +[#588]: https://github.com/scala-native/scala-native/pull/588 |
| 245 | +[#591]: https://github.com/scala-native/scala-native/pull/591 |
| 246 | +[#606]: https://github.com/scala-native/scala-native/pull/606 |
| 247 | +[#616]: https://github.com/scala-native/scala-native/pull/616 |
| 248 | +[#618]: https://github.com/scala-native/scala-native/pull/618 |
| 249 | +[#621]: https://github.com/scala-native/scala-native/pull/621 |
| 250 | +[#622]: https://github.com/scala-native/scala-native/pull/621 |
| 251 | +[#624]: https://github.com/scala-native/scala-native/pull/624 |
| 252 | +[#630]: https://github.com/scala-native/scala-native/pull/630 |
| 253 | +[#639]: https://github.com/scala-native/scala-native/pull/639 |
| 254 | +[#642]: https://github.com/scala-native/scala-native/pull/642 |
| 255 | +[#651]: https://github.com/scala-native/scala-native/pull/651 |
| 256 | +[#653]: https://github.com/scala-native/scala-native/pull/653 |
| 257 | +[#659]: https://github.com/scala-native/scala-native/pull/659 |
| 258 | +[#686]: https://github.com/scala-native/scala-native/pull/686 |
| 259 | +[#691]: https://github.com/scala-native/scala-native/pull/691 |
| 260 | +[#726]: https://github.com/scala-native/scal-anative/pull/726 |
0 commit comments