Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Nov 11, 2023
1 parent 4d10844 commit f51686e
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 61 deletions.
70 changes: 43 additions & 27 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,34 @@ name: Windows
on:
workflow_call:

defaults:
run:
shell: bash

env:
REPO_NAME: ${{ github.event.repository.name }}
GET_ENV: $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")

jobs:
setup:
runs-on: windows-latest
defaults:
run:
shell: bash
working-directory: ${{ env.REPO_NAME }}
steps:
- name: Install V
uses: vlang/setup-v@v1.3
with:
check-latest: true
- name: Checkout ${{ env.REPO_NAME }}
uses: actions/checkout@v4
with:
path: ${{ env.REPO_NAME }}
- name: Checkout V
uses: actions/checkout@v4
with:
repository: 'vlang/v'
path: vlang
- name: Setup V
run: cd ../vlang && ./make.bat && ./v symlink
- name: Setup modules
run: |
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
v install
~/.vmodules/webview/build.vsh
v $HOME/.vmodules/webview/build.vsh
- name: Cache
uses: actions/cache/save@v3
with:
Expand All @@ -35,21 +42,23 @@ jobs:
build:
needs: setup
runs-on: windows-latest
defaults:
run:
shell: bash
working-directory: ${{ env.REPO_NAME }}
steps:
- name: Restore cache
- name: Checkout ${{ env.REPO_NAME }}
uses: actions/checkout@v4
- name: Restore Cache
uses: actions/cache/restore@v3
with:
path: |
vlang
~/.vmodules
key: ${{ runner.os }}-${{ github.sha }}
fail-on-cache-miss: true
- name: Setup V
uses: vlang/setup-v@v1.3
- name: Checkout ${{ env.REPO_NAME }}
uses: actions/checkout@v4
- name: Build
run: v -cg -cc gcc .
run: ../vlang/v -cg -cc gcc .

deploy:
needs: build
Expand All @@ -58,28 +67,35 @@ jobs:
contents: write
env:
ARTIFACT: emoji-mart-windows-amd64.exe
defaults:
run:
shell: bash
working-directory: ${{ env.REPO_NAME }}
steps:
- name: Restore cache
uses: actions/cache/restore@v3
with:
path: |
vlang
~/.vmodules
key: ${{ runner.os }}-${{ github.sha }}
fail-on-cache-miss: true
- name: Setup V
uses: vlang/setup-v@v1.3
- name: Checkout ${{ env.REPO_NAME }}
uses: actions/checkout@v4
with:
path: ${{ env.REPO_NAME }}
- name: Checkout V
uses: actions/checkout@v4
with:
repository: 'vlang/v'
path: vlang
- name: Setup V
run: cd ../vlang && ./make.bat && ./v symlink
- name: Prepare deployment build
run: |
curl -sSLo lvb.exe https://github.com/ttytm/LVbag/releases/latest/download/lvb-windows-amd64.exe
./lvb --version
git fetch --prune --unshallow
- name: Build
run: ./build.vsh
run: |
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
./build.vsh
- name: Prepare artifacts
run: mv "dist/emoji-mart.exe" ./$ARTIFACT
run: |
find dist/
mv "dist/emoji-mart.exe" ./$ARTIFACT
- name: Upload binary artifact
uses: actions/upload-artifact@v3
with:
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion build.vsh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ fn gen_embeds() ! {

fn build_bin(flags string) ! {
cc := $if macos { 'clang' } $else { 'gcc' }
cmd := 'v -d embed -cc ${cc} ${flags} -o ${app_root}/dist/emoji-mart ${app_root}/src'
out_file := 'emoji-mart' + $if windows { '.exe' } $else { '' }
cmd := 'v -cc ${cc} ${flags} -o ${app_root}/dist/${out_file} ${app_root}/src'
println('Building binary: ${cmd}')
execute_opt($if windows { 'powershell -command ${cmd}' } $else { cmd })!
}
Expand Down
8 changes: 0 additions & 8 deletions src/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ mut:
proc os.Process // OS process spawned when running the app with `v -d dev`
}

const (
app_name = 'emoji-mart'
paths = &Paths{}
)

fn main() {
$if embed ? {
write_embedded() or { eprintln('Failed writing embedded files: `${err}`') }
}
mut app := App{
window: webview.create()
}
Expand Down
23 changes: 13 additions & 10 deletions src/main_d_embed.v
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
import os

const (
sound = $embed_file('../assets/pop.wav')
icon = $embed_file('../assets/emoji-mart.ico')
// Needs to be in another dir else V embeds the wrong file.
sound = $embed_file('../assets/audio/pop.wav')
)

fn write_embedded() ! {
if !os.exists(paths.ui) {
dist_ui_path := os.join_path('dist', 'ui')
for file in ui {
out_path := file.path.replace(os.join_path(paths.root, 'dist', 'ui'), paths.ui)
os.mkdir_all(os.dir(out_path))!
os.write_file(out_path, file.to_string())!
_, mut out_path := file.path.rsplit_once(dist_ui_path) or {
return error('failed to prepare path for ${file.path}')
}
out_path = os.join_path(paths.ui, out_path)
os.mkdir_all(os.dir(out_path)) or { panic(err) }
os.write_file(out_path, file.to_string()) or { panic(err) }
}
}
if !os.exists(paths.sound) {
path := sound.path.replace('../assets/pop.wav', paths.sound)
os.mkdir_all(os.dir(path)) or {}
os.write_file(path, sound.to_string())!
os.mkdir_all(os.dir(paths.sound)) or {}
os.write_file(paths.sound, sound.to_string())!
}
if !os.exists(paths.icon) {
path := sound.path.replace('../assets/emoji-mart.ico', paths.icon)
os.mkdir_all(os.dir(path)) or {}
os.write_file(path, icon.to_string())!
os.mkdir_all(os.dir(paths.icon)) or {}
os.write_file(paths.icon, icon.to_string())!
}
}
30 changes: 15 additions & 15 deletions src/paths.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@ struct Paths {
mut:
root string
tmp string
ui_dev string
ui string
sound_dev string
sound string
icon_dev string
icon string
cfg_dir string
cfg_file string
cache_dir string
cache_file string
}

const (
app_name = 'emoji-mart'
paths = &Paths{}
)

fn init() {
mut p := &Paths{}
unsafe {
p = paths
}
app_root := @VMODROOT
p.ui_dev = join_path(app_root, 'ui')
p.sound_dev = join_path(app_root, 'assets', 'pop.wav')
p.icon_dev = join_path(app_root, 'assets', 'emoji-mart.ico')
$if prod {
app_tmp := join_path(os.temp_dir(), '${app_name}-@${version}')
p.ui = join_path(app_tmp, 'ui')
p.sound = join_path(app_tmp, 'assets', 'pop.wav')
p.icon = join_path(app_tmp, 'assets', 'icon.ico')
$if embed ? {
ui_dir := join_path(os.temp_dir(), '${app_name}-@${version}')
p.ui = join_path(ui_dir, 'ui')
p.sound = join_path(ui_dir, 'assets', 'pop.wav')
p.icon = join_path(ui_dir, 'assets', 'icon.ico')
write_embedded() or { eprintln('Failed writing embedded files: `${err}`') }
} $else {
p.ui = p.ui_dev
p.sound = p.sound_dev
p.icon = p.icon_dev
app_root := @VMODROOT
p.ui = join_path(app_root, 'ui')
p.sound = join_path(app_root, 'assets', 'pop.wav')
p.icon = join_path(app_root, 'assets', 'emoji-mart.ico')
}
// Config
p.cfg_dir = join_path(os.config_dir() or { panic(err) }, app_name)
Expand Down

0 comments on commit f51686e

Please sign in to comment.