diff --git a/.editorconfig b/.editorconfig index 2d877d20b825..6972df7013d6 100644 --- a/.editorconfig +++ b/.editorconfig @@ -89,6 +89,10 @@ trim_trailing_whitespace = unset end_of_line = unset insert_final_newline = unset +# see https://manual.jule.dev/project/code-style.html#indentions +[*.jule] +indent_style = tab + # Keep this hint at the bottom: # Please don't add entries for subfolders here. # Create /.editorconfig instead. diff --git a/doc/hooks/index.md b/doc/hooks/index.md index cd04fd84495a..cd769cec0373 100644 --- a/doc/hooks/index.md +++ b/doc/hooks/index.md @@ -20,6 +20,7 @@ ghc.section.md gnome.section.md haredo.section.md installShellFiles.section.md +julec.section.md just.section.md libiconv.section.md libxml2.section.md diff --git a/doc/hooks/julec.section.md b/doc/hooks/julec.section.md new file mode 100644 index 000000000000..f85619ac39e7 --- /dev/null +++ b/doc/hooks/julec.section.md @@ -0,0 +1,77 @@ +# julec.hook {#julec-hook} + +[Jule](https://jule.dev) is an effective programming language designed to build efficient, fast, reliable and safe software while maintaining simplicity. + +In Nixpkgs, `jule.hook` overrides the default build, check and install phases. + +## Example code snippet {#julec-hook-example-code-snippet} + +```nix +{ + julec, + clangStdenv, +}: + +clangStdenv.mkDerivation (finalAttrs: { + # ... + + nativeBuildInputs = [ julec.hook ]; + + # Customize filenames if needed + JULE_SRC_DIR = "./src"; + JULE_OUT_DIR = "./bin"; + JULE_OUT_NAME = "hello-jule"; + JULE_TEST_DIR = "./tests"; + JULE_TEST_OUT_DIR = "./test-bin"; + JULE_TEST_OUT_NAME = "hello-jule-test"; + + # ... +}) +``` + +## Variables controlling julec.hook {#julec-hook-variables} + +### `JULE_SRC_DIR` {#julec-hook-variable-jule-src-dir} + +Specifies the source directory containing `main.jule`. +Default is `./src`. + +### `JULE_OUT_DIR` {#julec-hook-variable-jule-out-dir} + +Specifies the output directory for the compiled binary. +Default is `./bin`. + +### `JULE_OUT_NAME` {#julec-hook-variable-jule-out-name} + +Specifies the name of the compiled binary. +Default is `output`. + +### `JULE_TEST_DIR` {#julec-hook-variable-jule-test-dir} + +Specifies the directory containing test files. +Default is the value of [`JULE_SRC_DIR`](#julec-hook-variable-jule-src-dir). + +### `JULE_TEST_OUT_DIR` {#julec-hook-variable-jule-test-out-dir} + +Specifies the output directory for compiled test binaries. +Default is the value of [`JULE_OUT_DIR`](#julec-hook-variable-jule-out-dir). + +### `JULE_TEST_OUT_NAME` {#julec-hook-variable-jule-test-out-name} + +Specifies the name of the compiled test binary. +Default is the value of [`JULE_OUT_NAME`](#julec-hook-variable-jule-out-name) with `-test` suffix. + +### `dontUseJulecBuild` {#julec-hook-variable-dontusejulecbuild} + +When set to true, doesn't use the predefined `julecBuildHook`. +Default is false. + +### `dontUseJulecCheck` {#julec-hook-variable-dontusejuleccheck} + +When set to true, doesn't use the predefined `julecCheckHook`. +Default is false. + +### `dontUseJulecInstall` {#julec-hook-variable-dontusejulecinstall} + +When set to true, doesn't use the predefined `julecInstallHook`. +Default is false. diff --git a/doc/redirects.json b/doc/redirects.json index b4cec3d403eb..4198cee6ca48 100644 --- a/doc/redirects.json +++ b/doc/redirects.json @@ -124,6 +124,42 @@ "inkscape-plugins": [ "index.html#inkscape-plugins" ], + "julec-hook": [ + "index.html#julec-hook" + ], + "julec-hook-example-code-snippet": [ + "index.html#julec-hook-example-code-snippet" + ], + "julec-hook-variable-dontusejulecbuild": [ + "index.html#julec-hook-variable-dontusejulecbuild" + ], + "julec-hook-variable-dontusejuleccheck": [ + "index.html#julec-hook-variable-dontusejuleccheck" + ], + "julec-hook-variable-dontusejulecinstall": [ + "index.html#julec-hook-variable-dontusejulecinstall" + ], + "julec-hook-variable-jule-out-dir": [ + "index.html#julec-hook-variable-jule-out-dir" + ], + "julec-hook-variable-jule-out-name": [ + "index.html#julec-hook-variable-jule-out-name" + ], + "julec-hook-variable-jule-src-dir": [ + "index.html#julec-hook-variable-jule-src-dir" + ], + "julec-hook-variable-jule-test-dir": [ + "index.html#julec-hook-variable-jule-test-dir" + ], + "julec-hook-variable-jule-test-out-dir": [ + "index.html#julec-hook-variable-jule-test-out-dir" + ], + "julec-hook-variable-jule-test-out-name": [ + "index.html#julec-hook-variable-jule-test-out-name" + ], + "julec-hook-variables": [ + "index.html#julec-hook-variables" + ], "major-ghc-deprecation": [ "index.html#major-ghc-deprecation" ], diff --git a/pkgs/by-name/ju/julec/hook.nix b/pkgs/by-name/ju/julec/hook.nix new file mode 100644 index 000000000000..d6cccb165979 --- /dev/null +++ b/pkgs/by-name/ju/julec/hook.nix @@ -0,0 +1,15 @@ +{ + julec, + clang, + makeSetupHook, +}: + +makeSetupHook { + name = "julec-hook"; + + propagatedBuildInputs = [ julec ]; + + meta = { + inherit (julec.meta) maintainers; + }; +} ./hook.sh diff --git a/pkgs/by-name/ju/julec/hook.sh b/pkgs/by-name/ju/julec/hook.sh new file mode 100644 index 000000000000..112dc48d0c81 --- /dev/null +++ b/pkgs/by-name/ju/julec/hook.sh @@ -0,0 +1,80 @@ +# shellcheck shell=bash disable=SC2154,SC2034 + +julecSetEnv() { + if [ -z "$JULE_SRC_DIR" ]; then + export JULE_SRC_DIR='./src' + fi + if [ -z "$JULE_OUT_DIR" ]; then + export JULE_OUT_DIR='./bin' + fi + if [ -z "$JULE_OUT_NAME" ]; then + export JULE_OUT_NAME='output' + fi + if [ -z "$JULE_TEST_DIR" ]; then + export JULE_TEST_DIR="$JULE_SRC_DIR" + fi + if [ -z "$JULE_TEST_OUT_DIR" ]; then + export JULE_TEST_OUT_DIR="$JULE_OUT_DIR" + fi + if [ -z "$JULE_TEST_OUT_NAME" ]; then + export JULE_TEST_OUT_NAME="$JULE_OUT_NAME-test" + fi +} + +julecBuildHook() { + echo "Executing julecBuildHook" + + runHook preBuild + + julecSetEnv + mkdir -p "$JULE_OUT_DIR" + julec --opt L2 -p -o "$JULE_OUT_DIR/$JULE_OUT_NAME" "$JULE_SRC_DIR" + + runHook postBuild + + echo "Finished julecBuildHook" +} + +julecCheckHook() { + echo "Executing julecCheckHook" + + runHook preCheck + + echo "Building tests..." + + julecSetEnv + mkdir -p "$JULE_TEST_OUT_DIR" + julec test -o "$JULE_TEST_OUT_DIR/$JULE_TEST_OUT_NAME" "$JULE_TEST_DIR" + + echo "Running tests..." + + "$JULE_TEST_OUT_DIR/$JULE_TEST_OUT_NAME" + + runHook postCheck + + echo "Finished julecCheckHook" +} + +julecInstallHook() { + echo "Executing julecInstallHook" + + runHook preInstall + + julecSetEnv + mkdir -p "$out/bin" + cp -r "$JULE_OUT_DIR/$JULE_OUT_NAME" "$out/bin/" + + runHook postInstall + + echo "Finished julecInstallHook" +} + +if [ -z "${dontUseJulecBuild-}" ] && [ -z "${buildPhase-}" ]; then + buildPhase=julecBuildHook +fi +if [ -z "${dontUseJulecCheck-}" ] && [ -z "${checkPhase-}" ]; then + checkPhase=julecCheckHook +fi +if [ -z "${dontUseJulecInstall-}" ] && [ -z "${installPhase-}" ]; then + installPhase=julecInstallHook +fi diff --git a/pkgs/by-name/ju/julec/package.nix b/pkgs/by-name/ju/julec/package.nix index 27a007a791ee..e22298483855 100644 --- a/pkgs/by-name/ju/julec/package.nix +++ b/pkgs/by-name/ju/julec/package.nix @@ -1,6 +1,7 @@ { lib, clangStdenv, + callPackage, fetchFromGitHub, }: @@ -93,6 +94,12 @@ clangStdenv.mkDerivation (finalAttrs: { runHook postInstall ''; + passthru = { + # see doc/hooks/julec.section.md + hook = callPackage ./hook.nix { julec = finalAttrs.finalPackage; }; + tests.hello-jule = callPackage ./test { julec = finalAttrs.finalPackage; }; + }; + meta = { description = "Jule Programming Language Compiler"; longDescription = '' diff --git a/pkgs/by-name/ju/julec/test/default.nix b/pkgs/by-name/ju/julec/test/default.nix new file mode 100644 index 000000000000..6717600389c9 --- /dev/null +++ b/pkgs/by-name/ju/julec/test/default.nix @@ -0,0 +1,19 @@ +{ + julec, + clangStdenv, +}: + +clangStdenv.mkDerivation (finalAttrs: { + pname = "hello-jule"; + inherit (julec) version; + + src = ./hello-jule; + + nativeBuildInputs = [ julec.hook ]; + + doCheck = true; + + meta = { + inherit (julec.meta) platforms; + }; +}) diff --git a/pkgs/by-name/ju/julec/test/hello-jule/jule.mod b/pkgs/by-name/ju/julec/test/hello-jule/jule.mod new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/pkgs/by-name/ju/julec/test/hello-jule/src/_test.jule b/pkgs/by-name/ju/julec/test/hello-jule/src/_test.jule new file mode 100644 index 000000000000..53b23c3cf884 --- /dev/null +++ b/pkgs/by-name/ju/julec/test/hello-jule/src/_test.jule @@ -0,0 +1,8 @@ +use "std/testing" + +#test +fn testPi(t: &testing::T) { + if getPi() != 3.14 { + t.Errorf("PI not precise enough") + } +} diff --git a/pkgs/by-name/ju/julec/test/hello-jule/src/main.jule b/pkgs/by-name/ju/julec/test/hello-jule/src/main.jule new file mode 100644 index 000000000000..322bd3111649 --- /dev/null +++ b/pkgs/by-name/ju/julec/test/hello-jule/src/main.jule @@ -0,0 +1,7 @@ +fn main() { + println("Hello, Jule!"); +} + +fn getPi(): f64 { + ret 3.14; +}