Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ py_test(
":xlsynth_sys_dep_probe",
":xlsynth_sys_legacy_inputs_probe",
":xlsynth_sys_runtime_probe",
"@rules_xlsynth_selftest_xls_toolchain",
"@rules_xlsynth_selftest_xls_runtime//:dslx_stdlib",
"@rules_xlsynth_selftest_xls_runtime//:xlsynth_sys_artifact_config",
"@rules_xlsynth_selftest_xls_toolchain",
],
deps = ["@rules_python//python/runfiles"],
)
Expand Down
1 change: 1 addition & 0 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ is:
- `@<name>_runtime//:libxls_link`
- `@<name>_runtime//:xls_aot_runtime` when the selected XLS line provides the archive
- `@<name>_runtime//:xls_aot_runtime_file` when the selected XLS line provides the archive
- `@<name>_runtime//:xls_aot_runtime_link_config_file` when the selected XLS line provides the archive
- `@<name>_runtime//:dslx_stdlib`
- `@<name>_runtime//:xlsynth_sys_artifact_config`
- `@<name>_runtime//:xlsynth_sys_legacy_stdlib`
Expand Down
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,11 @@ do not use that repo directly or publish it with `use_repo(...)`.
The runtime repo exposes:

- `@<name>_runtime//:libxls` and `@<name>_runtime//:libxls_link` for native consumers
- `@<name>_runtime//:xls_aot_runtime` and `@<name>_runtime//:xls_aot_runtime_file`
when the selected XLS line provides the standalone AOT static runtime archive
- `@<name>_runtime//:xls_aot_runtime`,
`@<name>_runtime//:xls_aot_runtime_file`, and
`@<name>_runtime//:xls_aot_runtime_link_config_file` when the selected XLS
line provides the standalone AOT static runtime archive plus its producer-owned
link metadata
- `@<name>_runtime//:dslx_stdlib` for packages that need the standard library tree
- `@<name>_runtime//:xlsynth_sys_artifact_config` for the modern single-file
build-script contract shared by `xlsynth-sys` and `xlsynth-aot-runtime`
Expand All @@ -124,10 +127,11 @@ The runtime repo exposes:
`artifact_config`, `libxls_file`, `libxls`, or `dslx_stdlib` directly in
downstream `MODULE.bazel` files. `xlsynth-aot-runtime` consumers should reuse
the same artifact-config export so their build scripts receive the matching
standalone runtime archive without a second bundle contract. Older bundles may
omit the archive entirely; that keeps non-AOT consumers on old XLS lines valid
while making an AOT consumer fail locally if it selects a bundle that cannot
provide the archive it needs.
standalone runtime archive and its producer-owned link config without a second
bundle contract. Older bundles may omit the archive pair entirely; that keeps
non-AOT consumers on old XLS lines valid while making an AOT consumer fail
locally if it selects a bundle that cannot provide the runtime artifacts it
needs.

Supported DSLX rules may opt out of the registered default bundle with
`xls_bundle = "@<name>_toolchain//:bundle"`. Today that escape hatch is available on
Expand Down
53 changes: 53 additions & 0 deletions artifact_resolution_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def exists_fn(path):
"/tools/xlsynth/v0.38.0/xls/dslx/stdlib",
"/tools/xlsynth/v0.38.0/libxls.dylib" if sys.platform == "darwin" else "/tools/xlsynth/v0.38.0/libxls.so",
"/tools/xlsynth/v0.38.0/libxls_aot_runtime.a",
"/tools/xlsynth/v0.38.0/libxls_aot_runtime_link.toml",
],
)

Expand Down Expand Up @@ -105,6 +106,17 @@ def test_installed_only_requires_installed_paths(self):
exists_fn = lambda path: False,
)

def test_installed_paths_require_static_aot_runtime_pair(self):
with self.assertRaisesRegex(ValueError, "together"):
materialize_xls_bundle.resolve_artifact_plan(
artifact_source = "installed_only",
xls_version = "0.38.0",
driver_version = "0.33.0",
installed_tools_root_prefix = "/tools/xlsynth",
installed_driver_root_prefix = "/tools/xlsynth-driver",
exists_fn = lambda path: not path.endswith("libxls_aot_runtime_link.toml"),
)

def test_download_only_skips_installed_probe(self):
observed_paths = []

Expand All @@ -131,6 +143,7 @@ def test_local_paths_bypass_versioned_selection(self):
local_driver_path = "/tmp/xls-local-dev/xlsynth-driver",
local_libxls_path = "/tmp/xls-local-dev/libxls.so",
local_xls_aot_runtime_path = "/tmp/xls-local-dev/libxls_aot_runtime.a",
local_xls_aot_runtime_link_config_path = "/tmp/xls-local-dev/libxls_aot_runtime_link.toml",
)
self.assertEqual(plan["mode"], "local_paths")
self.assertEqual(
Expand All @@ -141,6 +154,10 @@ def test_local_paths_bypass_versioned_selection(self):
plan["xls_aot_runtime"],
Path("/tmp/xls-local-dev/libxls_aot_runtime.a"),
)
self.assertEqual(
plan["xls_aot_runtime_link_config"],
Path("/tmp/xls-local-dev/libxls_aot_runtime_link.toml"),
)

def test_local_paths_allow_bundle_without_static_aot_runtime(self):
plan = materialize_xls_bundle.resolve_artifact_plan(
Expand All @@ -153,6 +170,20 @@ def test_local_paths_allow_bundle_without_static_aot_runtime(self):
local_libxls_path = "/tmp/xls-local-dev/libxls.so",
)
self.assertIsNone(plan["xls_aot_runtime"])
self.assertIsNone(plan["xls_aot_runtime_link_config"])

def test_local_paths_require_static_aot_runtime_pair(self):
with self.assertRaisesRegex(ValueError, "together"):
materialize_xls_bundle.resolve_artifact_plan(
artifact_source = "local_paths",
xls_version = "",
driver_version = "",
local_tools_path = "/tmp/xls-local-dev/tools",
local_dslx_stdlib_path = "/tmp/xls-local-dev/stdlib",
local_driver_path = "/tmp/xls-local-dev/xlsynth-driver",
local_libxls_path = "/tmp/xls-local-dev/libxls.so",
local_xls_aot_runtime_path = "/tmp/xls-local-dev/libxls_aot_runtime.a",
)

def test_resolve_driver_plan_prefers_installed_driver(self):
plan = materialize_xls_bundle.resolve_driver_plan(
Expand Down Expand Up @@ -305,6 +336,10 @@ def test_installed_paths_use_live_version_pattern(self):
expected_name = "libxls.dylib" if sys.platform == "darwin" else "libxls.so"
self.assertEqual(plan["libxls"].name, expected_name)
self.assertEqual(plan["xls_aot_runtime"].name, "libxls_aot_runtime.a")
self.assertEqual(
plan["xls_aot_runtime_link_config"].name,
"libxls_aot_runtime_link.toml",
)

def test_build_driver_environment_sets_runtime_library_search_path(self):
libxls_path = "/tmp/xls-bundle/libxls.dylib" if sys.platform == "darwin" else "/tmp/xls-bundle/libxls.so"
Expand Down Expand Up @@ -414,6 +449,7 @@ def test_download_versioned_artifacts_reuses_valid_cache(self):
(download_root / binary).write_text("", encoding = "utf-8")
(download_root / "libxls-v0.38.0-arm64.dylib").write_text("", encoding = "utf-8")
(download_root / "libxls_aot_runtime-arm64.a").write_text("", encoding = "utf-8")
(download_root / "libxls_aot_runtime_link-arm64.toml").write_text("", encoding = "utf-8")

with mock.patch.object(materialize_xls_bundle, "detect_host_platform", return_value = "arm64"):
with mock.patch.object(materialize_xls_bundle.subprocess, "run") as mock_run:
Expand All @@ -429,6 +465,10 @@ def test_download_versioned_artifacts_reuses_valid_cache(self):
resolved["xls_aot_runtime"],
download_root / "libxls_aot_runtime-arm64.a",
)
self.assertEqual(
resolved["xls_aot_runtime_link_config"],
download_root / "libxls_aot_runtime_link-arm64.toml",
)
self.assertEqual(resolved["runtime_files"], [])
mock_run.assert_not_called()

Expand All @@ -447,6 +487,7 @@ def test_download_versioned_artifacts_reuses_valid_cache_without_aot_runtime(sel
resolved = materialize_xls_bundle.download_versioned_artifacts(repo_root, "0.38.0")

self.assertIsNone(resolved["xls_aot_runtime"])
self.assertIsNone(resolved["xls_aot_runtime_link_config"])
mock_run.assert_not_called()

def test_load_runtime_manifest_returns_runtime_files(self):
Expand Down Expand Up @@ -615,6 +656,8 @@ def test_stage_runtime_payload_records_runtime_metadata(self):
libxls_path.write_text("xls\n", encoding = "utf-8")
xls_aot_runtime_path = input_root / "libxls_aot_runtime.a"
xls_aot_runtime_path.write_text("aot\n", encoding = "utf-8")
xls_aot_runtime_link_config_path = input_root / "libxls_aot_runtime_link.toml"
xls_aot_runtime_link_config_path.write_text("format_version = 1\n", encoding = "utf-8")
runtime_companion = input_root / "libc++.so.1"
runtime_companion.write_text("runtime\n", encoding = "utf-8")

Expand All @@ -630,6 +673,7 @@ def test_stage_runtime_payload_records_runtime_metadata(self):
"dslx_stdlib_root": stdlib_root,
"libxls": libxls_path,
"xls_aot_runtime": xls_aot_runtime_path,
"xls_aot_runtime_link_config": xls_aot_runtime_link_config_path,
"runtime_files": [runtime_companion],
},
)
Expand All @@ -644,10 +688,19 @@ def test_stage_runtime_payload_records_runtime_metadata(self):
)
self.assertEqual(metadata["libxls_name"], "libxls.so")
self.assertEqual(metadata["xls_aot_runtime_name"], "libxls_aot_runtime.a")
self.assertEqual(
metadata["xls_aot_runtime_link_config_name"],
"libxls_aot_runtime_link.toml",
)
self.assertEqual(metadata["libxls_runtime_aliases"], "libxls-v0.38.0.so")
self.assertEqual(metadata["libxls_runtime_files"], "libc++.so.1")
self.assertIn('aot_runtime_path = "libxls_aot_runtime.a"', artifact_config)
self.assertIn(
'aot_runtime_link_config_path = "libxls_aot_runtime_link.toml"',
artifact_config,
)
self.assertTrue((repo_root / "libxls_aot_runtime.a").is_file())
self.assertTrue((repo_root / "libxls_aot_runtime_link.toml").is_file())
self.assertTrue((repo_root / "libc++.so.1").is_file())

def test_materialize_toolchain_surface_records_driver_capabilities(self):
Expand Down
25 changes: 23 additions & 2 deletions download_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def build_static_aot_runtime_release_filename(platform):
return "libxls_aot_runtime-{}.a".format(platform)


def build_static_aot_runtime_link_config_release_filename(platform):
return "libxls_aot_runtime_link-{}.toml".format(platform)


def build_runtime_tarball_release_filename(platform):
return "libxls-runtime-{}.tar.gz".format(platform)

Expand Down Expand Up @@ -264,13 +268,30 @@ def main():
high_integrity_download(base_url, artifact, options.output_dir, options.max_attempts, is_binary, options.platform)

if options.dso:
try_high_integrity_download(
static_aot_runtime = build_static_aot_runtime_release_filename(options.platform)
static_aot_runtime_link_config = build_static_aot_runtime_link_config_release_filename(
options.platform
)
archive_present = try_high_integrity_download(
base_url,
build_static_aot_runtime_release_filename(options.platform),
static_aot_runtime,
options.output_dir,
options.max_attempts,
is_binary = False,
)
link_config_present = try_high_integrity_download(
base_url,
static_aot_runtime_link_config,
options.output_dir,
options.max_attempts,
is_binary = False,
)
if archive_present != link_config_present:
print("Ignoring partial standalone AOT runtime asset set for {}".format(options.platform))
for partial_name in [static_aot_runtime, static_aot_runtime_link_config]:
partial_path = os.path.join(options.output_dir, partial_name)
if os.path.exists(partial_path):
os.remove(partial_path)

# Download and extract dslx_stdlib.tar.gz
stdlib_filename = "dslx_stdlib.tar.gz"
Expand Down
8 changes: 8 additions & 0 deletions download_release_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ def test_static_aot_runtime_release_filename_is_platform_scoped(self):
download_release.build_static_aot_runtime_release_filename("ubuntu2004"),
"libxls_aot_runtime-ubuntu2004.a",
)
self.assertEqual(
download_release.build_static_aot_runtime_link_config_release_filename("arm64"),
"libxls_aot_runtime_link-arm64.toml",
)
self.assertEqual(
download_release.build_static_aot_runtime_link_config_release_filename("ubuntu2004"),
"libxls_aot_runtime_link-ubuntu2004.toml",
)

def test_copy_url_to_path_retries_after_stream_reset(self):
with tempfile.TemporaryDirectory() as temp_dir:
Expand Down
27 changes: 26 additions & 1 deletion extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ def _driver_supports_sv_struct_field_ordering(driver_version):
return True
return _version_at_least(driver_version, "0.36.0")

def _runtime_build_file(libxls_name, xls_aot_runtime_name, runtime_files, runtime_aliases):
def _runtime_build_file(
libxls_name,
xls_aot_runtime_name,
xls_aot_runtime_link_config_name,
runtime_files,
runtime_aliases):
tool_list = ",\n ".join(['"{}"'.format(name) for name in _TOOL_BINARIES])
exported_names = _TOOL_BINARIES + [libxls_name] + runtime_files + runtime_aliases
if xls_aot_runtime_name:
exported_names.append(xls_aot_runtime_name)
exported_names.append(xls_aot_runtime_link_config_name)
exported_files = ",\n ".join(['"{}"'.format(name) for name in exported_names])
runtime_file_srcs = ",\n ".join(['"{}"'.format(name) for name in runtime_files])
runtime_alias_srcs = ",\n ".join(['"{}"'.format(name) for name in runtime_aliases])
Expand All @@ -91,13 +97,19 @@ filegroup(
srcs = ["{xls_aot_runtime_name}"],
visibility = ["//visibility:public"],
)
filegroup(
name = "xls_aot_runtime_link_config_file",
srcs = ["{xls_aot_runtime_link_config_name}"],
visibility = ["//visibility:public"],
)
cc_import(
name = "xls_aot_runtime",
static_library = ":xls_aot_runtime_file",
visibility = ["//visibility:public"],
)
""".format(
xls_aot_runtime_name = xls_aot_runtime_name,
xls_aot_runtime_link_config_name = xls_aot_runtime_link_config_name,
) if xls_aot_runtime_name else ""
lib_file_rule = """
filegroup(
Expand Down Expand Up @@ -158,6 +170,7 @@ xlsynth_artifact_config(
dslx_stdlib = ":dslx_stdlib",
shared_library = ":libxls_file",
static_aot_runtime = {static_aot_runtime},
static_aot_runtime_link_config = {static_aot_runtime_link_config},
visibility = ["//visibility:public"],
)

Expand Down Expand Up @@ -217,6 +230,7 @@ xls_runtime_surface(
lib_file_rule = lib_file_rule.strip(),
aot_runtime_rule = aot_runtime_rule.strip(),
static_aot_runtime = '":xls_aot_runtime_file"' if xls_aot_runtime_name else "None",
static_aot_runtime_link_config = '":xls_aot_runtime_link_config_file"' if xls_aot_runtime_name else "None",
)

def _string_attr_line(name, value):
Expand Down Expand Up @@ -369,6 +383,11 @@ def _materialize_bundle_args(repo_ctx, surface):
args.extend(["--local-libxls-path", repo_ctx.attr.local_libxls_path])
if repo_ctx.attr.local_xls_aot_runtime_path:
args.extend(["--local-xls-aot-runtime-path", repo_ctx.attr.local_xls_aot_runtime_path])
if repo_ctx.attr.local_xls_aot_runtime_link_config_path:
args.extend([
"--local-xls-aot-runtime-link-config-path",
repo_ctx.attr.local_xls_aot_runtime_link_config_path,
])
return args

def _runtime_repo_impl(repo_ctx):
Expand Down Expand Up @@ -398,6 +417,7 @@ def _runtime_repo_impl(repo_ctx):
_runtime_build_file(
libxls_name = metadata["libxls_name"],
xls_aot_runtime_name = metadata["xls_aot_runtime_name"],
xls_aot_runtime_link_config_name = metadata["xls_aot_runtime_link_config_name"],
runtime_files = runtime_files,
runtime_aliases = runtime_aliases,
),
Expand Down Expand Up @@ -439,6 +459,7 @@ _runtime_repo_attrs = {
"local_dslx_stdlib_path": attr.string(),
"local_libxls_path": attr.string(),
"local_xls_aot_runtime_path": attr.string(),
"local_xls_aot_runtime_link_config_path": attr.string(),
"local_tools_path": attr.string(),
"xls_version": attr.string(),
"xlsynth_driver_version": attr.string(),
Expand All @@ -453,6 +474,7 @@ _toolchain_repo_attrs = {
"local_dslx_stdlib_path": attr.string(),
"local_libxls_path": attr.string(),
"local_xls_aot_runtime_path": attr.string(),
"local_xls_aot_runtime_link_config_path": attr.string(),
"local_tools_path": attr.string(),
"repo_alias": attr.string(mandatory = True),
"runtime_repo_name": attr.string(mandatory = True),
Expand Down Expand Up @@ -496,6 +518,7 @@ _toolchain_tag = tag_class(attrs = {
"local_dslx_stdlib_path": attr.string(),
"local_libxls_path": attr.string(),
"local_xls_aot_runtime_path": attr.string(),
"local_xls_aot_runtime_link_config_path": attr.string(),
"local_tools_path": attr.string(),
"name": attr.string(mandatory = True),
"xls_version": attr.string(),
Expand All @@ -517,6 +540,7 @@ def _xls_extension_impl(module_ctx):
local_dslx_stdlib_path = toolchain.local_dslx_stdlib_path,
local_libxls_path = toolchain.local_libxls_path,
local_xls_aot_runtime_path = toolchain.local_xls_aot_runtime_path,
local_xls_aot_runtime_link_config_path = toolchain.local_xls_aot_runtime_link_config_path,
local_tools_path = toolchain.local_tools_path,
xls_version = toolchain.xls_version,
xlsynth_driver_version = toolchain.xlsynth_driver_version,
Expand All @@ -536,6 +560,7 @@ def _xls_extension_impl(module_ctx):
local_dslx_stdlib_path = toolchain.local_dslx_stdlib_path,
local_libxls_path = toolchain.local_libxls_path,
local_xls_aot_runtime_path = toolchain.local_xls_aot_runtime_path,
local_xls_aot_runtime_link_config_path = toolchain.local_xls_aot_runtime_link_config_path,
local_tools_path = toolchain.local_tools_path,
repo_alias = toolchain_name,
runtime_repo_name = runtime_name,
Expand Down
Loading
Loading