Skip to content

Commit c4db976

Browse files
committed
Migrate build to Mill
1 parent a8877d2 commit c4db976

File tree

7 files changed

+475
-34
lines changed

7 files changed

+475
-34
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,12 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- uses: actions/checkout@v2
11-
- uses: actions/cache@v4
12-
with:
13-
path: ~/.cache/coursier/v1
14-
key: ${{ runner.os }}-coursier-${{ hashFiles('**/build.sbt') }}
15-
- name: Set up java
16-
uses: actions/setup-java@v4
17-
with:
18-
distribution: 'temurin'
19-
java-version: 21
20-
- name: Set up sbt
21-
uses: sbt/setup-sbt@v1
22-
- name: Build
23-
env:
24-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25-
run: sbt compile
11+
- name: Compile
12+
run: ./mill _.compile
2613
- name: Test
27-
env:
28-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29-
run: sbt test
14+
run: ./mill _.test
3015
- name: Build distributable
31-
env:
32-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33-
run: sbt cmdJVM/stage
16+
run: ./mill cmd.assembly
3417
- name: Set up Docker Buildx
3518
id: buildx
3619
uses: docker/setup-buildx-action@master
@@ -43,7 +26,8 @@ jobs:
4326
- name: Push cmd images
4427
uses: docker/build-push-action@v2
4528
with:
46-
context: cmd
29+
context: .
30+
file: cmd/Dockerfile
4731
platforms: linux/amd64,linux/arm64
4832
push: true
4933
tags: ghcr.io/torrentdam/cmd:latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
target
2+
out
23

34
.idea
45
.idea_modules

bittorrent/shared/src/main/scala/com/github/torrentdam/bittorrent/wire/Download.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ object Download {
193193
info.bytes.get.tupleRight(info)
194194
})
195195
.flatMap(values =>
196-
val sorted = values.sortBy(_._1)(Ordering[Int].reverse).map(_._2)
196+
val sorted = values.sortBy(_._1)(using Ordering[Int].reverse).map(_._2)
197197
val fastCount = (values.size.toDouble * 0.7).ceil.toInt
198198
val (fast, slow) = sorted.splitAt(fastCount)
199199
fast.traverse(_.cls.set(SpeedClass.Fast)) >> slow.traverse(_.cls.set(SpeedClass.Slow))

build.mill

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
//| mill-version: 1.0.1
2+
//| mill-jvm-version: temurin:21.0.6
3+
4+
import mill.*, scalalib.*, scalanativelib.*
5+
6+
object common extends CommonSettings {
7+
def mvnDeps = Seq(
8+
Deps.`scodec-bits`,
9+
Deps.`cats-effect`,
10+
Deps.ip4s,
11+
)
12+
}
13+
14+
object dht extends CommonSettings {
15+
def moduleDeps = Seq(common)
16+
def mvnDeps = Seq(
17+
Deps.bencode,
18+
Deps.`scodec-bits`,
19+
Deps.`cats-core`,
20+
Deps.`cats-effect`,
21+
Deps.`fs2-io`,
22+
Deps.`woof-core`,
23+
Deps.`cats-effect-cps`,
24+
)
25+
}
26+
27+
object bittorrent extends CommonSettings {
28+
override def sourceRoots = Seq("shared", "jvm")
29+
30+
def moduleDeps = Seq(common)
31+
def mvnDeps = Seq(
32+
Deps.bencode,
33+
Deps.`cats-core`,
34+
Deps.`cats-effect`,
35+
Deps.`fs2-io`,
36+
Deps.`monocle-core`,
37+
Deps.`monocle-macro`,
38+
Deps.`woof-core`,
39+
Deps.`cats-effect-cps`,
40+
)
41+
}
42+
43+
object files extends CommonSettings {
44+
def moduleDeps = Seq(common, bittorrent)
45+
def mvnDeps = Seq(
46+
Deps.`scodec-bits`,
47+
Deps.`cats-core`,
48+
Deps.`cats-effect`,
49+
Deps.`fs2-io`,
50+
Deps.`woof-core`,
51+
Deps.`cats-effect-cps`,
52+
)
53+
}
54+
55+
object cmd extends CommonSettings {
56+
def moduleDeps = Seq(bittorrent, dht, files)
57+
def mvnDeps = Seq(
58+
Deps.decline,
59+
Deps.`woof-core`,
60+
Deps.`cats-effect-cps`,
61+
)
62+
}
63+
64+
trait CommonSettings extends ScalaModule {
65+
def scalaVersion = "3.7.1"
66+
def sourceRoots = Seq(os.RelPath("."))
67+
def sources = Task.Sources(
68+
sourceRoots.map(directory => moduleDir / directory / "src" / "main" / "scala")*
69+
)
70+
71+
object test extends ScalaTests, TestModule.Munit {
72+
def munitVersion = "1.1.1"
73+
def sources = Task.Sources(
74+
sourceRoots.map(directory => CommonSettings.this.moduleDir / directory / "src" / "test" / "scala")*
75+
)
76+
def resources = Task.Sources(
77+
sourceRoots.map(directory => CommonSettings.this.moduleDir / directory / "src" / "test" / "resources")*
78+
)
79+
80+
def mvnDeps = Seq(
81+
Deps.`munit-cats-effect`,
82+
)
83+
}
84+
}
85+
86+
object Deps {
87+
88+
object Versions {
89+
val cats = "2.10.0"
90+
val `cats-effect` = "3.5.4"
91+
val ip4s = "3.3.0"
92+
val fs2 = "3.9.4"
93+
val epollcat = "0.1.4"
94+
val monocle = "3.2.0"
95+
val `scodec-bits` = "1.1.37"
96+
val bencode = "1.1.0"
97+
val decline = "2.4.1"
98+
val woof = "0.6.0"
99+
val `cats-effect-cps` = "0.4.0"
100+
}
101+
102+
val `cats-core` = mvn"org.typelevel::cats-core::${Versions.cats}"
103+
val `cats-effect` = mvn"org.typelevel::cats-effect::${Versions.`cats-effect`}"
104+
105+
val ip4s = mvn"com.comcast::ip4s-core::${Versions.ip4s}"
106+
107+
val `fs2-io` = mvn"co.fs2::fs2-io::${Versions.fs2}"
108+
109+
val `scodec-bits` = mvn"org.scodec::scodec-bits::${Versions.`scodec-bits`}"
110+
111+
val `woof-core` = mvn"org.legogroup::woof-core::${Versions.woof}"
112+
113+
val `monocle-core` = mvn"dev.optics::monocle-core::${Versions.monocle}"
114+
val `monocle-macro` = mvn"dev.optics::monocle-macro::${Versions.monocle}"
115+
116+
val bencode = mvn"io.github.torrentdam.bencode::bencode::${Versions.bencode}"
117+
118+
val `munit-cats-effect` = mvn"org.typelevel::munit-cats-effect::2.1.0"
119+
120+
val decline = mvn"com.monovore::decline-effect::${Versions.decline}"
121+
122+
val `cats-effect-cps` = mvn"org.typelevel::cats-effect-cps::${Versions.`cats-effect-cps`}"
123+
}

cmd/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
FROM eclipse-temurin:24-jre-noble
22

3-
COPY ./.jvm/target/universal/stage /opt/torrentdam
3+
COPY ./out/cmd/assembly.dest/out.jar /opt/torrentdam/assembly.jar
44

5-
ENTRYPOINT ["/opt/torrentdam/bin/cmd", "-Dcats.effect.tracing.mode=none", "-J-XX:+UnlockExperimentalVMOptions", "-J-XX:+UseCompactObjectHeaders"]
5+
ENTRYPOINT [ "java", "-Dcats.effect.tracing.mode=none", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCompactObjectHeaders", "-jar", "/opt/torrentdam/assembly.jar"]

dht/src/main/scala/com/github/torrentdam/bittorrent/dht/message.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,32 @@ object Message {
2323
BencodeFormat.ByteVectorFormat.imap(NodeId.apply)(_.bytes)
2424

2525
val PingQueryFormat: BencodeFormat[Query.Ping] = (
26-
field[NodeId]("a")(field[NodeId]("id"))
26+
field[NodeId]("a")(using field[NodeId]("id"))
2727
).imap[Query.Ping](qni => Query.Ping(qni))(v => v.queryingNodeId)
2828

2929
val FindNodeQueryFormat: BencodeFormat[Query.FindNode] = (
3030
field[(NodeId, NodeId)]("a")(
31-
(field[NodeId]("id"), field[NodeId]("target")).tupled
31+
using (field[NodeId]("id"), field[NodeId]("target")).tupled
3232
)
3333
).imap[Query.FindNode](Query.FindNode.apply)(v => (v.queryingNodeId, v.target))
3434

3535
given BencodeFormat[InfoHash] = BencodeFormat.ByteVectorFormat.imap(InfoHash(_))(_.bytes)
3636

3737
val GetPeersQueryFormat: BencodeFormat[Query.GetPeers] = (
3838
field[(NodeId, InfoHash)]("a")(
39-
(field[NodeId]("id"), field[InfoHash]("info_hash")).tupled
39+
using (field[NodeId]("id"), field[InfoHash]("info_hash")).tupled
4040
)
4141
).imap[Query.GetPeers](Query.GetPeers.apply)(v => (v.queryingNodeId, v.infoHash))
4242

4343
val AnnouncePeerQueryFormat: BencodeFormat[Query.AnnouncePeer] = (
4444
field[(NodeId, InfoHash, Long)]("a")(
45-
(field[NodeId]("id"), field[InfoHash]("info_hash"), field[Long]("port")).tupled
45+
using (field[NodeId]("id"), field[InfoHash]("info_hash"), field[Long]("port")).tupled
4646
)
4747
).imap[Query.AnnouncePeer](Query.AnnouncePeer.apply)(v => (v.queryingNodeId, v.infoHash, v.port))
4848

4949
val SampleInfoHashesQueryFormat: BencodeFormat[Query.SampleInfoHashes] = (
5050
field[(NodeId, NodeId)]("a")(
51-
(field[NodeId]("id"), field[NodeId]("target")).tupled
51+
using (field[NodeId]("id"), field[NodeId]("target")).tupled
5252
)
5353
).imap[Query.SampleInfoHashes](Query.SampleInfoHashes.apply)(v => (v.queryingNodeId, v.target))
5454

@@ -114,7 +114,7 @@ object Message {
114114

115115
val NodesResponseFormat: BencodeFormat[Response.Nodes] = (
116116
field[NodeId]("id"),
117-
field[List[NodeInfo]]("nodes")(encodedString(CompactNodeInfoCodec))
117+
field[List[NodeInfo]]("nodes")(using encodedString(CompactNodeInfoCodec))
118118
).imapN[Response.Nodes](Response.Nodes.apply)(v => (v.id, v.nodes))
119119

120120
val PeersResponseFormat: BencodeFormat[Response.Peers] = (
@@ -124,8 +124,8 @@ object Message {
124124

125125
val SampleInfoHashesResponseFormat: BencodeFormat[Response.SampleInfoHashes] = (
126126
field[NodeId]("id"),
127-
fieldOptional[List[NodeInfo]]("nodes")(encodedString(CompactNodeInfoCodec)),
128-
field[List[InfoHash]]("samples")(encodedString(CompactInfoHashCodec))
127+
fieldOptional[List[NodeInfo]]("nodes")(using encodedString(CompactNodeInfoCodec)),
128+
field[List[InfoHash]]("samples")(using encodedString(CompactInfoHashCodec))
129129
).imapN[Response.SampleInfoHashes](Response.SampleInfoHashes.apply)(v => (v.id, v.nodes, v.samples))
130130

131131
val ResponseFormat: BencodeFormat[Response] =
@@ -147,7 +147,7 @@ object Message {
147147

148148
val ResponseMessageFormat: BencodeFormat[Message.ResponseMessage] = (
149149
field[ByteVector]("t"),
150-
field[Response]("r")(ResponseFormat)
150+
field[Response]("r")(using ResponseFormat)
151151
).imapN[ResponseMessage]((tid, r) => ResponseMessage(tid, r))(v => (v.transactionId, v.response))
152152

153153
val ErrorMessageFormat: BencodeFormat[Message.ErrorMessage] = (

0 commit comments

Comments
 (0)