Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cross compile scala 3 #504

Merged
merged 16 commits into from
Jul 3, 2023
Merged

Conversation

i10416
Copy link
Contributor

@i10416 i10416 commented Jun 26, 2023

complete #468

This PR supports cross build of all modules in Scala 3.

The most changes are introduced with the aim of hiding shapeless from shared files in core modules and filling the gap of implicit conversions and implicit defs/vals between scala 2.x and 3.x.

In addition, other changes address Scala 3 compiler/linter warnings.

@i10416 i10416 force-pushed the feat-cross-compile-3 branch from c3d9c9d to a547e16 Compare July 2, 2023 06:39
@i10416
Copy link
Contributor Author

i10416 commented Jul 2, 2023

depends on #506

@i10416 i10416 force-pushed the feat-cross-compile-3 branch from 5b82bdf to 03eb141 Compare July 2, 2023 07:37
@i10416 i10416 changed the title draft: cross compile scala 3 cross compile scala 3 Jul 2, 2023
@i10416 i10416 marked this pull request as ready for review July 2, 2023 08:26
@i10416
Copy link
Contributor Author

i10416 commented Jul 2, 2023

cron4s compiles in Scala 3!

val g = "https://raw.githubusercontent.com/alonsodomin/cron4s/" + tagOrHash
s"-P:scalajs:mapSourceURI:$a->$g/"
},
scalacOptions ++= (if (scalaVersion.value.startsWith("2.")) Seq {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this causes bad option error in scala 3 scala.js: https://github.com/alonsodomin/cron4s/actions/runs/5435520680

implicit lazy val arbitraryBetweenDayOfMonth = Arbitrary(betweenGen[DayOfMonth])
implicit lazy val arbitraryBetweenMonth = Arbitrary(betweenGen[Month])
implicit lazy val arbitraryBetweenDayOfWeek = Arbitrary(betweenGen[DayOfWeek])
implicit lazy val arbitraryBetweenSecond: Arbitrary[BetweenNode[Second]] = Arbitrary(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicit types for implicit vals/defs

@@ -17,17 +17,22 @@
package cron4s.testkit.gen

import cron4s.CronField._
import cron4s.expr.ConstNode

import org.scalacheck.Arbitrary

/**
* Created by alonsodomin on 28/08/2016.
*/
trait ArbitraryConstNode extends NodeGenerators {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicit types for implicit vals/defs

implicit lazy val arbitraryDaysOfMonthUnit = Arbitrary(Gen.const(CronUnit[DayOfMonth]))
implicit lazy val arbitraryMonthsUnit = Arbitrary(Gen.const(CronUnit[Month]))
implicit lazy val arbitraryDaysOfWeekUnit = Arbitrary(Gen.const(CronUnit[DayOfWeek]))
implicit lazy val arbitrarySecondsUnit: Arbitrary[CronUnit[Second]] = Arbitrary(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicit types for implicit vals/defs

),
libraryDependencies ++= (if (scalaVersion.value.startsWith("2."))
Seq("com.chuusai" %%% "shapeless" % version.shapeless)
else Seq.empty)
Copy link
Contributor Author

@i10416 i10416 Jul 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shapeless is no longer necessary in Scala 3. We can use union type and Tuple instead of Coproduct and HList.

import cron4s.expr._

import org.scalacheck._

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is almost the same as https://github.com/alonsodomin/cron4s/pull/504/files#diff-fe082e93829b26c97f89813516bdfd1efa4b2f6cc1d26d5dcd7aa2dcec929e03.

The differences are

  • explicit type annotations for implicit vals/defs
  • shapeless import removal

@i10416
Copy link
Contributor Author

i10416 commented Jul 2, 2023

There are around 1700 lines of changes. However, changes in test and testkit modules are just explicit type annotations and imports for implicit conversions. There is a few changes in core modules, but most of them are just replacement from scala directory to scala-2 directory to hide shapeless from Scala 3. All tests pass for both Scala 2 and Scala 3.

Therefore, I think whole changes in this PR are safe to some extent.

@i10416 i10416 mentioned this pull request Jul 2, 2023
@i10416
Copy link
Contributor Author

i10416 commented Jul 2, 2023

@alonsodomin Hi, all cron4s modules compile in Scala 3 now. Please check when you have free time.

Copy link
Owner

@alonsodomin alonsodomin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the hard work, I truly believe this was some tedious effort. I'll publish a new version of the library ready for Scala 3 after merging this. Let me know if you have any outstanding things you would like to include before I do that.

@alonsodomin alonsodomin merged commit ff55e34 into alonsodomin:master Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants