From 852db6233c0a7f6c3d91e2b3954fcf77a458a330 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Mon, 10 Feb 2025 21:25:46 -0500 Subject: [PATCH 1/3] Upgrade actions to v4 No need for double-zipping anymore since the upload artifact action preserves +x permissions now. (cherry picked from commit 0f6611f19f5ac304709fbb3a96759d12ade89eac) --- .github/workflows/autobuild.yml | 45 +++++++++++---------------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index 275f7bfa..d72ab6fd 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -22,7 +22,6 @@ jobs: - uses: msys2/setup-msys2@v2 with: msystem: mingw64 - # zip is just used for artifact compression at the end. install: >- base-devel git @@ -32,13 +31,11 @@ jobs: mingw-w64-x86_64-meson mingw-w64-x86_64-autotools mingw-w64-x86_64-gcc - zip - - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: | windows/build-mingw64 @@ -73,16 +70,11 @@ jobs: cp ../../mkxp.json . cp -r ../../scripts . cp ../../assets/LICENSE.mkxp-z-with-https.txt . - cd .. - # Zipping before uploading decreases the upload time considerably. - # Unfortunately this results in double-zipping; tracked at: - # https://github.com/actions/upload-artifact/issues/426 - zip -r artifact.zip artifact - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: mkxp-z.windows.${{github.event_name == 'pull_request' && format('PR{0}', github.event.number) || github.ref_name}}-${{steps.short-sha.outputs.sha}} - path: build/artifact.zip + path: build/artifact build-linux-native: name: Ubuntu 22.04 x86_64 @@ -94,9 +86,9 @@ jobs: length: 7 - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: | linux/build-x86_64 @@ -129,16 +121,11 @@ jobs: cp ../../mkxp.json . cp -r ../../scripts . cp ../../assets/LICENSE.mkxp-z-with-https.txt . - cd .. - # Zipping before uploading preserves +x permissions. - # Unfortunately this results in double-zipping; tracked at: - # https://github.com/actions/upload-artifact/issues/426 - zip -r local.zip local - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: mkxp-z.linux.x86_64.${{github.event_name == 'pull_request' && format('PR{0}', github.event.number) || github.ref_name}}-${{steps.short-sha.outputs.sha}} - path: build/local.zip + path: build/local build-linux-cross: name: Ubuntu 22.04 ${{matrix.arch_mkxpz}} @@ -190,9 +177,9 @@ jobs: length: 7 - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: | linux/build-${{matrix.arch_mkxpz}} @@ -240,13 +227,11 @@ jobs: cp ../../mkxp.json . cp -r ../../scripts . cp ../../assets/LICENSE.mkxp-z-with-https.txt . - cd .. - zip -r local.zip local - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: mkxp-z.linux.${{matrix.arch_mkxpz}}.${{github.event_name == 'pull_request' && format('PR{0}', github.event.number) || github.ref_name}}-${{steps.short-sha.outputs.sha}} - path: build/local.zip + path: build/local build-macos: name: macOS @@ -261,9 +246,9 @@ jobs: run: brew remove --force $(brew list) - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: | macos/Dependencies/build-macosx-x86_64 @@ -294,7 +279,7 @@ jobs: ditto -c -k --sequesterRsrc --keepParent Z-universal.app Z-universal.app.zip - name: Upload archive - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: mkxp-z.macos.${{github.event_name == 'pull_request' && format('PR{0}', github.event.number) || github.ref_name}}-${{steps.short-sha.outputs.sha}} path: build/Build/Products/Release/Z-universal.app.zip From ceea260b82d6cbd27381a020b55d8a3ce23d1284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Tue, 18 Feb 2025 22:58:58 -0500 Subject: [PATCH 2/3] Make the xxd command in shader/meson.build less fragile --- meson.build | 1 + shader/meson.build | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 17bb062b..b8178bc7 100644 --- a/meson.build +++ b/meson.build @@ -7,6 +7,7 @@ if host_system == 'darwin' endif xxd = find_program('xxd', native: true) +xxd_supports_n = run_command(xxd, '-n', 'meson', '-i', meson.current_source_dir() / 'meson.build', check: false).returncode() == 0 git_hash = run_command('git', 'rev-parse', '--short', 'HEAD').stdout().strip() diff --git a/shader/meson.build b/shader/meson.build index 197a7139..31383552 100644 --- a/shader/meson.build +++ b/shader/meson.build @@ -41,7 +41,9 @@ foreach file : embedded_shaders_f global_sources += custom_target(embedded_shaders[count], input: file, output: '@0@.xxd'.format(embedded_shaders[count]), - command: [ + command: xxd_supports_n ? [ + xxd, '-n', '___shader_@0@'.format(embedded_shaders[count].replace('.', '_')), '-i', '@INPUT@' + ] : [ xxd, '-i', '@INPUT@' ], capture: true, From f162e8a494add0253268f82ff3892c6e8a94093f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Thu, 27 Feb 2025 22:55:22 -0500 Subject: [PATCH 3/3] Replace xxd with a custom executable This removes the need to have xxd installed and provides a portable way to specify the name of the output array (xxd has an `-n` option for this, but it isn't present in older versions of xxd), which helps reduce the possibility of symbol conflicts in libretro builds and also prevents portability issues since the name of xxd's output array depends on the relative path to the input file, which can break if Meson changes the structure of the build directory or if the user sets the build directory to a different location. Also, this custom executable declares the array as const so that it goes into the read-only data section of the binary instead of the data section. --- .github/workflows/autobuild.yml | 1 - assets/meson.build | 7 ++-- embedtool.cpp | 59 +++++++++++++++++++++++++++++++++ meson.build | 6 ++-- shader/meson.build | 11 +++--- src/display/font.cpp | 10 ++---- src/display/gl/shader.cpp | 6 ++-- src/eventthread.cpp | 2 +- src/main.cpp | 2 +- 9 files changed, 78 insertions(+), 26 deletions(-) create mode 100644 embedtool.cpp diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index d72ab6fd..26edfaa0 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -26,7 +26,6 @@ jobs: base-devel git ruby - vim mingw-w64-x86_64-cmake mingw-w64-x86_64-meson mingw-w64-x86_64-autotools diff --git a/assets/meson.build b/assets/meson.build index b746281a..6659aa9a 100644 --- a/assets/meson.build +++ b/assets/meson.build @@ -17,10 +17,11 @@ foreach file : embedded_assets_f input: file, output: '@0@.xxd'.format(embedded_assets[count]), command: [ - xxd, '-i', '@INPUT@' + embedtool, + '@INPUT@', + '@OUTPUT@', + 'mkxp_assets_@0@'.format(embedded_assets[count].replace('.', '_')), ], - capture: true, - depend_files: embedded_assets_f[count] ) count += 1 endforeach diff --git a/embedtool.cpp b/embedtool.cpp new file mode 100644 index 00000000..f4fd28a6 --- /dev/null +++ b/embedtool.cpp @@ -0,0 +1,59 @@ +/* +** embedtool.cpp +** +** This file is part of mkxp. +** +** Copyright (C) 2013 - 2021 Amaryllis Kulla +** +** mkxp is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 2 of the License, or +** (at your option) any later version. +** +** mkxp is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with mkxp. If not, see . +*/ + +#include +#include + +int main(int argc, char **argv) { + if (argc < 4) { + return 1; + } + + const char *input = argv[1]; + const char *output = argv[2]; + const char *arrayname = argv[3]; + + std::ifstream inputf(input); + if (!inputf.is_open()) { + return 2; + } + + std::ofstream outputf(output); + if (!outputf.is_open()) { + return 3; + } + + outputf << "#include \n#include \nconst uint8_t " << arrayname << "[] = {"; + + uint64_t len = 0; + for (;;) { + unsigned char c = inputf.get(); + if (inputf.eof()) { + break; + } + outputf << (unsigned int)c << ','; + ++len; + } + + outputf << "};\nconst size_t " << arrayname << "_len = " << len << "ULL;"; + + return 0; +} diff --git a/meson.build b/meson.build index b8178bc7..8aa0e836 100644 --- a/meson.build +++ b/meson.build @@ -6,9 +6,6 @@ if host_system == 'darwin' error('\nThis Meson project no longer supports macOS. Please use the Xcode project instead.') endif -xxd = find_program('xxd', native: true) -xxd_supports_n = run_command(xxd, '-n', 'meson', '-i', meson.current_source_dir() / 'meson.build', check: false).returncode() == 0 - git_hash = run_command('git', 'rev-parse', '--short', 'HEAD').stdout().strip() compilers = {'cpp': meson.get_compiler('cpp')} @@ -117,6 +114,9 @@ endif global_args += '-DMKXPZ_INIT_GL_LATER' subdir('src') + +embedtool = executable('embedtool', sources: 'embedtool.cpp', native: true, override_options: []) + subdir('binding') subdir('shader') subdir('assets') diff --git a/shader/meson.build b/shader/meson.build index 31383552..adae8842 100644 --- a/shader/meson.build +++ b/shader/meson.build @@ -41,13 +41,12 @@ foreach file : embedded_shaders_f global_sources += custom_target(embedded_shaders[count], input: file, output: '@0@.xxd'.format(embedded_shaders[count]), - command: xxd_supports_n ? [ - xxd, '-n', '___shader_@0@'.format(embedded_shaders[count].replace('.', '_')), '-i', '@INPUT@' - ] : [ - xxd, '-i', '@INPUT@' + command: [ + embedtool, + '@INPUT@', + '@OUTPUT@', + 'mkxp_shader_@0@'.format(embedded_shaders[count].replace('.', '_')), ], - capture: true, - depend_files: embedded_shaders_f[count] ) count += 1 endforeach diff --git a/src/display/font.cpp b/src/display/font.cpp index 3b4befd6..2b0c1e6f 100644 --- a/src/display/font.cpp +++ b/src/display/font.cpp @@ -55,14 +55,8 @@ #define BUNDLED_FONT wqymicrohei #endif -#define BUNDLED_FONT_DECL(FONT) \ - extern unsigned char ___assets_##FONT##_ttf[]; \ - extern unsigned int ___assets_##FONT##_ttf_len; - -BUNDLED_FONT_DECL(liberation) - -#define BUNDLED_FONT_D(f) ___assets_## f ##_ttf -#define BUNDLED_FONT_L(f) ___assets_## f ##_ttf_len +#define BUNDLED_FONT_D(f) mkxp_assets_## f ##_ttf +#define BUNDLED_FONT_L(f) sizeof mkxp_assets_## f ##_ttf // Go fuck yourself CPP #define BNDL_F_D(f) BUNDLED_FONT_D(f) diff --git a/src/display/gl/shader.cpp b/src/display/gl/shader.cpp index aad98276..44ce4136 100644 --- a/src/display/gl/shader.cpp +++ b/src/display/gl/shader.cpp @@ -74,7 +74,7 @@ #else #define INIT_SHADER(vert, frag, name) \ { \ - Shader::init(___shader_##vert##_vert, ___shader_##vert##_vert_len, ___shader_##frag##_frag, ___shader_##frag##_frag_len, \ + Shader::init(mkxp_shader_##vert##_vert, sizeof mkxp_shader_##vert##_vert, mkxp_shader_##frag##_frag, sizeof mkxp_shader_##frag##_frag, \ #vert, #frag, #name); \ } #endif @@ -168,8 +168,8 @@ static void setupShaderSource(GLuint shader, GLenum type, } #ifndef MKXPZ_BUILD_XCODE - shaderSrc[i] = (const GLchar*) ___shader_common_h; - shaderSrcSize[i] = ___shader_common_h_len; + shaderSrc[i] = (const GLchar*) mkxp_shader_common_h; + shaderSrcSize[i] = sizeof mkxp_shader_common_h; #else shaderSrc[i] = (const GLchar*) Shader::commonHeader().c_str(); shaderSrcSize[i] = Shader::commonHeader().length(); diff --git a/src/eventthread.cpp b/src/eventthread.cpp index 2bd3b808..65085d61 100644 --- a/src/eventthread.cpp +++ b/src/eventthread.cpp @@ -184,7 +184,7 @@ void EventThread::process(RGSSThreadData &rtData) SDL_GameControllerAddMappingsFromFile(mkxp_fs::getPathForAsset("gamecontrollerdb", "txt").c_str()); #else SDL_GameControllerAddMappingsFromRW( - SDL_RWFromConstMem(___assets_gamecontrollerdb_txt, ___assets_gamecontrollerdb_txt_len), + SDL_RWFromConstMem(mkxp_assets_gamecontrollerdb_txt, sizeof mkxp_assets_gamecontrollerdb_txt), 1); #endif diff --git a/src/main.cpp b/src/main.cpp index 9aca9c06..92cbe9a0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -186,7 +186,7 @@ static void setupWindowIcon(const Config &conf, SDL_Window *win) { if (conf.iconPath.empty()) #ifndef MKXPZ_BUILD_XCODE - iconSrc = SDL_RWFromConstMem(___assets_icon_png, ___assets_icon_png_len); + iconSrc = SDL_RWFromConstMem(mkxp_assets_icon_png, sizeof mkxp_assets_icon_png); #else iconSrc = SDL_RWFromFile(mkxp_fs::getPathForAsset("icon", "png").c_str(), "rb"); #endif