Skip to content

Commit

Permalink
[32_8] xmake build libmogan on wasm
Browse files Browse the repository at this point in the history
Co-authored-by: 沈浪熊猫儿 <[email protected]>
  • Loading branch information
da-liii and 沈浪熊猫儿 authored Sep 8, 2023
1 parent 7e998ed commit 18dde97
Show file tree
Hide file tree
Showing 21 changed files with 309 additions and 142 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/ci-xmake-wasm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Build and Test by WASM

on:
push:
branches: [ branch-1.2 ]
paths:
- 'src/**'
- '!src/Plugins/Macos/**'
- '!src/Plugins/Windows/**'
- '!src/Plugins/Unix/**'
- 'tests/**'
- 'xmake.lua'
- '.github/workflows/ci-xmake-wasm.yml'
pull_request:
branches: [ branch-1.2 ]
paths:
- 'src/**'
- '!src/Plugins/Macos/**'
- '!src/Plugins/Windows/**'
- '!src/Plugins/Unix/**'
- 'tests/**'
- 'xmake.lua'
- '.github/workflows/ci-xmake-wasm.yml'

jobs:
wasmbuild:
runs-on: ubuntu-22.04
if: always()
steps:
- uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: branch@dev
- name: update repo
run: |
xrepo update-repo
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: set XMAKE_GLOBALDIR
run: echo "XMAKE_GLOBALDIR=${{ runner.workspace }}/xmake-global" >> $GITHUB_ENV
- name: cache packages from xrepo
uses: actions/cache@v2
with:
path: |
${{ env.XMAKE_GLOBALDIR }}/.xmake/packages
key: ${{ runner.os }}-xrepo-wasm-${{ hashFiles('**/packages.lua') }}
- name: cache xmake
uses: actions/cache@v2
with:
path: |
${{ github.workspace }}/build/.build_cache
key: ${{ runner.os }}-xmake-build-${{ hashFiles('**/xmake.lua') }}
- name: Install Qt wasm
uses: jurplel/install-qt-action@v3
with:
version: 6.5.2
arch: wasm_singlethread
host: 'linux'
target: 'desktop'
cache: 'true'
# workarounds in https://github.com/jurplel/install-qt-action/issues/181
aqtversion: '==3.1.*'
py7zrversion: '==0.20.*'
extra: '--autodesktop'
- name: config
run: xmake config --policies=build.ccache -o ${{ runner.workspace }}/build -vD -p wasm -m releasedbg --yes
- name: build
run: xmake build libmogan
7 changes: 1 addition & 6 deletions bin/config_wasm
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#!/usr/bin/env elvish

xrepo install -y "emscripten 3.1.42"
xmake config -p wasm --qt=~/6.5.2/wasm_singlethread/ --yes

var pkg_info = (xrepo fetch --json emscripten | from-json)
var emsdk_path = $pkg_info[0][artifacts][installdir]
set-env EMSDK $emsdk_path

xmake config --yes -p wasm -vD
2 changes: 1 addition & 1 deletion misc/xmake/packages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ package_end()


function add_requires_of_mogan()
local LOLLY_VERSION = "1.2.0"
local LOLLY_VERSION = "1.2.3"
local CURL_VERSION = "7.84.0"
local FREETYPE_VERSION = "2.12.1"
local PDFHUMMUS_VERSION = "4.5.10"
Expand Down
14 changes: 14 additions & 0 deletions src/Mogan/Research/research.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ TeXmacs_init_paths (int& argc, char** argv) {
as_string (exedir * "/system/lib/TeXmacs/bin"));
#endif

#ifdef OS_WASM
set_env ("PWD", "/");
set_env ("HOME", "/");
if (is_empty (current_texmacs_path)) set_env ("TEXMACS_PATH", "/TeXmacs");
#endif

// check on the latest $TEXMACS_PATH
current_texmacs_path= get_env ("TEXMACS_PATH");
if (is_empty (current_texmacs_path) ||
Expand Down Expand Up @@ -333,6 +339,10 @@ TeXmacs_main (int argc, char** argv) {
retina_factor= 2;
retina_zoom = 1;
retina_scale = 1.4;
#elif defined(OS_WASM)
retina_factor= 2;
retina_zoom = 2;
retina_scale = (tm_style_sheet == "" ? 1.0 : 1.6666);
#else
retina_factor= 1;
retina_zoom = 2;
Expand Down Expand Up @@ -595,6 +605,8 @@ immediate_options (int argc, char** argv) {
#elif defined(OS_HAIKU)
set_env ("TEXMACS_HOME_PATH",
get_env ("HOME") * "/config/settings/TeXmacs");
#elif defined(OS_WASM)
set_env ("TEXMACS_HOME_PATH", "/.Xmacs");
#else
set_env ("TEXMACS_HOME_PATH", get_env ("HOME") * "/.TeXmacs");
#endif
Expand Down Expand Up @@ -695,10 +707,12 @@ main (int argc, char** argv) {
#ifndef OS_MINGW
set_env ("LC_NUMERIC", "POSIX");
#ifndef OS_MACOS
#ifndef OS_WASM
set_env ("QT_QPA_PLATFORM", "xcb");
set_env ("XDG_SESSION_TYPE", "x11");
#endif
#endif
#endif
#ifdef MACOSX_EXTENSIONS
// Reset TeXmacs if Alt is pressed during startup
if (mac_alternate_startup ()) {
Expand Down
9 changes: 9 additions & 0 deletions src/Plugins/LaTeX_Preview/latex_preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ set_latex_command (string cmd) {
latex_command= cmd;
}

#ifdef OS_WASM
array<tree>
latex_preview (string s, tree t) {
dbg ("LaTeX preview disabled in WASM");
return array<tree>();
}
#else

bool
latex_present () {
return exists_in_path (latex_command);
Expand Down Expand Up @@ -235,3 +243,4 @@ latex_preview (string s, tree t) {
latex_clean_tmp_directory (wdir);
return r;
}
#endif // OS_WASM
1 change: 0 additions & 1 deletion src/Plugins/Qt/QTMPipeLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,3 @@ QTMPipeLink::killProcess (int msecs) {
if (! waitForFinished (msecs)) kill ();
#endif
}

1 change: 0 additions & 1 deletion src/Plugins/Qt/QTMPipeLink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,3 @@ public slots:
};

#endif // QTM_PIPE_LINK

1 change: 0 additions & 1 deletion src/Plugins/Qt/QTMPrinterSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,4 +571,3 @@ WinQTMPrinterSettings::availablePrinters() {
}

#endif

2 changes: 0 additions & 2 deletions src/Plugins/Qt/qt_printer_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,3 @@ qt_printer_widget_rep::showDialog () {
if (!is_nil (commandAfterExecution))
commandAfterExecution ();
}


1 change: 1 addition & 0 deletions src/Plugins/Qt/qt_printer_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
******************************************************************************/

#ifndef QT_PRINTER_WIDGET_HPP
#define QT_PRINTER_WIDGET_HPP

Expand Down
2 changes: 2 additions & 0 deletions src/Plugins/Qt/qt_sys_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ string qt_get_pretty_os_name () {
return from_qstring (QSysInfo::prettyProductName ());
}

#if !defined (OS_WASM)
static void
ReadOutputs(QProcess& p, string& o, string& e) {
if (p.processChannelMode() == QProcess::MergedChannels)
Expand Down Expand Up @@ -85,3 +86,4 @@ qt_system (string cmd, string& result) {
proc.setProcessChannelMode (QProcess::MergedChannels);
return qt_system (proc, cmd, result, dummy);
}
#endif // !defined (OS_WASM)
19 changes: 18 additions & 1 deletion src/Plugins/Qt/qt_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <time.h>

#include <QImage>
#include <QPrinter>
#include <QPainter>
#include <QCoreApplication>
#include <QLocale>
Expand All @@ -26,8 +25,11 @@
#include <QStringList>
#include <QKeySequence>

#ifdef USE_QT_PRINTER
#include <QPrinter>
#include <QPrintDialog>
#endif

#include <QImageReader>
#include <QApplication>

Expand Down Expand Up @@ -470,6 +472,7 @@ qt_convert_image (url image, url dest, int w, int h) {// w, h in pixels
}
}

#ifdef USE_QT_PRINTER
void
qt_image_to_pdf (url image, url outfile, int w_pt, int h_pt, int dpi) {
// use a QPrinter to output raster images to eps or pdf
Expand Down Expand Up @@ -531,6 +534,12 @@ qt_image_to_pdf (url image, url outfile, int w_pt, int h_pt, int dpi) {
p.end();
}
}
#else
void
qt_image_to_pdf (url image, url outfile, int w_pt, int h_pt, int dpi){
if (DEBUG_CONVERT) debug_convert << "NOT SUPPORTED: qt_image_to_eps_or_pdf " << image << " -> "<<outfile<<LF;
}
#endif // defined(USE_QT_PRINTER)

void qt_image_to_eps(url image, url outfile, int w_pt, int h_pt, int dpi) {
qt_image_to_pdf(image, outfile, w_pt, h_pt, dpi);};
Expand Down Expand Up @@ -779,6 +788,7 @@ qt_pretty_time (int t) {
return from_qstring (s);
}

#ifdef USE_QT_PRINTER
#ifndef _MBD_EXPERIMENTAL_PRINTER_WIDGET // this is in qt_printer_widget
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#define PAPER(fmt) case QPrinter::fmt : return "fmt"
Expand Down Expand Up @@ -851,6 +861,13 @@ qt_print (bool& to_file, bool& landscape, string& pname, url& filename,
}

#endif //(not defined) _MBD_EXPERIMENTAL_PRINTER_WIDGET
#else
bool
qt_print (bool& to_file, bool& landscape, string& pname, url& filename,
string& first, string& last, string& paper_type) {
return false;
}
#endif // defined(USE_QT_PRINTER)


#ifdef OS_MACOS
Expand Down
8 changes: 8 additions & 0 deletions src/Plugins/Qt/qt_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,18 @@ widget file_chooser_widget (command cmd, string type, string prompt) {
if (headless_mode) return headless_widget ();
return tm_new<qt_chooser_widget_rep> (cmd, type, prompt);
}

#if !defined (USE_QT_PRINTER)
widget printer_widget (command cmd, url ps_pdf_file){
return widget();
}
#else
widget printer_widget (command cmd, url ps_pdf_file) {
if (headless_mode) return headless_widget ();
return tm_new<qt_printer_widget_rep> (cmd, ps_pdf_file);
}
#endif

widget texmacs_widget (int mask, command quit) {
if (headless_mode) return headless_widget ();
if (mask) return tm_new<qt_tm_widget_rep> (mask, quit);
Expand Down
2 changes: 1 addition & 1 deletion src/System/Boot/init_texmacs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ init_env_vars () {
static void
init_misc () {
// Test whether 'which' works
#ifdef OS_MINGW
#if defined(OS_MINGW) || defined(OS_WASM)
use_which = false;
#else
use_which = (var_eval_system ("which texmacs 2> /dev/null") != "");
Expand Down
10 changes: 9 additions & 1 deletion src/System/Link/pipe_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
******************************************************************************/

#include "basic.hpp"
#include "tm_link.hpp"

#if !(defined (QTTEXMACS) && (defined (OS_MINGW) || defined (QTPIPES)))
#if !(defined (QTTEXMACS) && (defined (OS_MINGW) || defined (QTPIPES) || defined(OS_WASM)))

#include "tm_link.hpp"
#include "socket_notifier.hpp"
Expand Down Expand Up @@ -376,3 +377,10 @@ void pipe_callback (void *obj, void *info) {
}

#endif // !(defined (QTTEXMACS) && defined (OS_MINGW))

#ifdef OS_WASM
tm_link make_pipe_link (string cmd) { return tm_link(); }

void close_all_pipes () {}
void process_all_pipes () {}
#endif
8 changes: 8 additions & 0 deletions src/System/Misc/tm_sys_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,20 @@ string get_pretty_os_name () {

int
system (string s, string& result, string& error) {
#ifdef OS_WASM
return -1;
#else
return qt_system (s, result, error);
#endif
}

int
system (string s, string& result) {
#ifdef OS_WASM
return -1;
#else
return qt_system (s, result);
#endif
}

string
Expand Down
10 changes: 4 additions & 6 deletions src/System/config.h.xmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/* L1 Kernel */
${define QTTEXMACS}
${define OS_MINGW}
${define OS_GNU_LINUX}
${define OS_MACOS}
${define OS_WASM}


/* Define to 1 if the system has the type `intptr_t'. */
${define HAVE_INTPTR_T}
Expand Down Expand Up @@ -77,10 +81,6 @@ ${define LINKED_SQLITE3}

${define MACOSX_EXTENSIONS}

${define OS_GNU_LINUX}

${define OS_MACOS}

${define PDFHUMMUS_NO_TIFF}

/* Disable fast memory allocator */
Expand Down Expand Up @@ -109,8 +109,6 @@ ${define QTPIPES}

${define USE_QT_PRINTER}

${define USE_CURL}

${define SANITY_CHECKS}

#define SIZEOF_VOID_P ${SIZEOF_VOID_P}
Expand Down
2 changes: 1 addition & 1 deletion src/System/config_l3.h.xmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#define KERNEL_L3
#define LOLLY_VERSION "@LOLLY_VERSION@"

/* L1 Kernel */
${define HAVE_INTPTR_T}
Expand All @@ -9,6 +8,7 @@ ${define SANITY_CHECKS}
${define OS_MINGW}
${define OS_MACOS}
${define OS_WIN}
${define OS_WASM}

/* L2 Kernel */
${define HAVE_TIME_T}
Expand Down
1 change: 1 addition & 0 deletions src/System/tm_configure_l3.hpp.xmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define BUILD_USER "@CONFIG_USER@"
#define BUILD_DATE "@VERSION_BUILD@"
#define TEXMACS_VERSION "@VERSION@"
#define LOLLY_VERSION "@LOLLY_VERSION@"
2 changes: 2 additions & 0 deletions src/Texmacs/Server/tm_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ tm_server_rep::refresh () {

void
tm_server_rep::interpose_handler () {
#ifndef OS_WASM
#ifdef QTTEXMACS
// TeXmacs/Qt handles delayed messages and socket notification
// in its own runloop
Expand All @@ -177,6 +178,7 @@ tm_server_rep::interpose_handler () {
perform_select ();
exec_pending_commands ();
#endif
#endif // not OS_WASM

if (!headless_mode) {
int i, j;
Expand Down
Loading

0 comments on commit 18dde97

Please sign in to comment.