[VER] v0.3.6-alpha

[Feat] 增加控制台在线安装器 !
[Impl] 修改ExampleCodes的一些实现,使用最新库 std.io
This commit is contained in:
2026-01-04 00:51:11 +08:00
parent 893eb1050f
commit c93840af5f
10 changed files with 223 additions and 14 deletions

View File

@@ -46,9 +46,26 @@ jobs:
xmake build -j$(nproc) xmake build -j$(nproc)
echo "Linux构建成功。" echo "Linux构建成功。"
# 🔧 新增构建Linux平台安装器
- name: 构建Linux安装器
run: |
echo "开始构建Linux安装器..."
cd Installer/ConsoleInstaller
# 确保pip已安装
if ! command -v pip3 &> /dev/null; then
echo "安装pip3..."
apt-get update && apt-get install -y python3-pip
fi
# 安装依赖并构建
pip3 install --upgrade pip
pip3 install -r requirements.txt
python3 -m PyInstaller -F -n fig-setup --distpath ./dist/linux main.py
echo "Linux安装器构建完成"
- name: 打包Linux发布文件 - name: 打包Linux发布文件
run: | run: |
PACKAGE_NAME="Fig-${{ env.VERSION }}-linux-x86_64" VERSION="${{ env.VERSION }}"
PACKAGE_NAME="Fig-${VERSION}-linux-x86_64"
mkdir -p "${PACKAGE_NAME}" mkdir -p "${PACKAGE_NAME}"
cp build/linux/x86_64/release/Fig "${PACKAGE_NAME}/" cp build/linux/x86_64/release/Fig "${PACKAGE_NAME}/"
if [ -d "src/Module/Library" ]; then if [ -d "src/Module/Library" ]; then
@@ -88,6 +105,7 @@ jobs:
echo "使用发布 ID: $RELEASE_ID 进行上传" echo "使用发布 ID: $RELEASE_ID 进行上传"
# 上传语言包
curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \ curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/octet-stream" \ -H "Content-Type: application/octet-stream" \
--data-binary @Fig-$VERSION-linux-x86_64.tar.gz \ --data-binary @Fig-$VERSION-linux-x86_64.tar.gz \
@@ -98,6 +116,15 @@ jobs:
--data-binary @Fig-$VERSION-linux-x86_64.sha256 \ --data-binary @Fig-$VERSION-linux-x86_64.sha256 \
"$API/releases/$RELEASE_ID/assets?name=Fig-$VERSION-linux-x86_64.sha256" "$API/releases/$RELEASE_ID/assets?name=Fig-$VERSION-linux-x86_64.sha256"
# 🔧 新增上传Linux安装器
if [ -f "Installer/ConsoleInstaller/dist/linux/fig-setup" ]; then
echo "正在上传Linux安装器..."
curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @Installer/ConsoleInstaller/dist/linux/fig-setup \
"$API/releases/$RELEASE_ID/assets?name=fig-setup"
fi
echo "✅ Linux版本发布完成" echo "✅ Linux版本发布完成"
build-windows-x64: build-windows-x64:
@@ -143,6 +170,16 @@ jobs:
xmake build -j $env:NUMBER_OF_PROCESSORS xmake build -j $env:NUMBER_OF_PROCESSORS
Write-Host 'Windows构建成功。' Write-Host 'Windows构建成功。'
# 🔧 新增构建Windows平台安装器
- name: 构建Windows安装器
run: |
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Write-Host "开始构建Windows安装器..."
cd Installer\ConsoleInstaller
pip install -r requirements.txt
pyinstaller -F -i logo.ico -n FigSetup --distpath .\dist\windows main.py
Write-Host "Windows安装器构建完成"
- name: 打包Windows发布文件 - name: 打包Windows发布文件
run: | run: |
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8 [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
@@ -203,8 +240,6 @@ jobs:
$API = "https://git.fig-lang.cn/api/v1/repos/$REPO" $API = "https://git.fig-lang.cn/api/v1/repos/$REPO"
$TOKEN = $env:GITEA_TOKEN $TOKEN = $env:GITEA_TOKEN
$TOKEN = $env:GITEA_TOKEN
Write-Host "正在上传Windows版本到发布 $VERSION ..." Write-Host "正在上传Windows版本到发布 $VERSION ..."
# 1. 尝试通过标签获取 Release ID # 1. 尝试通过标签获取 Release ID
@@ -233,4 +268,15 @@ jobs:
Write-Host '正在上传校验文件...' Write-Host '正在上传校验文件...'
Invoke-RestMethod -Method Post -Uri "$API/releases/$RELEASE_ID/assets?name=Fig-$VERSION-windows-x86_64.sha256" -Headers @{Authorization = "token $TOKEN"; 'Content-Type' = 'text/plain' } -InFile "Fig-$VERSION-windows-x86_64.sha256" Invoke-RestMethod -Method Post -Uri "$API/releases/$RELEASE_ID/assets?name=Fig-$VERSION-windows-x86_64.sha256" -Headers @{Authorization = "token $TOKEN"; 'Content-Type' = 'text/plain' } -InFile "Fig-$VERSION-windows-x86_64.sha256"
# 🔧 新增上传Windows安装器
$InstallerPath = "Installer\ConsoleInstaller\dist\windows\FigSetup.exe"
if (Test-Path $InstallerPath) {
Write-Host '正在上传Windows安装器...'
Invoke-RestMethod -Method Post -Uri "$API/releases/$RELEASE_ID/assets?name=FigSetup.exe" `
-Headers @{
Authorization = "token $TOKEN"
'Content-Type' = 'application/octet-stream'
} -InFile $InstallerPath
}
Write-Host '✅ Windows版本发布完成' Write-Host '✅ Windows版本发布完成'

View File

@@ -1,10 +1,11 @@
import std.io;
func greeting(name:String) -> String func greeting(name:String) -> String
{ {
return "Hello " + name + "!"; return "Hello " + name + "!";
} }
const print := __fstdout_println; // link to std out io.println(greeting("Fig"));
print(greeting("Fig"));
func adder(x) func adder(x)
{ {
@@ -12,4 +13,4 @@ func adder(x)
} }
const add2 = adder(2); const add2 = adder(2);
print(add2(3)); io.println(add2(3));

View File

@@ -1,3 +1,5 @@
import std.io;
func fib(x:Int) -> Int func fib(x:Int) -> Int
{ {
if (x <= 1) if (x <= 1)
@@ -8,4 +10,4 @@ func fib(x:Int) -> Int
} }
var result := fib(25); var result := fib(25);
__fstdout_println("result: ", result); io.println("result: ", result);

View File

@@ -1,3 +1,6 @@
import std.io;
import std.value;
var callCnt:Int = 0; var callCnt:Int = 0;
func fib(x:Int) -> Int func fib(x:Int) -> Int
{ {
@@ -10,15 +13,15 @@ func fib(x:Int) -> Int
} }
var fibx:Int; var fibx:Int;
__fstdout_print("input an index of fib "); io.print("input an index of fib ");
fibx = __fvalue_int_parse(__fstdin_read()); fibx = value.int_parse(io.read());
var cnt:Int = 0; var cnt:Int = 0;
__fstdout_println("test forever"); io.println("test forever");
while (true) while (true)
{ {
cnt = cnt + 1; cnt = cnt + 1;
__fstdout_println("test ", cnt,",result: ", fib(fibx)); io.println("test ", cnt,",result: ", fib(fibx));
__fstdout_println("func `fib` called ", callCnt); io.println("func `fib` called ", callCnt);
callCnt = 0; callCnt = 0;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -1,3 +1,156 @@
# Fig online installer - Python
# Copyright (C) 2020-2026 PuqiAR
from tqdm import tqdm from tqdm import tqdm
import requests import requests
import json
import zipfile
import platform
from os import path as ospath
from os import mkdir,chdir
from sys import exit, argv
VERSION = '1.0.0'
GITEA_URL = 'https://git.fig-lang.cn'
Windows = 0
Linux = 2
Darwin = 3
def getOSName() -> int|str:
name = platform.system()
if name == 'Windows':
return Windows
elif name == 'Linux':
return Linux
elif name == 'Darwin':
return Darwin
else:
return name
def resolveInstallPath(os: int):
default_path = {
Windows : r'C:\Program Files\Fig',
Linux : r'/opt/Fig'
}
if os not in default_path:
raise
return default_path[os]
def getReleases():
api_postfix = '/api/v1/repos/PuqiAR/Fig/releases'
api_url = GITEA_URL + api_postfix
rel = requests.get(api_url).text
# print(rel)
return rel
def install(url, path:str) -> None:
if not ospath.exists(path):
mkdir(path)
filename = path.split('/')[-1]
response = requests.get(url, stream=True)
total_size = int(response.headers.get('content-length', 0))
with tqdm(total=total_size, unit='B', unit_scale=True, desc=filename) as b:
with open(filename, 'wb') as f:
for data in response.iter_content(chunk_size=1024):
f.write(data)
b.update(len(data))
print(f'{filename} download completed.')
print(f'unziping to {path} ...')
with zipfile.ZipFile(filename) as zip:
zip.extractall(path)
print('unziping completed')
def main() -> None:
print(f'== Fig Online Installer v{VERSION} ==')
osName = getOSName()
if osName is int or osName == 'Darwin':
print(f'Unsupport os: {osName}')
exit(1)
dpath = resolveInstallPath(osName)
print(f'Install to (default: {dpath}): ', end='')
path = input()
if path.isspace():
path = dpath
print()
releases = json.loads(getReleases())
# print(type(releases))
if not isinstance(releases, list):
print('get releases failed!')
exit(1)
if len(releases) == 0:
print('No version has been released!')
exit(0)
print('There are {} versions:' % len(releases))
i = 1
for release in releases:
print(f" {i} {release['name']} - {release['body']}")
print(f" @{release['published_at']}")
if i >= 3:
print(f' .....')
break # 展示前3个
insVersion: dict = releases[0]
print(f"Which version do you want to install({insVersion['name']} if empty)(e.g. x.x.x/index)? ", end='')
usrInput = input()
print()
version = insVersion
if not usrInput.isspace():
if '.' in usrInput:
for release in releases:
if release['tag_name'].find(usrInput) != -1:
version = release
else:
try:
index = int(usrInput)
if index > 3 or index < 1 or (index > len(releases)):
print(f'Invalid index {usrInput} to install')
exit(1)
version = releases[index - 1]
except Exception:
print('Invalid input')
exit(1)
print('\n================================')
print(f"Installing Fig-{version['tag_name']}")
url = None
for asset in version['assets']:
if asset['name'].find(osName) != -1:
url = asset['browser_download_url']
break
if url:
install(url, path)
else:
print('Could not find artifact:')
print(version['assets'])
exit(1)
print(f"Fig-{version['tag_name']} install successfully to {path} !")
exit(0)
if __name__ == '__main__':
path = ospath.realpath(ospath.dirname(argv[0]))
chdir(path)
main()

View File

@@ -1,2 +1,4 @@
requests requests
tqdm tqdm
pyinstaller
json

BIN
Logo/Logo1024x1024.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -4,7 +4,7 @@
#include <cstdint> #include <cstdint>
#include <string_view> #include <string_view>
#define __FCORE_VERSION "0.3.5-alpha" #define __FCORE_VERSION "0.3.6-alpha"
#if defined(_WIN32) #if defined(_WIN32)
#define __FCORE_PLATFORM "Windows" #define __FCORE_PLATFORM "Windows"

View File

@@ -7,6 +7,8 @@ target("Fig")
set_kind("binary") set_kind("binary")
set_languages("c++23") set_languages("c++23")
add_ldflags("-static", {force = true})
if is_plat("linux") then if is_plat("linux") then
-- Linux: clang + libc++ -- Linux: clang + libc++
set_toolchains("clang") set_toolchains("clang")