-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Closes #3077 * Closes #3100 * Adds a compilation-time configuration script that creates a `config/config.json` file which is then read by the `Makefile`/`justfile` and embedded into the Juvix binary.
- Loading branch information
Showing
28 changed files
with
344 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Commands.Compile.RiscZeroRust.Rust where | ||
|
||
import Commands.Base | ||
import Commands.Compile.RiscZeroRust.Options | ||
import Commands.Extra.NewCompile | ||
import Data.FileEmbed qualified as FE | ||
|
||
compileRustCode :: forall k r. (Members '[App, TaggedLock, EmbedIO] r) => RiscZeroRustOptions k -> Maybe (AppPath File) -> Text -> Sem r () | ||
compileRustCode opts inputFile code = do | ||
let moutputDir = opts ^. riscZeroRustOutputDir | ||
outDir :: Path Abs Dir <- getOutputDir FileExtRiscZero inputFile moutputDir | ||
writeDirFiles riscZeroDir outDir | ||
let outJuvixSourceDir :: Path Abs Dir = outDir <//> $(mkRelDir "juvix") <//> $(mkRelDir "src") | ||
writeDirFiles rustRuntimeSourceDir outJuvixSourceDir | ||
writeFile (outDir <//> $(mkRelDir "juvix") <//> $(mkRelFile "Cargo.toml")) rustRuntimeToml | ||
let outFile :: Path Abs File = | ||
outDir | ||
<//> $(mkRelDir "methods") | ||
<//> $(mkRelDir "guest") | ||
<//> $(mkRelDir "src") | ||
<//> $(mkRelFile "main.rs") | ||
writeFileEnsureLn outFile code | ||
where | ||
riscZeroDir :: [(FilePath, ByteString)] | ||
riscZeroDir = $(FE.makeRelativeToProject "runtime/rust/risc0" >>= FE.embedDir) | ||
|
||
rustRuntimeSourceDir :: [(FilePath, ByteString)] | ||
rustRuntimeSourceDir = $(FE.makeRelativeToProject "runtime/rust/juvix/src" >>= FE.embedDir) | ||
|
||
rustRuntimeToml :: ByteString | ||
rustRuntimeToml = $(FE.makeRelativeToProject "runtime/rust/juvix/Cargo.toml" >>= FE.embedFile) | ||
|
||
writeDirFiles :: [(FilePath, ByteString)] -> Path Abs Dir -> Sem r () | ||
writeDirFiles fs outDir = do | ||
let fs' = map (first relFile) fs | ||
forM_ (first (outDir <//>) <$> fs') (uncurry writeFile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Commands.Dev.Tree.Compile.RiscZeroRust where | ||
|
||
import Commands.Base | ||
import Commands.Compile.RiscZeroRust.Options | ||
import Commands.Compile.RiscZeroRust.Rust | ||
import Juvix.Compiler.Backend.Rust.Data.Result | ||
import Juvix.Compiler.Tree.Data.InfoTable | ||
import Juvix.Compiler.Tree.Translation.FromSource qualified as Tree | ||
|
||
runCommand :: | ||
(Members '[App, TaggedLock, EmbedIO] r) => | ||
RiscZeroRustOptions ('InputExtension 'FileExtJuvixTree) -> | ||
Sem r () | ||
runCommand opts = do | ||
let inputFile = Just $ opts ^. riscZeroRustCompileCommonOptions . compileInputFile | ||
mainFile <- getMainFile inputFile | ||
tab :: InfoTable <- readFile mainFile >>= getRight . Tree.runParser mainFile | ||
entrypoint <- | ||
applyOptions opts | ||
<$> getEntryPoint inputFile | ||
Result {..} <- | ||
getRight | ||
. run | ||
. runError @JuvixError | ||
. runReader entrypoint | ||
$ treeToRiscZeroRust tab | ||
compileRustCode opts inputFile _resultRustCode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.