Skip to content

Commit 780a43b

Browse files
committed
Include stdlib
1 parent 6996585 commit 780a43b

File tree

5 files changed

+40
-26
lines changed

5 files changed

+40
-26
lines changed

.github/workflows/lit.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,26 @@ on:
1010
workflow_dispatch:
1111

1212
jobs:
13-
lit-linux:
14-
name: Lit (Linux)
13+
lit-linux-debug:
14+
name: lit tests (Linux, debug build)
1515
runs-on: ubuntu-latest
1616
container: ghcr.io/plc-lang/rust-llvm:latest
1717
steps:
1818
- uses: actions/checkout@v3
1919

20-
- name: Run `build.sh --lit`
20+
- name: `build.sh --lit`
2121
shell: bash
2222
run: |
23-
./scripts/build.sh --lit
23+
./scripts/build.sh --lit
24+
25+
lit-linux-release:
26+
name: lit tests (Linux, release build)
27+
runs-on: ubuntu-latest
28+
container: ghcr.io/plc-lang/rust-llvm:latest
29+
steps:
30+
- uses: actions/checkout@v3
31+
32+
- name: `build.sh --lit --release`
33+
shell: bash
34+
run: |
35+
./scripts/build.sh --lit --release

scripts/build.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,16 @@ function run_check_style() {
142142
}
143143

144144
function run_lit_test() {
145-
# We need a binary to execute the lit tests
146-
cargo build
147-
cargo build --release
145+
# We need a binary as well as the stdlib and its *.so file before running lit tests
146+
run_build
147+
run_std_build
148+
run_package_std
148149

149-
lit -v -DCOMPILER=$project_location/target/debug/plc tests/lit/
150-
lit -v -DCOMPILER=$project_location/target/release/plc tests/lit/
150+
if [[ $release -eq 0 ]]; then
151+
lit -v -DLIB=$project_location/output -DCOMPILER=$project_location/target/debug/plc tests/lit/
152+
else
153+
lit -v -DLIB=$project_location/output -DCOMPILER=$project_location/target/release/plc tests/lit/
154+
fi
151155
}
152156

153157
function run_test() {
@@ -201,6 +205,8 @@ function set_offline() {
201205

202206
function run_package_std() {
203207
cc=$(get_compiler)
208+
OUTPUT_DIR=$project_location/output
209+
make_dir "$OUTPUT_DIR"
204210
log "Packaging Standard functions"
205211
log "Removing previous output folder"
206212
rm -rf $OUTPUT_DIR
@@ -433,11 +439,6 @@ if [[ $container -ne 0 ]]; then
433439
exit 0
434440
fi
435441

436-
if [[ $package -ne 0 ]]; then
437-
OUTPUT_DIR=$project_location/output
438-
make_dir "$OUTPUT_DIR"
439-
fi
440-
441442
if [[ $vendor -ne 0 ]]; then
442443
generate_sources
443444
exit 0

tests/lit/lit.cfg

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,9 @@ config.test_format = lit.formats.ShTest(True)
44
config.pipefail = False
55
rustyRootDirectory = subprocess.check_output("dirname `cargo locate-project --message-format plain`", shell=True).decode("utf-8").strip()
66

7-
# TODO: These need to be adjusted to the action runner / build.sh file
8-
# compiler = lit_config.params["COMPILER"]
9-
# lib = lit_config.params["STDLIBPATH"]
10-
# arch = lit_config.params["ARCH"]
11-
# config.substitutions.append(('%COMPILE', f'{compiler} -o /tmp/%basename_t.out -liec61131std -L{lib}{arch}/lib/ -i "{lib}/include/*.st" -i {srcDir}/helpers/printf.pli --linker=cc'))
12-
# config.substitutions.append(('%RUN', f'LD_LIBRARY_PATH="{lib}{arch}/lib" /tmp/%basename_t.out'))
13-
# config.substitutions.append(('%CHECK', f'FileCheck-14 --check-prefixes GREY,CHECK --allow-unused-prefixes --match-full-lines'))
14-
157
# ~/.local/bin/lit -v -DCOMPILER=/home/[email protected]/Development/rusty/target/debug/plc ./tests/lit
16-
compiler = lit_config.params["COMPILER"]
17-
config.substitutions.append(('%COMPILE', f'{compiler} -o /tmp/%basename_t.out {rustyRootDirectory}/tests/lit/util/printf.pli --linker=cc'))
18-
config.substitutions.append(('%RUN', f'/tmp/%basename_t.out'))
8+
stdlibLocation = lit_config.params["LIB"]
9+
compilerLocation = lit_config.params["COMPILER"]
10+
config.substitutions.append(('%COMPILE', f'LD_LIBRARY_PATH="{stdlibLocation}/lib" {compilerLocation} -o /tmp/%basename_t.out -liec61131std -L{stdlibLocation}/lib -i "{stdlibLocation}/include/*.st" -i {rustyRootDirectory}/tests/lit/util/printf.pli --linker=cc'))
11+
config.substitutions.append(('%RUN', f'LD_LIBRARY_PATH="{stdlibLocation}/lib" /tmp/%basename_t.out'))
1912
config.substitutions.append(('%CHECK', f'FileCheck-14 --check-prefixes CHECK --allow-unused-prefixes --match-full-lines'))

tests/lit/single/arithmetic/addition.st

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: (%COMPILE %s && %RUN) | %CHECK %s
2+
// CHECK: 10
23
FUNCTION main
34
VAR
45
x : DINT;
@@ -8,5 +9,4 @@ FUNCTION main
89
x := 5;
910
y := 5;
1011
printf('%d$N', x + y);
11-
// CHECK: 10
1212
END_FUNCTION

tests/lit/single/arithmetic/sqrt.st

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: (%COMPILE %s && %RUN) | %CHECK %s
2+
// CHECK: 2
3+
FUNCTION main
4+
VAR
5+
res : LREAL;
6+
END_VAR
7+
printf('%d$N', REAL_TO_DINT(SQRT(4.0)));
8+
END_FUNCTION

0 commit comments

Comments
 (0)