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
9 changes: 2 additions & 7 deletions .github/workflows/git-clean.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
name: Git is clean
on: [push]

jobs:
git-clean:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- uses: nixbuild/nix-quick-install-action@v30
with:
nix_conf: |
Expand All @@ -26,12 +23,10 @@ jobs:
# before trying to save a new cache
# 1G = 1073741824
gc-max-store-size-linux: 1G

- run: nix develop -c forge soldeer install
- run: nix develop -c forge script ./script/BuildPointers.sol

# Format the repo after generating pointers so that the pointer files are
# formatted too.
- run: nix develop -c forge fmt

# Check if the repo is clean after generating pointers and formatting.
- run: git diff --exit-code
- run: git diff --exit-code
9 changes: 9 additions & 0 deletions .github/workflows/publish-soldeer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Publish to Soldeer
on:
push:
tags:
- "v*"
jobs:
publish:
uses: rainlanguage/rainix/.github/workflows/publish-soldeer.yaml@main
secrets: inherit
39 changes: 3 additions & 36 deletions .github/workflows/rainix.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
name: Rainix CI
name: rainix
on: [push]

jobs:
rainix:
strategy:
matrix:
os: [ubuntu-latest]
task: [rainix-sol-test, rainix-sol-static, rainix-sol-legal]
fail-fast: false
runs-on: ${{ matrix.os }}
env:
DEPLOYMENT_KEY: ${{ github.ref == 'refs/heads/main' && secrets.PRIVATE_KEY || secrets.PRIVATE_KEY_DEV }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- uses: nixbuild/nix-quick-install-action@v30
with:
nix_conf: |
keep-env-derivations = true
keep-outputs = true
- name: Restore and save Nix store
uses: nix-community/cache-nix-action@v6
with:
# restore and save a cache using this key
primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock') }}
# if there's no cache hit, restore a cache by this prefix
restore-prefixes-first-match: nix-${{ runner.os }}-
# collect garbage until the Nix store size (in bytes) is at most this number
# before trying to save a new cache
# 1G = 1073741824
gc-max-store-size-linux: 1G

- run: nix develop -c rainix-sol-prelude
- name: Run ${{ matrix.task }}
run: nix develop -c ${{ matrix.task }}
uses: rainlanguage/rainix/.github/workflows/rainix-sol.yaml@main
secrets: inherit
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
cache
out
dependencies
out
.pre-commit-config.yaml
6 changes: 0 additions & 6 deletions .gitmodules

This file was deleted.

26 changes: 26 additions & 0 deletions .soldeerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.DS_Store
.coderabbitai.yaml
.gas-snapshot
.git
.github
.gitignore
.gitmodules
.pre-commit-config.yaml
.soldeerignore
.vscode
CLAUDE.md
/audit
/cache
/dependencies
/docs
/flake.lock
/flake.nix
/foundry.lock
/foundry.toml
/lib
/out
/remappings.txt
/slither.config.json
/soldeer.lock
/target
/test
77 changes: 62 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,68 @@
# rain.sol.codegen

Solidity native tooling to generate Solidity code.
Solidity-native tooling to generate Solidity source. Builds a valid `.sol` file
(pragma + foundry-clean formatting) that hosts the constant caches for prebuilt
function-pointer tables — needed for runtime gas efficiency in the Rain
interpreter.

Notably builds a valid Solidity file (pragma, etc.) that passes foundry
formatting cleanly, that can build the constant caches needed for prebuilt
function pointer tables to ensure runtime gas efficiency.
Also exposes interfaces (interpreter, sub-parsers, externs) for Rain contracts
to implement against the generated code.

Includes interfaces for the interpreter and sub parsers/externs for Rain
contracts to implement and be compatible with the code generation functions here.
`script/BuildPointers.sol` is an example implementation;
`.github/workflows/git-clean.yaml` is an example CI guard that fails when the
committed pointer artifacts drift from a fresh regeneration.

`script/BuildPointers.sol` includes an example implementation and
`.github/workflows/git-clean.yaml` an example CI action to show how to build
pointers cleanly and ensure that the source code does not become out of sync with
the built artifacts when merging new code.
Generated code is imported downstream by contracts that themselves expose
pointers, which pointers feed back into the generation. This cycle means
pointers may need to be regenerated several times until they reach a fixed point
where neither pointer values nor the codehash of any consuming contract shift.

Generated code is intended to be imported downstream into contracts that may
themselves expose pointers to be included in the generated code. This circular
dependency means the pointers may need to be built several times until they
produce a stable output where the pointers do not move, and therefore do not
break the codehash over the contract that includes the pointers.
## Install

Via [soldeer](https://soldeer.xyz):

```sh
forge soldeer install rain-sol-codegen~<version>
```

## Develop

This repo uses [nix](https://nixos.org/download.html). The default shell is the
slim `sol-shell` from [rainix](https://github.com/rainlanguage/rainix).

```sh
nix develop # enter the shell
forge soldeer install # install deps declared in foundry.toml
forge build
```

Tasks:

- `rainix-sol-static` — slither
- `rainix-sol-legal` — `reuse lint`

This repo has no `forge test` suite — the code is tooling exercised by
downstream consumers' generated artifacts.

Use the nix-pinned `forge` for all development.

## Publish

Tag `v<x.y.z>` on `main`. The
[`Publish to Soldeer`](.github/workflows/publish-soldeer.yaml) wrapper delegates
to rainix's reusable workflow, which derives the package name from the repo name
(`rain.sol.codegen` → `rain-sol-codegen`).

## License

DecentraLicense 1.0 (DCL-1.0) — full text in
[`LICENSES/`](LICENSES/LicenseRef-DCL-1.0.txt). Roughly `CAL-1.0`
([opensource.org](https://opensource.org/license/cal-1-0)) plus user-data
disclosure obligations consistent with permissionless-blockchain assumptions.

This repo is [REUSE 3.2](https://reuse.software/spec-3.2/) compliant. Verify
locally:

```sh
nix develop -c rainix-sol-legal
```
29 changes: 16 additions & 13 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ version = 1

[[annotations]]
path = [
".gas-snapshot",
".github/workflows/**/",
".gitignore",
".gitmodules",
"audit/**/",
"README.md",
"flake.lock",
"flake.nix",
"foundry.toml",
"slither.config.json",
"REUSE.toml",
"src/lib/LibCodeGen.sol",
"foundry.lock",
".gas-snapshot",
".github/workflows/**/",
".gitignore",
".gitmodules",
".soldeerignore",
"audit/**/",
"README.md",
"flake.lock",
"flake.nix",
"foundry.toml",
"remappings.txt",
"slither.config.json",
"REUSE.toml",
"src/lib/LibCodeGen.sol",
"foundry.lock",
"soldeer.lock",
]
SPDX-FileCopyrightText = "Copyright (c) 2020 Rain Open Source Software Ltd"
SPDX-License-Identifier = "LicenseRef-DCL-1.0"
Loading
Loading