diff --git a/config/config.json b/config/config.json new file mode 100644 index 0000000000..489b6c5677 --- /dev/null +++ b/config/config.json @@ -0,0 +1,4 @@ +{ + "wasm": true, + "rust": true +} diff --git a/config/configure.sh b/config/configure.sh new file mode 100755 index 0000000000..709970eae5 --- /dev/null +++ b/config/configure.sh @@ -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 diff --git a/package.yaml b/package.yaml index 2237be6719..faeee7bcb3 100644 --- a/package.yaml +++ b/package.yaml @@ -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.* diff --git a/src/Juvix/Config.hs b/src/Juvix/Config.hs new file mode 100644 index 0000000000..362fe8df7d --- /dev/null +++ b/src/Juvix/Config.hs @@ -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)