Skip to content

Commit

Permalink
Merge pull request #427 from armanbilge/feature/native
Browse files Browse the repository at this point in the history
Cross-build for Native
  • Loading branch information
mpilquist authored Sep 15, 2022
2 parents eeb2cdb + 9b64841 commit a2e1515
Show file tree
Hide file tree
Showing 13 changed files with 304 additions and 22 deletions.
56 changes: 45 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.16, 2.13.8, 3.2.0]
scala: [2.12.16, 2.13.8, 3.1.3]
java: [temurin@8]
project: [rootJS, rootJVM]
project: [rootJS, rootJVM, rootNative]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
Expand Down Expand Up @@ -77,6 +77,10 @@ jobs:
if: matrix.project == 'rootJS'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' Test/scalaJSLinkerResult

- name: nativeLink
if: matrix.project == 'rootNative'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' Test/nativeLink

- name: Test
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' test

Expand All @@ -90,11 +94,11 @@ jobs:

- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: mkdir -p target .js/target test-kit/js/target js/target test-kit/jvm/target jvm/target .jvm/target .native/target project/target
run: mkdir -p target .js/target native/target test-kit/js/target js/target test-kit/native/target test-kit/jvm/target jvm/target .jvm/target .native/target project/target

- name: Compress target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: tar cf targets.tar target .js/target test-kit/js/target js/target test-kit/jvm/target jvm/target .jvm/target .native/target project/target
run: tar cf targets.tar target .js/target native/target test-kit/js/target js/target test-kit/native/target test-kit/jvm/target jvm/target .jvm/target .native/target project/target

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
Expand All @@ -110,7 +114,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [3.2.0]
scala: [3.1.3]
java: [temurin@8]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -167,6 +171,16 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (2.12.16, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.16-rootNative

- name: Inflate target directories (2.12.16, rootNative)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (2.13.8, rootJS)
uses: actions/download-artifact@v2
with:
Expand All @@ -187,22 +201,42 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.2.0, rootJS)
- name: Download target directories (2.13.8, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.8-rootNative

- name: Inflate target directories (2.13.8, rootNative)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.1.3, rootJS)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.1.3-rootJS

- name: Inflate target directories (3.1.3, rootJS)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.1.3, rootJVM)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.2.0-rootJS
name: target-${{ matrix.os }}-${{ matrix.java }}-3.1.3-rootJVM

- name: Inflate target directories (3.2.0, rootJS)
- name: Inflate target directories (3.1.3, rootJVM)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.2.0, rootJVM)
- name: Download target directories (3.1.3, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.2.0-rootJVM
name: target-${{ matrix.os }}-${{ matrix.java }}-3.1.3-rootNative

- name: Inflate target directories (3.2.0, rootJVM)
- name: Inflate target directories (3.1.3, rootNative)
run: |
tar xf targets.tar
rm targets.tar
Expand Down
49 changes: 48 additions & 1 deletion NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,51 @@ http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
This product includes software developed at Comcast (http://www.comcast.com/).

This product includes a dependency on [punycode.js](https://github.com/bestiejs/punycode.js), which is available under the MIT license.
This product includes a dependency on and sources derived from [punycode.js](https://github.com/mathiasbynens/punycode.js), which is available under the following MIT license.

```
Copyright Mathias Bynens <https://mathiasbynens.be/>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```

This product includes sources derived from [libuv](https://github.com/libuv/libuv/), which is available under the following license.

```
Copyright (c) 2015-present libuv project contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
```
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[![Published Artifact](https://img.shields.io/maven-central/v/com.comcast/ip4s-core_3.svg)](http://search.maven.org/#search%7Cga%7C1%7Cip4s-core_3)
[![javadoc](https://javadoc.io/badge2/com.comcast/ip4s-core_3/javadoc.svg)](https://javadoc.io/doc/com.comcast/ip4s-core_3)

ip4s: IP Addresses for Scala & Scala.js
=======================================
ip4s: IP Addresses for Scala, Scala.js & Scala Native
=====================================================

This project defines immutable, safe data structures for describing IP addresses, multicast joins, socket addresses and similar IP & network related data types.

There are two defining characteristics of this project that make it different from other similar projects:
- all data types are immutable and every function/method is referentially transparent (e.g., no accidental DNS lookups by calling `InetAddress.getByName(...)`)
- published for both Scala and Scala.js
- published for Scala, Scala.js and Scala Native

See the [guide](docs/guide.md) and [ScalaDoc](https://javadoc.io/doc/com.comcast/ip4s-core_3) for more details.

Expand Down
30 changes: 23 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ThisBuild / developers ++= List(

ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("8"))

ThisBuild / crossScalaVersions := List("2.12.16", "2.13.8", "3.2.0")
ThisBuild / crossScalaVersions := List("2.12.16", "2.13.8", "3.1.3")

ThisBuild / tlVersionIntroduced := Map("3" -> "3.0.3")

Expand All @@ -35,7 +35,7 @@ ThisBuild / mimaBinaryIssueFilters ++= Seq(

lazy val root = tlCrossRootProject.aggregate(core, testKit)

lazy val testKit = crossProject(JVMPlatform, JSPlatform)
lazy val testKit = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.in(file("./test-kit"))
.settings(commonSettings)
.settings(
Expand All @@ -45,9 +45,9 @@ lazy val testKit = crossProject(JVMPlatform, JSPlatform)
.settings(
libraryDependencies ++= Seq(
"org.scalacheck" %%% "scalacheck" % "1.16.0",
"org.scalameta" %%% "munit-scalacheck" % "0.7.29" % Test,
"org.scalameta" %%% "munit-scalacheck" % "1.0.0-M6" % Test,
"org.typelevel" %%% "cats-effect" % "3.3.14" % Test,
"org.typelevel" %%% "munit-cats-effect-3" % "1.0.7" % Test
"org.typelevel" %%% "munit-cats-effect" % "2.0.0-M3" % Test
)
)
.jvmSettings(
Expand All @@ -59,8 +59,11 @@ lazy val testKitJVM = testKit.jvm
lazy val testKitJS = testKit.js
.disablePlugins(DoctestPlugin)
.enablePlugins(ScalaJSBundlerPlugin)
lazy val testKitNative = testKit.js
.disablePlugins(DoctestPlugin)
.settings(commonNativeSettings)

lazy val core = crossProject(JVMPlatform, JSPlatform)
lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.in(file("."))
.settings(commonSettings)
.settings(
Expand All @@ -79,6 +82,11 @@ lazy val core = crossProject(JVMPlatform, JSPlatform)
"org.scalacheck" %%% "scalacheck" % "1.16.0" % Test
)
)
.nativeSettings(
libraryDependencies ++= Seq(
"org.typelevel" %%% "idna4s-core" % "0.0.1"
)
)

lazy val coreJVM = core.jvm.settings(
doctestIgnoreRegex := Some(".*Literals.scala")
Expand All @@ -88,10 +96,14 @@ lazy val coreJS = core.js
.disablePlugins(DoctestPlugin)
.enablePlugins(ScalaJSBundlerPlugin)
.settings(
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
Compile / npmDependencies += "punycode" -> "2.1.1"
Compile / npmDependencies += "punycode" -> "2.1.1",
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule))
)

lazy val coreNative = core.native
.disablePlugins(DoctestPlugin)
.settings(commonNativeSettings)

lazy val docs = project
.in(file("docs"))
.enablePlugins(MdocPlugin)
Expand All @@ -109,3 +121,7 @@ lazy val commonSettings = Seq(
(base / "NOTICE") +: (base / "LICENSE") +: (base / "CONTRIBUTING") +: ((base / "licenses") * "LICENSE_*").get
}
)

lazy val commonNativeSettings = Seq(
tlVersionIntroduced := List("2.12", "2.13", "3").map(_ -> "3.1.4").toMap
)
47 changes: 47 additions & 0 deletions native/src/main/scala/com/comcast/ip4s/IDNCompanionPlatform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2018 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.comcast.ip4s

import org.typelevel.idna4s.core.bootstring.Bootstring
import org.typelevel.idna4s.core.bootstring.BootstringParams.PunycodeParams
import cats.syntax.all._

private[ip4s] trait IDNCompanionPlatform {

private[this] val DotPattern = "[\u002e\u3002\uff0e\uff61]".r.pattern

private[ip4s] def toAscii(value: String): Option[String] =
DotPattern
.split(value, -1)
.toList
.traverse { label =>
if (label.forall(_ < 128)) Some(label)
else Bootstring.encodeRaw(PunycodeParams)(label).toOption.map("xn--" + _)
}
.map(_.mkString("."))

private[ip4s] def toUnicode(value: String): String =
DotPattern
.split(value, -1)
.toList
.traverse { label =>
if (label.startsWith("xn--")) Bootstring.decodeRaw(PunycodeParams)(label.substring(4, label.length))
else Right(label)
}
.map(_.mkString("."))
.fold(e => throw new IllegalArgumentException(e), identity[String](_))
}
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.4.13")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.1")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.7")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.2.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.21.0")
addSbtPlugin("com.github.tkawachi" % "sbt-doctest" % "0.10.0")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.3")
Loading

0 comments on commit a2e1515

Please sign in to comment.