Skip to content

Commit 10fee39

Browse files
committed
refact: port to Jule v0.1.7
1 parent 134e966 commit 10fee39

9 files changed

Lines changed: 67 additions & 57 deletions

File tree

.github/workflows/jule.yml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ jobs:
1414
submodules: 'true'
1515

1616
- name: Install JuleC
17-
run: |
18-
mkdir julec
19-
cd julec
20-
bash <(curl -s https://raw.githubusercontent.com/julelang/julec-ir/main/compile-ir.sh)
21-
echo "$(pwd)/jule-master/bin" >> $GITHUB_PATH
22-
cd ..
17+
uses: Panquesito7/setup-jule@v1.1.3
18+
with:
19+
version: dev
20+
directory: .julec
21+
22+
- name: Add JuleC to PATH
23+
run: echo "$(pwd)/.julec/julec-dev/bin" >> $GITHUB_PATH
24+
2325
- name: Install JuleFmt
2426
run: |
25-
git clone https://github.com/julelang/julefmt.git --depth=1
26-
cd julefmt
27+
git clone https://github.com/julelang/julefmt.git --depth=1 .julefmt
28+
cd .julefmt
2729
mkdir -p bin
28-
julec --opt-deadcode -o bin/julefmt ./src
30+
julec build --opt-deadcode -o bin/julefmt ./src
2931
echo "$(pwd)/bin" >> $GITHUB_PATH
3032
cd ..
3133
@@ -37,17 +39,15 @@ jobs:
3739
- name: Build
3840
run: |
3941
make
40-
- name: Test
41-
run: |
42-
make test
42+
4343
- name: Format
4444
run: |
4545
make format
4646
4747
- name: Clean up
4848
run: |
4949
make clean
50-
rm -rf julec julefmt
50+
rm -rf .julec .julefmt
5151
5252
- name: Check formatting
5353
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
main
12
**/*.out
23
**/dist
34
**/build

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ all: build
1313

1414
build:
1515
mkdir -p build
16-
$(JULEC) $(JULECFLAGS) src
16+
$(JULEC) build src $(JULECFLAGS)
1717

1818
run: build
1919
./build/$(BINARY)
2020

2121
test:
22-
$(JULEC) test src
22+
$(JULEC) test src $(JULECFLAGS)-test
23+
./build/$(BINARY)-test
2324

2425
format:
2526
julefmt -w src

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ A lightweight and fast tool for installing, updating and managing [Proton], [Pro
44
jpu is written in [Jule], a low-level, compiled, memory-safe fast programming language.<br>
55
The tool's main goal is to provide a **faster** [ProtonUp] implementation. The original project is written in Python, which is quite slow.
66

7-
Supported Jule versions:
8-
- `0.1.4`
9-
- `0.1.5@master`
10-
117
## Installation
128

139
### Arch Linux

src/crypto.h renamed to crypto.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <string.h>
1111
#include <openssl/evp.h>
1212

13-
jule::Str sha512sum(const jule::Str input) {
13+
__jule_Str sha512sum(const __jule_Str input) {
1414
EVP_MD_CTX* ctx = EVP_MD_CTX_new();
1515
unsigned char hash[EVP_MAX_MD_SIZE];
1616
unsigned int length;
@@ -23,7 +23,7 @@ jule::Str sha512sum(const jule::Str input) {
2323

2424
char* output = (char*)malloc((length * 2) + 1);
2525
if (output == NULL) {
26-
return jule::Str();
26+
return __jule_Str();
2727
}
2828

2929
for (unsigned int i = 0; i < length; i++) {

jule.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module jpu

snapbox

src/jpu.jule

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,21 @@
33
// Use of this source code is governed by the BSD 3-Clause License.
44
// See the LICENSE file for details.
55

6-
#pass "-lcurl -lcrypto"
6+
#pass "-lcrypto"
77

8-
use sbx "snapbox"
9-
use sbh "snapbox/header"
10-
use sbs "snapbox/status"
8+
use sbx "jpu/snapbox"
9+
use sbh "jpu/snapbox/header"
10+
use sbs "jpu/snapbox/status"
11+
use "std/bufio"
1112
use "std/conv"
1213
use "std/os"
1314
use "std/os/filepath"
1415
use ss "std/strings"
1516

16-
cpp use "crypto.h"
17+
cpp use "jpu/crypto.h"
1718

1819
const tempDir = "/tmp/jpu"
1920

20-
static headerMap: sbh::HeaderMap = {
21-
sbh::ACCEPT: "application/vnd.github+json",
22-
sbh::USER_AGENT: "jpu",
23-
"X-GitHub-Api-Version": "2022-11-28",
24-
}
25-
2621
cpp fn sha512sum(str): str
2722

2823
struct Proton {
@@ -32,7 +27,7 @@ struct Proton {
3227
}
3328

3429
impl Proton {
35-
fn Download(self)! {
30+
fn Download(*self)! {
3631
os::Mkdir(tempDir) else {}
3732

3833
tempProtonFile := tempDir + "/" + self.tagName + ".tar.gz"
@@ -64,7 +59,7 @@ impl Proton {
6459
}
6560
}
6661

67-
fn Install(self)! {
62+
fn Install(*self)! {
6863
tempProtonFile := tempDir + "/" + self.tagName + ".tar.gz"
6964
tempChecksumFile := tempDir + "/" + self.tagName + ".sha512sum"
7065

@@ -86,6 +81,12 @@ fn GetProton(tagRaw: str, urlRaw: str, mut installDir: str)!: Proton {
8681
tag = "/tags/" + tagRaw
8782
}
8883

84+
let headerMap: sbh::HeaderMap = {
85+
sbh::ACCEPT: "application/vnd.github+json",
86+
sbh::USER_AGENT: "jpu",
87+
"X-GitHub-Api-Version": "2022-11-28",
88+
}
89+
8990
url := urlRaw + tag
9091
request := sbx::GET(url).Headers(headerMap).Send()
9192

@@ -131,7 +132,12 @@ fn GetProton(tagRaw: str, urlRaw: str, mut installDir: str)!: Proton {
131132
println(" MB\n Date: " + publishedAt)
132133
print(" Continue? [Y/n]: ")
133134

134-
input := os::Stdin().ReadLine()!
135+
mut scanner := bufio::Scanner.New(os::Stdin())
136+
scanner.Scan() else {
137+
error("Failed to read input")
138+
}
139+
input := scanner.Text()
140+
135141
match ss::ToLower(input) {
136142
| "n":
137143
error("Aborted")

src/main.jule

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Use of this source code is governed by the BSD 3-Clause License.
44
// See the LICENSE file for details.
55

6-
use cy "colorify"
6+
use cy "jpu/colorify"
77
use "std/flag"
88
use "std/os"
99
use ss "std/strings"
@@ -12,20 +12,6 @@ use "std/sys"
1212
const protonGeURL = "https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases"
1313
const defaultInstallDir = "~/.steam/root/compatibilitytools.d/"
1414

15-
static argMap: map[int][2]str = {}
16-
static successMessage = cy::Colorify("#", cy::Style{
17-
Foreground: cy::Foreground.Green,
18-
Background: cy::Background.Black,
19-
})
20-
static infoMessage = cy::Colorify("*", cy::Style{
21-
Foreground: cy::Foreground.Blue,
22-
Background: cy::Background.Black,
23-
})
24-
static errorMessage = cy::Colorify("!", cy::Style{
25-
Foreground: cy::Foreground.Red,
26-
Background: cy::Background.Black,
27-
})
28-
2915
fn main() {
3016
mut fs := flag::FlagSet.New()
3117

@@ -45,29 +31,29 @@ fn main() {
4531
ret
4632
}
4733

48-
println(infoMessage + " No arguments provided. Assuming an update.")
34+
printInfo("No arguments provided. Assuming an update.")
4935
update(dir)
5036
}
5137

5238
fn update(mut installDir: str) {
53-
println(infoMessage + " Getting the latest Proton-GE release...")
39+
printInfo("Getting the latest Proton-GE release...")
5440
proton := GetProton("", protonGeURL, installDir) else {
5541
handleErr(error)
5642
ret
5743
}
58-
println(infoMessage + " Downloading...")
44+
printInfo("Downloading...")
5945
proton.Download() else {
6046
handleErr(error)
6147
}
62-
println(infoMessage + " Installing...")
48+
printInfo("Installing...")
6349
proton.Install() else {
6450
handleErr(error)
6551
}
66-
println(successMessage + " Done!")
52+
printSuccess("Done!")
6753
}
6854

6955
fn handleErr(err: any) {
70-
print(errorMessage + " ")
56+
printError()
7157
println(err)
7258
sys::Exit(1)
7359
}
@@ -86,4 +72,23 @@ fn autoHelp(mut flags: &flag::FlagSet): (res: str) {
8672
}
8773

8874
ret res
75+
}
76+
77+
fn printSuccess(msg: str) {
78+
println(cy::Colorify("#", cy::Style{
79+
Foreground: cy::Foreground.Green,
80+
Background: cy::Background.Black,
81+
}) + " " + msg)
82+
}
83+
fn printInfo(msg: str) {
84+
println(cy::Colorify("*", cy::Style{
85+
Foreground: cy::Foreground.Blue,
86+
Background: cy::Background.Black,
87+
}) + " " + msg)
88+
}
89+
fn printError() {
90+
println(cy::Colorify("!", cy::Style{
91+
Foreground: cy::Foreground.Red,
92+
Background: cy::Background.Black,
93+
}) + " ")
8994
}

0 commit comments

Comments
 (0)