Skip to content

Commit

Permalink
Move starknet/rust deps to separate package (#2148)
Browse files Browse the repository at this point in the history
Co-authored-by: Mario Apra <mariotapra@gmail.com>
  • Loading branch information
weiihann and derrix060 authored Oct 3, 2024
1 parent 262c51f commit 7e9652c
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/find-smallest-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- .github/workflows/find-smallest-rust.yml
- core/rust/*
- vm/rust/*
- starknet/rust/*
- starknet/compiler/rust/*
workflow_dispatch:

concurrency:
Expand All @@ -24,7 +24,7 @@ jobs:
id: rust-version
uses: derrix060/detect-rust-minimum-version@v1
with:
paths: core/rust/,vm/rust/,starknet/rust/
paths: core/rust/,vm/rust/,starknet/compiler/rust/
- name: Send notification on PR
uses: actions/github-script@v7
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/juno-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
workspaces: |
vm/rust
core/rust
starknet/rust
starknet/compiler/rust
- name: Install deps
run: make install-deps
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ core-rust:
$(MAKE) -C core/rust $(VM_TARGET)

compiler:
$(MAKE) -C starknet/rust $(VM_TARGET)
$(MAKE) -C starknet/compiler/rust $(VM_TARGET)

generate: ## generate
mkdir -p mocks
Expand Down Expand Up @@ -94,13 +94,13 @@ tidy: ## add missing and remove unused modules
format: ## run go & rust formatters
$(MAKE) -C vm/rust format
$(MAKE) -C core/rust format
$(MAKE) -C starknet/rust format
$(MAKE) -C starknet/compiler/rust format
gofumpt -l -w .

clean: ## clean project builds
$(MAKE) -C vm/rust clean
$(MAKE) -C core/rust clean
$(MAKE) -C starknet/rust clean
$(MAKE) -C starknet/compiler/rust clean
@rm -rf ./build

help: ## show this help
Expand Down
3 changes: 2 additions & 1 deletion adapters/p2p2core/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/p2p/starknet/spec"
"github.com/NethermindEth/juno/starknet"
"github.com/NethermindEth/juno/starknet/compiler"
"github.com/NethermindEth/juno/utils"
)

Expand Down Expand Up @@ -110,7 +111,7 @@ func createCompiledClass(cairo1 *spec.Cairo1Class) (*core.CompiledClass, error)
Version: cairo1.ContractClassVersion,
}

compiledClass, err := starknet.Compile(def)
compiledClass, err := compiler.Compile(def)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion rpc/class.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/NethermindEth/juno/core/felt"
"github.com/NethermindEth/juno/jsonrpc"
"github.com/NethermindEth/juno/starknet"
"github.com/NethermindEth/juno/starknet/compiler"
"github.com/NethermindEth/juno/utils"
)

Expand Down Expand Up @@ -49,7 +50,7 @@ func adaptDeclaredClass(declaredClass json.RawMessage) (core.Class, error) {

switch {
case feederClass.V1 != nil:
compiledClass, cErr := starknet.Compile(feederClass.V1)
compiledClass, cErr := compiler.Compile(feederClass.V1)
if cErr != nil {
return nil, cErr
}
Expand Down
10 changes: 6 additions & 4 deletions starknet/compiler.go → starknet/compiler/compiler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package starknet
package compiler

/*
#include <stdint.h>
Expand All @@ -19,10 +19,12 @@ import (
"encoding/json"
"errors"
"unsafe"

"github.com/NethermindEth/juno/starknet"
)

func Compile(sierra *SierraDefinition) (*CompiledClass, error) {
sierraJSON, err := json.Marshal(SierraDefinition{
func Compile(sierra *starknet.SierraDefinition) (*starknet.CompiledClass, error) {
sierraJSON, err := json.Marshal(starknet.SierraDefinition{
EntryPoints: sierra.EntryPoints,
Program: sierra.Program,
Version: sierra.Version,
Expand All @@ -45,7 +47,7 @@ func Compile(sierra *SierraDefinition) (*CompiledClass, error) {

casmJSON := C.GoString(result)

var casmClass CompiledClass
var casmClass starknet.CompiledClass
if err := json.Unmarshal([]byte(casmJSON), &casmClass); err != nil {
return nil, err
}
Expand Down
11 changes: 6 additions & 5 deletions starknet/compiler_test.go → starknet/compiler/compiler_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package starknet_test
package compiler_test

import (
"context"
Expand All @@ -10,14 +10,15 @@ import (
"github.com/NethermindEth/juno/adapters/sn2core"
"github.com/NethermindEth/juno/clients/feeder"
"github.com/NethermindEth/juno/starknet"
"github.com/NethermindEth/juno/starknet/compiler"
"github.com/NethermindEth/juno/utils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestCompile(t *testing.T) {
t.Run("zero sierra", func(t *testing.T) {
_, err := starknet.Compile(&starknet.SierraDefinition{})
_, err := compiler.Compile(&starknet.SierraDefinition{})
require.Error(t, err)
})

Expand All @@ -33,7 +34,7 @@ func TestCompile(t *testing.T) {
expectedCompiled, err := sn2core.AdaptCompiledClass(compiledDef)
require.NoError(t, err)

res, err := starknet.Compile(classDef.V1)
res, err := compiler.Compile(classDef.V1)
require.NoError(t, err)

gotCompiled, err := sn2core.AdaptCompiledClass(res)
Expand All @@ -45,7 +46,7 @@ func TestCompile(t *testing.T) {
// tests https://github.com/NethermindEth/juno/issues/1748
definition := loadTestData[starknet.SierraDefinition](t, "declare_cairo2_definition.json")

_, err := starknet.Compile(&definition)
_, err := compiler.Compile(&definition)
require.NoError(t, err)
})
}
Expand All @@ -54,7 +55,7 @@ func TestCompile(t *testing.T) {
func loadTestData[T any](t *testing.T, filename string) T {
t.Helper()

file := fmt.Sprintf("./testdata/%s", filename)
file := fmt.Sprintf("../testdata/%s", filename)
buff, err := os.ReadFile(file)
if err != nil {
t.Fatalf("Failed to read file %s: %v", file, err)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 7e9652c

Please sign in to comment.