From f51686efcbb081a2f63d04afc5f1dae519e8a974 Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+ttytm@users.noreply.github.com> Date: Mon, 6 Nov 2023 01:30:44 +0100 Subject: [PATCH] temp --- .github/workflows/windows.yml | 70 +++++++++++++++++++++------------- assets/{ => audio}/pop.wav | Bin build.vsh | 3 +- src/main.v | 8 ---- src/main_d_embed.v | 23 ++++++----- src/paths.v | 30 +++++++-------- 6 files changed, 73 insertions(+), 61 deletions(-) rename assets/{ => audio}/pop.wav (100%) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index b5e91dc..1b3cd92 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -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: @@ -35,8 +42,14 @@ 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: | @@ -44,12 +57,8 @@ jobs: ~/.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 @@ -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: diff --git a/assets/pop.wav b/assets/audio/pop.wav similarity index 100% rename from assets/pop.wav rename to assets/audio/pop.wav diff --git a/build.vsh b/build.vsh index a9631b5..cddb6f5 100755 --- a/build.vsh +++ b/build.vsh @@ -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 })! } diff --git a/src/main.v b/src/main.v index ed34e78..e5f78f9 100644 --- a/src/main.v +++ b/src/main.v @@ -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() } diff --git a/src/main_d_embed.v b/src/main_d_embed.v index 1a88f25..0768577 100644 --- a/src/main_d_embed.v +++ b/src/main_d_embed.v @@ -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())! } } diff --git a/src/paths.v b/src/paths.v index c97a5a6..f4368dd 100644 --- a/src/paths.v +++ b/src/paths.v @@ -4,11 +4,8 @@ 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 @@ -16,24 +13,27 @@ mut: 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)