Skip to content
This repository was archived by the owner on Apr 17, 2025. It is now read-only.

Commit 39b4871

Browse files
committed
Support for library downloading
1 parent b9d6655 commit 39b4871

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

Diff for: README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ This is an experimental project, so we're going to take some shortcuts:
7272
* No multiloader or mojmap/parchment support
7373
* Ok to vendor or manually write out dependencies instead of parsing maven POM's
7474

75-
- [ ] Library downloading
75+
- [x] version manifest and version json parsing
76+
- [x] asset downloading
77+
- ish, buck2 seems to open tons of fd's which can make the download flaky
78+
- [x] Library downloading
7679
- [ ] Client/server jar merge
7780
- [ ] Remap to intermediary
7881
- [ ] Remap to named

Diff for: minecraft_info.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ MinecraftInfo = provider(
66
"server_jar", # artifact
77
"server_mappings", # artifact
88
"asset_index", # artifact
9+
"libraries_dir", # artifact
910
]
1011
)

Diff for: minecraft_version.bzl

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
load("//minecraft_info.bzl", "MinecraftInfo")
22

3+
def _library_rules_match(rules):
4+
for rule in rules:
5+
# Assert action is always "allow"? That's the only thing appearing in the json
6+
os_name = rule["os"]["name"]
7+
# FIXME: Non-linux platform support
8+
if os_name != "linux":
9+
return False
10+
return True
11+
12+
313
def _minecraft_version_impl(ctx: "context") -> ["provider"]:
414
# Convert from dependency to artifact
515
# TODO: Should this assert only one output?
@@ -26,12 +36,13 @@ def _minecraft_version_impl(ctx: "context") -> ["provider"]:
2636
f=derive_version_json
2737
)
2838

29-
# Crawl version json and get the asset index, jars, and mappings
39+
# Crawl version json and get the asset index, jars, mappings, and libs
3040
asset_index_artifact = ctx.actions.declare_output("asset_index.json")
3141
client_jar_artifact = ctx.actions.declare_output("client.jar")
3242
client_mappings_artifact = ctx.actions.declare_output("client.txt")
3343
server_jar_artifact = ctx.actions.declare_output("server.jar")
3444
server_mappings_artifact = ctx.actions.declare_output("server.txt")
45+
libraries_dir_artifact = ctx.actions.declare_output("libraries", dir = True)
3546

3647
def derive_version_json_contents(ctx: "context", dynamic_artifacts, outputs):
3748
version_json = dynamic_artifacts[version_json_artifact].read_json()
@@ -60,6 +71,17 @@ def _minecraft_version_impl(ctx: "context") -> ["provider"]:
6071
version_json["downloads"]["server_mappings"]["url"],
6172
sha1=version_json["downloads"]["server_mappings"]["sha1"],
6273
)
74+
libraries = {}
75+
for library in version_json["libraries"]:
76+
if not _library_rules_match(library.get("rules", [])):
77+
continue
78+
lib_name = library["downloads"]["artifact"]["path"]
79+
libraries[lib_name] = ctx.actions.download_file(
80+
lib_name,
81+
library["downloads"]["artifact"]["url"],
82+
sha1=library["downloads"]["artifact"]["sha1"],
83+
)
84+
ctx.actions.symlinked_dir(outputs[libraries_dir_artifact].as_output(), libraries)
6385
ctx.actions.dynamic_output(
6486
dynamic=[version_json_artifact],
6587
inputs=[],
@@ -69,6 +91,7 @@ def _minecraft_version_impl(ctx: "context") -> ["provider"]:
6991
server_jar_artifact,
7092
server_mappings_artifact,
7193
asset_index_artifact,
94+
libraries_dir_artifact,
7295
],
7396
f=derive_version_json_contents,
7497
)
@@ -79,6 +102,7 @@ def _minecraft_version_impl(ctx: "context") -> ["provider"]:
79102
"client_mappings": [DefaultInfo(default_output=client_mappings_artifact)],
80103
"server_mappings": [DefaultInfo(default_output=server_mappings_artifact)],
81104
"asset_index": [DefaultInfo(default_output=asset_index_artifact)],
105+
"libraries": [DefaultInfo(default_output=libraries_dir_artifact)],
82106
},
83107
),
84108
MinecraftInfo(
@@ -88,6 +112,7 @@ def _minecraft_version_impl(ctx: "context") -> ["provider"]:
88112
server_jar=server_jar_artifact,
89113
server_mappings=server_mappings_artifact,
90114
asset_index=asset_index_artifact,
115+
libraries_dir=libraries_dir_artifact,
91116
),
92117
]
93118

0 commit comments

Comments
 (0)