Skip to content

Commit 155bcc6

Browse files
koibtwphiliptaron
andcommitted
julec.hook: init
Co-authored-by: philiptaron <philip.taron@gmail.com>
1 parent f1d065e commit 155bcc6

File tree

11 files changed

+254
-0
lines changed

11 files changed

+254
-0
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ trim_trailing_whitespace = unset
8989
end_of_line = unset
9090
insert_final_newline = unset
9191

92+
# see https://manual.jule.dev/project/code-style.html#indentions
93+
[*.jule]
94+
indent_style = tab
95+
9296
# Keep this hint at the bottom:
9397
# Please don't add entries for subfolders here.
9498
# Create <subfolder>/.editorconfig instead.

doc/hooks/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ghc.section.md
2020
gnome.section.md
2121
haredo.section.md
2222
installShellFiles.section.md
23+
julec.section.md
2324
just.section.md
2425
libiconv.section.md
2526
libxml2.section.md

doc/hooks/julec.section.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# julec.hook {#julec-hook}
2+
3+
[Jule](https://jule.dev) is an effective programming language designed to build efficient, fast, reliable and safe software while maintaining simplicity.
4+
5+
In Nixpkgs, `jule.hook` overrides the default build, check and install phases.
6+
7+
## Example code snippet {#julec-hook-example-code-snippet}
8+
9+
```nix
10+
{
11+
julec,
12+
clangStdenv,
13+
}:
14+
15+
clangStdenv.mkDerivation (finalAttrs: {
16+
# ...
17+
18+
nativeBuildInputs = [ julec.hook ];
19+
20+
# Customize filenames if needed
21+
JULE_SRC_DIR = "./src";
22+
JULE_OUT_DIR = "./bin";
23+
JULE_OUT_NAME = "hello-jule";
24+
JULE_TEST_DIR = "./tests";
25+
JULE_TEST_OUT_DIR = "./test-bin";
26+
JULE_TEST_OUT_NAME = "hello-jule-test";
27+
28+
# ...
29+
})
30+
```
31+
32+
## Variables controlling julec.hook {#julec-hook-variables}
33+
34+
### `JULE_SRC_DIR` {#julec-hook-variable-jule-src-dir}
35+
36+
Specifies the source directory containing `main.jule`.
37+
Default is `./src`.
38+
39+
### `JULE_OUT_DIR` {#julec-hook-variable-jule-out-dir}
40+
41+
Specifies the output directory for the compiled binary.
42+
Default is `./bin`.
43+
44+
### `JULE_OUT_NAME` {#julec-hook-variable-jule-out-name}
45+
46+
Specifies the name of the compiled binary.
47+
Default is `output`.
48+
49+
### `JULE_TEST_DIR` {#julec-hook-variable-jule-test-dir}
50+
51+
Specifies the directory containing test files.
52+
Default is the value of [`JULE_SRC_DIR`](#julec-hook-variable-jule-src-dir).
53+
54+
### `JULE_TEST_OUT_DIR` {#julec-hook-variable-jule-test-out-dir}
55+
56+
Specifies the output directory for compiled test binaries.
57+
Default is the value of [`JULE_OUT_DIR`](#julec-hook-variable-jule-out-dir).
58+
59+
### `JULE_TEST_OUT_NAME` {#julec-hook-variable-jule-test-out-name}
60+
61+
Specifies the name of the compiled test binary.
62+
Default is the value of [`JULE_OUT_NAME`](#julec-hook-variable-jule-out-name) with `-test` suffix.
63+
64+
### `dontUseJulecBuild` {#julec-hook-variable-dontusejulecbuild}
65+
66+
When set to true, doesn't use the predefined `julecBuildHook`.
67+
Default is false.
68+
69+
### `dontUseJulecCheck` {#julec-hook-variable-dontusejuleccheck}
70+
71+
When set to true, doesn't use the predefined `julecCheckHook`.
72+
Default is false.
73+
74+
### `dontUseJulecInstall` {#julec-hook-variable-dontusejulecinstall}
75+
76+
When set to true, doesn't use the predefined `julecInstallHook`.
77+
Default is false.

doc/redirects.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,42 @@
124124
"inkscape-plugins": [
125125
"index.html#inkscape-plugins"
126126
],
127+
"julec-hook": [
128+
"index.html#julec-hook"
129+
],
130+
"julec-hook-example-code-snippet": [
131+
"index.html#julec-hook-example-code-snippet"
132+
],
133+
"julec-hook-variable-dontusejulecbuild": [
134+
"index.html#julec-hook-variable-dontusejulecbuild"
135+
],
136+
"julec-hook-variable-dontusejuleccheck": [
137+
"index.html#julec-hook-variable-dontusejuleccheck"
138+
],
139+
"julec-hook-variable-dontusejulecinstall": [
140+
"index.html#julec-hook-variable-dontusejulecinstall"
141+
],
142+
"julec-hook-variable-jule-out-dir": [
143+
"index.html#julec-hook-variable-jule-out-dir"
144+
],
145+
"julec-hook-variable-jule-out-name": [
146+
"index.html#julec-hook-variable-jule-out-name"
147+
],
148+
"julec-hook-variable-jule-src-dir": [
149+
"index.html#julec-hook-variable-jule-src-dir"
150+
],
151+
"julec-hook-variable-jule-test-dir": [
152+
"index.html#julec-hook-variable-jule-test-dir"
153+
],
154+
"julec-hook-variable-jule-test-out-dir": [
155+
"index.html#julec-hook-variable-jule-test-out-dir"
156+
],
157+
"julec-hook-variable-jule-test-out-name": [
158+
"index.html#julec-hook-variable-jule-test-out-name"
159+
],
160+
"julec-hook-variables": [
161+
"index.html#julec-hook-variables"
162+
],
127163
"major-ghc-deprecation": [
128164
"index.html#major-ghc-deprecation"
129165
],

pkgs/by-name/ju/julec/hook.nix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
julec,
3+
clang,
4+
makeSetupHook,
5+
}:
6+
7+
makeSetupHook {
8+
name = "julec-hook";
9+
10+
propagatedBuildInputs = [ julec ];
11+
12+
meta = {
13+
inherit (julec.meta) maintainers;
14+
};
15+
} ./hook.sh

pkgs/by-name/ju/julec/hook.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# shellcheck shell=bash disable=SC2154,SC2034
2+
3+
julecSetEnv() {
4+
if [ -z "$JULE_SRC_DIR" ]; then
5+
export JULE_SRC_DIR='./src'
6+
fi
7+
if [ -z "$JULE_OUT_DIR" ]; then
8+
export JULE_OUT_DIR='./bin'
9+
fi
10+
if [ -z "$JULE_OUT_NAME" ]; then
11+
export JULE_OUT_NAME='output'
12+
fi
13+
if [ -z "$JULE_TEST_DIR" ]; then
14+
export JULE_TEST_DIR="$JULE_SRC_DIR"
15+
fi
16+
if [ -z "$JULE_TEST_OUT_DIR" ]; then
17+
export JULE_TEST_OUT_DIR="$JULE_OUT_DIR"
18+
fi
19+
if [ -z "$JULE_TEST_OUT_NAME" ]; then
20+
export JULE_TEST_OUT_NAME="$JULE_OUT_NAME-test"
21+
fi
22+
}
23+
24+
julecBuildHook() {
25+
echo "Executing julecBuildHook"
26+
27+
runHook preBuild
28+
29+
julecSetEnv
30+
mkdir -p "$JULE_OUT_DIR"
31+
julec --opt L2 -p -o "$JULE_OUT_DIR/$JULE_OUT_NAME" "$JULE_SRC_DIR"
32+
33+
runHook postBuild
34+
35+
echo "Finished julecBuildHook"
36+
}
37+
38+
julecCheckHook() {
39+
echo "Executing julecCheckHook"
40+
41+
runHook preCheck
42+
43+
echo "Building tests..."
44+
45+
julecSetEnv
46+
mkdir -p "$JULE_TEST_OUT_DIR"
47+
julec test -o "$JULE_TEST_OUT_DIR/$JULE_TEST_OUT_NAME" "$JULE_TEST_DIR"
48+
49+
echo "Running tests..."
50+
51+
"$JULE_TEST_OUT_DIR/$JULE_TEST_OUT_NAME"
52+
53+
runHook postCheck
54+
55+
echo "Finished julecCheckHook"
56+
}
57+
58+
julecInstallHook() {
59+
echo "Executing julecInstallHook"
60+
61+
runHook preInstall
62+
63+
julecSetEnv
64+
mkdir -p "$out/bin"
65+
cp -r "$JULE_OUT_DIR/$JULE_OUT_NAME" "$out/bin/"
66+
67+
runHook postInstall
68+
69+
echo "Finished julecInstallHook"
70+
}
71+
72+
if [ -z "${dontUseJulecBuild-}" ] && [ -z "${buildPhase-}" ]; then
73+
buildPhase=julecBuildHook
74+
fi
75+
if [ -z "${dontUseJulecCheck-}" ] && [ -z "${checkPhase-}" ]; then
76+
checkPhase=julecCheckHook
77+
fi
78+
if [ -z "${dontUseJulecInstall-}" ] && [ -z "${installPhase-}" ]; then
79+
installPhase=julecInstallHook
80+
fi

pkgs/by-name/ju/julec/package.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
lib,
33
clangStdenv,
4+
callPackage,
45
fetchFromGitHub,
56
}:
67

@@ -93,6 +94,12 @@ clangStdenv.mkDerivation (finalAttrs: {
9394
runHook postInstall
9495
'';
9596

97+
passthru = {
98+
# see doc/hooks/julec.section.md
99+
hook = callPackage ./hook.nix { julec = finalAttrs.finalPackage; };
100+
tests.hello-jule = callPackage ./test { julec = finalAttrs.finalPackage; };
101+
};
102+
96103
meta = {
97104
description = "Jule Programming Language Compiler";
98105
longDescription = ''
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
julec,
3+
clangStdenv,
4+
}:
5+
6+
clangStdenv.mkDerivation (finalAttrs: {
7+
pname = "hello-jule";
8+
inherit (julec) version;
9+
10+
src = ./hello-jule;
11+
12+
nativeBuildInputs = [ julec.hook ];
13+
14+
doCheck = true;
15+
16+
meta = {
17+
inherit (julec.meta) platforms;
18+
};
19+
})

pkgs/by-name/ju/julec/test/hello-jule/jule.mod

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use "std/testing"
2+
3+
#test
4+
fn testPi(t: &testing::T) {
5+
if getPi() != 3.14 {
6+
t.Errorf("PI not precise enough")
7+
}
8+
}

0 commit comments

Comments
 (0)