Skip to content

throwaway rust impl #1

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ tsconfig.tsbuildinfo
.idea
.vs
dist/
.vscode
*.map
*.tsbuildinfo
*.tabl.json
Expand All @@ -15,3 +14,6 @@ dist/
build/
coverage/
jsii-outdir/
test-rust-generation/
rust-cdk-example/
test-dependency-generation/
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"terminal.integrated.shell.linux": "/bin/bash",
"files.associations": {
"*.rs": "rust"
},
"rust-analyzer.checkOnSave.command": "clippy",
"terminal.integrated.cwd": "${workspaceFolder}"
}
40 changes: 40 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build Rust Target (jsii-calc)",
"type": "shell",
"command": "./build-rust-target.sh",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
},
"problemMatcher": [],
"detail": "Builds jsii-pacmak with Rust target and generates Rust code for jsii-calc"
},
{
"label": "Build Rust Target (All in Docker)",
"type": "shell",
"command": "./build-rust-target-docker.sh",
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
},
"problemMatcher": [],
"detail": "Builds everything in Docker including cargo build"
}
]
}
37 changes: 37 additions & 0 deletions build-rust-target-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

set -e # Exit on any error

echo "🚀 Building Rust target for jsii-calc (all in Docker)..."

# Ensure output directory exists
mkdir -p test-rust-generation

echo "📦 Building everything in Docker..."
docker run -it --rm \
-v "$(pwd)":/source \
-v "$(pwd)/test-rust-generation":/output \
--user "$(id -u):$(id -g)" \
-e HOME=/tmp \
-e YARN_CACHE_FOLDER=/tmp/.yarn-cache \
-w /source \
jsii/superchain:local \
bash -c "
echo '🔨 Building jsii-pacmak...'
yarn workspace jsii-pacmak build

echo '🦀 Generating Rust code...'
node packages/jsii-pacmak/bin/jsii-pacmak --target rust --force-target --outdir /output packages/jsii-calc

echo '🦀 Building generated Rust code...'
if [ -d '/output/rust/jsii_calc' ]; then
cd /output/rust/jsii_calc
cargo build
echo '✅ Rust build completed successfully!'
else
echo '❌ Error: Generated Rust code not found'
exit 1
fi
"

echo "🎉 All done! Check test-rust-generation/rust/jsii_calc for the generated and built Rust code."
67 changes: 67 additions & 0 deletions build-rust-target.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/bin/bash

set -e # Exit on any error

echo "🚀 Building Rust target for AWS S3 test..."

# Ensure output directory exists with correct permissions
mkdir -p test-rust-generation
# Fix ownership if needed (in case it was created by root previously)
if [ "$(stat -c %U test-rust-generation)" != "$(whoami)" ]; then
echo "🔧 Fixing directory permissions..."
sudo chown -R "$(id -u):$(id -g)" test-rust-generation/
fi

echo "📦 Building everything inside Docker..."
docker run -it --rm \
-v "$(pwd)":/source \
-v "$(pwd)/test-rust-generation":/output \
--user "$(id -u):$(id -g)" \
-e HOME=/tmp \
-e YARN_CACHE_FOLDER=/tmp/.yarn-cache \
-w /source \
jsii/superchain:local \
bash -c "
echo '📦 Installing root dependencies...'
yarn install

echo '🔨 Building dependencies first...'
yarn workspace @scope/jsii-calc-lib build

echo '🔨 Building aws-s3-test package...'
yarn workspace aws-s3-test build

echo '🔧 Fixing jsii-pacmak linting issues...'
yarn workspace jsii-pacmak lint:fix || echo 'Lint fix attempted, continuing...'

echo '🔨 Building jsii-pacmak...'
yarn workspace jsii-pacmak build

echo '🦀 Generating Rust code...'
node packages/jsii-pacmak/bin/jsii-pacmak --target rust --force-target --outdir /output packages/aws-s3-test
"

echo "🦀 Building generated Rust code on host..."
if [ -d "test-rust-generation/rust/aws_s3_test" ]; then
cd test-rust-generation/rust/aws_s3_test

echo "📋 Generated Cargo.toml:"
cat Cargo.toml
echo ""

echo "🔍 Generated Rust files:"
find . -name "*.rs" | head -10
echo ""

cargo build
echo "✅ Rust build completed successfully!"
else
echo "❌ Error: Generated Rust code not found in test-rust-generation/rust/aws_s3_test"
echo "📂 Available directories:"
ls -la test-rust-generation/
if [ -d "test-rust-generation/rust" ]; then
echo "📂 In rust directory:"
ls -la test-rust-generation/rust/
fi
exit 1
fi
44 changes: 44 additions & 0 deletions pack-rust-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
# Docker-based pack script for Rust bindings generation
set -eu

echo "🦀 Generating Rust bindings for AWS CDK using custom jsii-pacmak (Docker)"

RUST_OUTPUT_DIR="$(pwd)/aws-cdk-rust-bindings"
mkdir -p "$RUST_OUTPUT_DIR"

echo "🐳 Running build inside Docker container..."

docker run -it --rm \
-v "$(pwd)":/aws-cdk \
-v "/home/clear/jsii":/jsii \
-v "$RUST_OUTPUT_DIR":/output \
--user "$(id -u):$(id -g)" \
-e HOME=/tmp \
-e YARN_CACHE_FOLDER=/tmp/.yarn-cache \
-w /aws-cdk \
jsii/superchain:local \
bash -c "
echo '📦 Installing AWS CDK dependencies...'
yarn install

echo '🔨 Building aws-cdk-lib...'
npx lerna run build --scope aws-cdk-lib --include-dependencies --stream

echo '🦀 Generating Rust bindings...'
echo 'Using jsii-pacmak: /jsii/packages/jsii-pacmak/bin/jsii-pacmak'
echo 'Output directory: /output'

# Generate Rust bindings using our custom jsii-pacmak
NODE_PATH=/jsii/packages/jsii-pacmak/node_modules:\$NODE_PATH \
node /jsii/packages/jsii-pacmak/bin/jsii-pacmak \
--verbose \
--targets rust \
--code-only \
--output /output \
./packages/aws-cdk-lib
"

echo "✅ Rust bindings generated in $RUST_OUTPUT_DIR"
echo "📁 Contents:"
ls -la "$RUST_OUTPUT_DIR"
93 changes: 93 additions & 0 deletions packages/@jsii/rust-runtime-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Jsii Rust Runtime Tests

This package contains compliance tests for the Rust jsii runtime implementation, following the [AWS jsii Language Implementation Guide](https://aws.github.io/jsii/user-guides/language-support/).

## Overview

The tests in this package verify that the Rust jsii runtime correctly implements the jsii protocol and provides consistent behavior with other language runtimes (Java, Go, Python, .NET).

## Structure

```
packages/@jsii/rust-runtime-test/
├── project/ # Rust test project
│ ├── src/
│ │ ├── lib.rs # Test utilities and re-exports
│ │ └── compliance_tests.rs # Standard compliance tests
│ └── Cargo.toml # Dependencies and configuration
├── build-tools/
│ └── gen-calc.js # Generates jsii-calc Rust bindings
└── package.json # NPM package configuration
```

## Development Phases

### Phase 1: Basic Infrastructure ✅
- [x] Create runtime test package structure
- [x] Set up basic jsii runtime library
- [x] Implement 5 fundamental compliance tests (stubs)
- [x] Establish testing framework

### Phase 2: Core Runtime (In Progress)
- [ ] Implement actual jsii-runtime process communication
- [ ] Handle basic jsii protocol messages
- [ ] Get first 5 compliance tests passing
- [ ] Generate jsii-calc Rust bindings

### Phase 3: Expand Coverage
- [ ] Implement collections (arrays, maps)
- [ ] Add class and interface support
- [ ] Handle error scenarios
- [ ] Pass 20+ core compliance tests

### Phase 4: Full Compliance
- [ ] Implement async operations
- [ ] Add property overrides
- [ ] Handle union types
- [ ] Pass 80%+ of Standard Compliance Suite

## Fundamental Compliance Tests

The 5 basic tests that must pass first:

1. **`test_jsii_agent`** - Verify jsii runtime starts and handshake works
2. **`test_primitive_types`** - Handle basic types (bool, string, number)
3. **`test_call_methods`** - Invoke methods on jsii objects
4. **`test_statics`** - Call static methods and access static properties
5. **`test_get_set_primitive_properties`** - Get/set object properties

## Running Tests

```bash
# Run basic compliance tests
cd project && cargo test

# Generate jsii-calc bindings (when runtime is ready)
yarn build

# Run with generated bindings
cd project && cargo test --features jsii_calc
```

## Current Status

- ✅ **Code Generation**: Rust target generates valid, compilable code
- 🔄 **Runtime Stubs**: Basic protocol structures implemented
- ⏳ **Protocol Communication**: Need to implement actual jsii-runtime process communication
- ⏳ **Type Conversion**: Need Rust ↔ jsii JSON type mapping
- ⏳ **Object Lifecycle**: Need proper object reference management

## Next Steps

1. **Implement actual jsii communication** (reuse existing Rust CDK code)
2. **Get `test_jsii_agent` passing** (verify handshake works)
3. **Implement basic type conversion** (string, number, bool)
4. **Get `test_primitive_types` passing**
5. **Add object creation and method calls**

## Related Documentation

- [AWS jsii Language Implementation Guide](https://aws.github.io/jsii/user-guides/language-support/)
- [jsii Standard Compliance Suite](https://github.com/aws/jsii/blob/main/gh-pages/content/specification/4-standard-compliance-suite.md)
- [Go Runtime Tests](../go-runtime-test/) (reference implementation)
- [Python Runtime Tests](../python-runtime/tests/) (reference implementation)
32 changes: 32 additions & 0 deletions packages/@jsii/rust-runtime-test/build-tools/gen-calc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env node
const { execSync } = require('child_process');
const { removeSync } = require('fs-extra');
const { join, resolve } = require('path');

const genRoot = join(__dirname, '..', 'jsii-calc');

// Clean previous generation
removeSync(genRoot);

console.log('🦀 Generating Rust bindings for jsii-calc...');

// Generate Rust bindings for jsii-calc
try {
execSync([
'npx jsii-pacmak',
'-t rust',
'-v',
'-c',
'-o', genRoot,
'--recurse',
resolve(__dirname, '..', '..', '..', 'jsii-calc')
].join(' '), {
stdio: 'inherit',
cwd: __dirname
});

console.log('✅ Rust bindings generated successfully!');
} catch (error) {
console.error('❌ Failed to generate Rust bindings:', error.message);
process.exit(1);
}
23 changes: 23 additions & 0 deletions packages/@jsii/rust-runtime-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@jsii/rust-runtime-test",
"version": "0.0.0",
"private": true,
"description": "jsii runtime tests for Rust",
"scripts": {
"build": "yarn gen:calc",
"fmt": "cd project && cargo fmt",
"lint": "cd project && cargo clippy -- -D warnings",
"test": "cd project && cargo test",
"lint:fix": "yarn lint && yarn fmt",
"gen:calc": "node build-tools/gen-calc.js"
},
"keywords": [],
"author": "",
"license": "Apache-2.0",
"devDependencies": {
"jsii-pacmak": "^0.0.0"
},
"dependencies": {
"fs-extra": "^10.1.0"
}
}
1 change: 1 addition & 0 deletions packages/@jsii/rust-runtime-test/project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
Loading