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: 2 additions & 0 deletions cuda-wasm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Package metadata

- Set `homepage` to https://ruv.io. No code or dependency change.
- Add truthful search keywords (`cuda2rust`, `code-generation`, `nodejs`).
- The `cuda-rust-wasm` crate moves to 0.2.1 because its archive contains this directory's `package.json`, README and changelog; crates.io 0.2.0 holds the old bytes. No Rust code change.

## [2.0.0] - Unreleased

Expand Down
2 changes: 1 addition & 1 deletion cuda-wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cuda-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cuda-rust-wasm"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
authors = ["CUDA-Rust Team"]
description = "CUDA to Rust transpiler with WebGPU/WASM support"
Expand Down
6 changes: 3 additions & 3 deletions cuda-wasm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

`cuda-rust-wasm` is an experimental Rust toolkit for reading a subset of CUDA C++, generating Rust or WGSL text, and experimenting with CPU reference kernels. CUDA is an NVIDIA trademark; this project is independent of NVIDIA.

The Rust library and `cuda2rust` command have a staged 0.2.0 release. The `cuda-wasm` npm package has a staged 2.0.1 release with a smaller, working contract: a Node.js wrapper around that command, returning Rust or WGSL **source text**. These versions are prepared in this checkout; registry publication is a separate step.
The Rust library and `cuda2rust` command are published on crates.io as `cuda-rust-wasm` 0.2.1. The `cuda-wasm` npm package (2.0.1) has a smaller, working contract: a Node.js wrapper around that command, returning Rust or WGSL **source text**.

![CUDA source passes through the Node wrapper to a trusted cuda2rust executable, which returns Rust or WGSL source for separate validation.](docs/assets/source-flow.svg)

## Use the Node.js package

Node.js 22.12 or newer and a trusted `cuda2rust` 0.2.0-or-newer executable are required. npm installation has no install hooks, downloads no executables, and builds no native modules. The package has no npm runtime dependencies.

After the staged versions are published:
Install both:

```bash
npm install cuda-wasm@2
cargo install cuda-rust-wasm --version 0.2.0 --locked
cargo install cuda-rust-wasm --version 0.2.1 --locked
```

For this checkout, build the real command and point the wrapper at it:
Expand Down
5 changes: 4 additions & 1 deletion cuda-wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
"rust",
"wgsl",
"cli",
"source-generation"
"source-generation",
"cuda2rust",
"code-generation",
"nodejs"
],
"author": {
"name": "CUDA-WASM Team",
Expand Down
32 changes: 24 additions & 8 deletions scripts/publish-candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
ROOT = Path(__file__).resolve().parents[1]
API = 'https://crates.io/api/v1'
USER_AGENT = 'ruv-fann-release (https://github.com/ruvnet/ruv-FANN)'
# static.crates.io can take several minutes to serve a newly uploaded crate.
VISIBILITY_TIMEOUT = 600
VISIBILITY_DELAYS = (5, 10, 20, 30, 60)


def sha(data):
Expand Down Expand Up @@ -111,6 +114,21 @@ def downloaded(name, version):
raise


def wait_public(name, version, timeout=VISIBILITY_TIMEOUT, sleep=time.sleep, clock=time.monotonic):
"""Return the public crate bytes, or None if static.crates.io still lacks them past the deadline."""
deadline = clock() + timeout
attempt = 0
while True:
public = downloaded(name, version)
if public is not None:
return public
remaining = deadline - clock()
if remaining <= 0:
return None
sleep(min(VISIBILITY_DELAYS[min(attempt, len(VISIBILITY_DELAYS) - 1)], remaining))
attempt += 1


def publish(archive, data, digest, token):
existing = downloaded(data['name'], data['vers'])
if existing is not None:
Expand All @@ -132,14 +150,12 @@ def publish(archive, data, digest, token):
raise RuntimeError(f'Crates upload HTTP {error.code}: {detail}') from None
if result.get('errors'):
raise RuntimeError(str(result['errors']).replace(token, '[REDACTED]'))
for _ in range(24):
public = downloaded(data['name'], data['vers'])
if public is not None:
if sha(public) != digest:
raise ValueError('Public bytes differ from verified candidate')
return 'published-and-byte-verified'
time.sleep(5)
raise RuntimeError('Published, but public download is not yet available')
public = wait_public(data['name'], data['vers'])
if public is None:
raise RuntimeError(f"Published, but {data['name']} {data['vers']} was not publicly downloadable within {VISIBILITY_TIMEOUT}s; rerun the failed job to verify the bytes")
if sha(public) != digest:
raise ValueError('Public bytes differ from verified candidate')
return 'published-and-byte-verified'


def main():
Expand Down
2 changes: 1 addition & 1 deletion scripts/publish-npm-candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def main():
stream.seek(0);json.dump({'sourceSha':head(),'packages':published},stream,indent=2);stream.truncate();stream.flush()
return
# Install the Cargo compiler and dense example from public crates.io too.
run(['cargo','install','cuda-rust-wasm','--version','=0.2.0','--locked','--bin','cuda2rust','--root',str(base/'public-compiler')],base)
run(['cargo','install','cuda-rust-wasm','--version','=0.2.1','--locked','--bin','cuda2rust','--root',str(base/'public-compiler')],base)
consumer(base/'npm-public-consumer',[r['name']+'@'+r['version'] for r in record['packages']],record['packages'],base/'public-compiler/bin/cuda2rust')
rust = base/'rust-public-consumer';(rust/'src').mkdir(parents=True)
(rust/'Cargo.toml').write_text('[package]\nname="release-consumer"\nversion="0.0.0"\nedition="2021"\n[dependencies]\nruv-fann={version="=0.2.2",default-features=false,features=["std","serde"]}\nruv-fann-candle="=0.1.0"\n')
Expand Down
44 changes: 44 additions & 0 deletions scripts/tests/test_publish_candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,48 @@ def test_changed_archive_is_rejected_before_upload(self):
upload.assert_not_called()


def test_public_download_waits_past_two_minutes_with_backoff(self):
clock = Clock()
calls = []
def fake(name, version):
calls.append((name, version))
return b'crate' if clock.now >= 300 else None
with patch.object(publisher, 'downloaded', side_effect=fake):
self.assertEqual(publisher.wait_public('fixture', '1.0.0', sleep=clock.sleep, clock=clock.time), b'crate')
self.assertEqual(clock.sleeps[:5], [5, 10, 20, 30, 60])
self.assertTrue(all(delay <= 60 for delay in clock.sleeps))
self.assertEqual(calls[0], ('fixture', '1.0.0'))

def test_public_download_gives_up_at_the_deadline(self):
clock = Clock()
with patch.object(publisher, 'downloaded', return_value=None):
self.assertIsNone(publisher.wait_public('fixture', '1.0.0', sleep=clock.sleep, clock=clock.time))
self.assertEqual(clock.now, publisher.VISIBILITY_TIMEOUT)

def test_upload_timeout_reports_visibility_not_byte_mismatch(self):
with tempfile.TemporaryDirectory() as directory:
archive = self.archive(directory, '[package]\nname="fixture"\nversion="1.0.0"')
response = io.BytesIO(b'{}')
response.__enter__ = lambda *a: response
response.__exit__ = lambda *a: False
with patch.object(publisher, 'downloaded', return_value=None), \
patch.object(publisher.urllib.request, 'urlopen', return_value=response), \
patch.object(publisher, 'wait_public', return_value=None):
with self.assertRaisesRegex(RuntimeError, 'not publicly downloadable'):
publisher.publish(archive, publisher.metadata(archive), publisher.sha(archive.read_bytes()), 'test-only')


class Clock:
def __init__(self):
self.now = 0
self.sleeps = []

def time(self):
return self.now

def sleep(self, seconds):
self.sleeps.append(seconds)
self.now += seconds


if __name__ == '__main__': unittest.main()
Loading