Skip to content

Commit

Permalink
compile-time config
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszcz committed Oct 14, 2024
1 parent 8353914 commit 58c1d20
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"wasm": true,
"rust": true
}
22 changes: 22 additions & 0 deletions config/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

# This script should be run from the root of the project

if [ `basename "$PWD"` != "juvix" ] || [ ! -d "config" ]; then
echo "This script should be run from the root of the project"
exit 1
fi

if clang -target wasm32-wasi --print-supported-cpus >/dev/null 2>&1; then
WASM="true"
else
WASM="false"
fi

if rustc --version >/dev/null 2>&1; then
RUST="true"
else
RUST="false"
fi

printf "{\n \"wasm\": $WASM,\n \"rust\": $RUST\n}\n" > config/config.json
2 changes: 2 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ extra-source-files:
- runtime/vampir/*.pir
- runtime/casm/*.casm
- runtime/nockma/*.nockma
- config/config.json
- config/configure.sh

dependencies:
- aeson-better-errors == 0.9.*
Expand Down
28 changes: 28 additions & 0 deletions src/Juvix/Config.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Juvix.Config where

import Data.Aeson
import Data.ByteString.Lazy qualified as BL
import Data.FileEmbed qualified as FE
import Juvix.Prelude

data Config = Config
{ _configWasm :: Bool,
_configRust :: Bool
}
deriving stock (Show, Eq, Generic)

makeLenses ''Config

instance FromJSON Config where
parseJSON = genericParseJSON opts
where
opts =
defaultOptions
{ fieldLabelModifier = map toLower . dropPrefix "_config"
}

config :: Config
config =
fromMaybe (Config False False) $
decode $
BL.fromStrict $(FE.makeRelativeToProject "config/config.json" >>= FE.embedFile)

0 comments on commit 58c1d20

Please sign in to comment.