Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

feat: rubiks cube sample #3

Merged
merged 16 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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: 4 additions & 0 deletions RubiksCube/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build
widget/dist
widget/node_modules
.vscode/
16 changes: 16 additions & 0 deletions RubiksCube/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Rubiks cube visualiser

This project is a demo for showing rubiks cubes in the lean infoview.
Inspired by the [rubiks-cube-group](https://github.com/kendfrey/rubiks-cube-group) by Kendal Frey.

## Building

In order to install you need [Lean](https://leanprover.github.io/lean4/doc/quickstart.html) and [npm](https://npmjs.com).
You also need to be using VSCode (or a gitpod).

```
cd widget
npm i
cd ..
lake build
```
21 changes: 21 additions & 0 deletions RubiksCube/Rubiks.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Lean
open Lean Elab

elab (name := includeStr) "include_str " str:str : term => do
let some str := str.isStrLit? | Lean.Elab.throwUnsupportedSyntax
let ctx ← readThe Lean.Core.Context
let srcPath := System.FilePath.mk ctx.fileName
let some srcDir := srcPath.parent | throwError "{srcPath} not in a valid directory"
let path := srcDir / str
Lean.mkStrLit <$> IO.FS.readFile path

@[widgetSource]
def rubiks : String := include_str "./widget/dist/rubiks.js"

structure RubiksProps where
seq : Array String := #[]
deriving ToJson, FromJson, Inhabited

def eg : RubiksProps := {seq := #["U", "L", "D⁻¹", "U⁻¹", "L", "D", "D", "L", "U⁻¹", "R", "D", "F", "F", "D"]}

#widget rubiks (toJson eg)
23 changes: 23 additions & 0 deletions RubiksCube/lakefile.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Lake
open System Lake DSL

def jsTarget (pkgDir : FilePath) : FileTarget :=
let jsFile := pkgDir / "widget/dist/rubiks.js"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work on windows, perhaps this would be better:

  let jsFile := pkgDir / "widget" / "dist" / "rubiks.js"
  let srcFiles := inputFileTarget <| pkgDir / "widget" / "src" / "rubiks.tsx"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the proposed change is good, but we also need this fix in lean for it to work: leanprover/lean4#1257

let srcFiles := inputFileTarget <| pkgDir / "widget/src/rubiks.tsx"
fileTargetWithDep jsFile srcFiles fun _srcFile => do
proc {
cmd := "npm"
args := #["install"]
cwd := some <| pkgDir / "widget"
}
proc {
cmd := "npm"
args := #["run", "build"]
cwd := some <| pkgDir / "widget"
}

package Rubiks (pkgDir) {
extraDepTarget := jsTarget pkgDir |>.withoutInfo
defaultFacet := PackageFacet.oleans
dependencies := #[ ]
}
1 change: 1 addition & 0 deletions RubiksCube/lean-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
leanprover/lean4:nightly-2022-06-21
Loading