Skip to content

Commit

Permalink
Improve windows compatibility and update build (@sp1ritCS)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackhole89 committed Apr 9, 2023
1 parent 9e6b9b2 commit 3dcf7e7
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 153 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,13 @@ jobs:
run: |
dnf config-manager --add-repo https://download.opensuse.org/repositories/home:sp1rit:mingw/Fedora_33/home:sp1rit:mingw.repo
dnf install -y mingw64-clatexmath mingw64-clatexmath-static
- name: Patch NoteKit 🩹
run: patch -p1 < windows.patch
- name: Configure 🔧
run: |
export CFLAGS="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4" \
LDFLAGS="-fstack-protector -lssp"
export CXXFLAGS="$CFLAGS"
meson --prefix=/ --cross-file=/usr/share/mingw/toolchain-mingw64.meson --default-library shared x86_64-w64-mingw32
run: meson --prefix=/ --cross-file=/usr/share/mingw/toolchain-mingw64.meson --default-library shared bin-x86_64-w64-mingw32
- name: Compile 🎲
run: ninja -C x86_64-w64-mingw32
run: ninja -C bin-x86_64-w64-mingw32
- name: Compress build artifacts 📦
run: |
pushd x86_64-w64-mingw32
pushd bin-x86_64-w64-mingw32
tar -c * | zstd -o $GITHUB_WORKSPACE/x86_64-w64-mingw32.tar.zst
popd
- name: Upload build artifacts 📤
Expand Down
12 changes: 3 additions & 9 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,14 @@ jobs:
run: |
dnf config-manager --add-repo https://download.opensuse.org/repositories/home:sp1rit:mingw/Fedora_33/home:sp1rit:mingw.repo
dnf install -y mingw64-clatexmath mingw64-clatexmath-static
- name: Patch NoteKit 🩹
run: patch -p1 < windows.patch
- name: Configure 🔧
run: |
export CFLAGS="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 -mwindows" \
LDFLAGS="-fstack-protector -lssp -mwindows -Wl,--subsystem,windows"
export CXXFLAGS="$CFLAGS"
meson --prefix=/ --cross-file=/usr/share/mingw/toolchain-mingw64.meson --default-library shared x86_64-w64-mingw32
run: meson --prefix=/ --cross-file=/usr/share/mingw/toolchain-mingw64.meson --default-library shared bin-x86_64-w64-mingw32
- name: Compile 🎲
run: ninja -C x86_64-w64-mingw32
run: ninja -C bin-x86_64-w64-mingw32
- name: Build Windows-compatible directory 📁
run: |
mkdir dist
DESTDIR="$PWD/dist/" ninja -C x86_64-w64-mingw32 install
DESTDIR="$PWD/dist/" ninja -C bin-x86_64-w64-mingw32 install
#cp $(x86_64-w64-mingw32-objdump -p dist/bin/notekit.exe | grep "DLL Name" | awk '{print $3}' | grep -vE '(KERNEL|msvcrt)' | sed "s|^|/usr/x86_64-w64-mingw32/sys-root/mingw/bin/|" | tr "\n" " ") dist/bin/
# fuck it, we'll ship the whole bin/ folder for now
cp -r /usr/x86_64-w64-mingw32/sys-root/mingw/bin/* dist/bin/
Expand Down
16 changes: 8 additions & 8 deletions Apple/llvm.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
From dab284742032488165f12dce09b10ab2187efea0 Mon Sep 17 00:00:00 2001
From ea003311a6137abe7bd5737900b9d9babfd0a299 Mon Sep 17 00:00:00 2001
From: sp1rit <[email protected]>
Date: Tue, 27 Apr 2021 09:31:41 +0200
Date: Mon, 30 Jan 2023 19:52:53 +0100
Subject: [PATCH] tweaks to llvm clang build

Signed-off-by: sp1rit <[email protected]>
Expand All @@ -10,12 +10,12 @@ Signed-off-by: sp1rit <[email protected]>
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/main.cpp b/main.cpp
index 02a736e..c97889e 100644
index 98b67a7..43904bc 100644
--- a/main.cpp
+++ b/main.cpp
@@ -9,8 +9,8 @@ int main (int argc, char *argv[])

@@ -23,8 +23,8 @@ int main (int argc, char *argv[])
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "com.github.blackhole89.notekit");
#endif

- app->signal_activate().connect( [app,&mainwindow]() {
- mainwindow=new CMainWindow(app);
Expand All @@ -25,17 +25,17 @@ index 02a736e..c97889e 100644
} );

diff --git a/meson.build b/meson.build
index 185a398..622e588 100644
index 6720b25..c43cee1 100644
--- a/meson.build
+++ b/meson.build
@@ -1,6 +1,6 @@
project('notekit', 'cpp',
version : '0.2.0',
version : '0.3.0',
- default_options : ['warning_level=3', 'cpp_std=c++14']
+ default_options : ['warning_level=3', 'cpp_std=c++17']
)

has_devenv = meson.version().version_compare('>=0.58.0')
--
2.38.1
2.39.1

4 changes: 2 additions & 2 deletions drawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,13 +416,13 @@ void CBoundDrawing::Unselect() {

void CBoundDrawing::on_unrealize()
{
printf("unrealize event on %08lX\n", (unsigned long) this);
printf("unrealize event on %p\n", (void*) this);
//get_parent()->remove(*this);
}

void CBoundDrawing::destroy_notify_()
{
printf("destroy event on %08lX\n", (unsigned long) this);
printf("destroy event on %p\n", (void*) this);
strokes.~vector<CStroke>();
}

Expand Down
4 changes: 2 additions & 2 deletions imagewidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ CImageWidget::CImageWidget(Glib::RefPtr<Gdk::Window> wnd) : Glib::ObjectBase("CI

void CImageWidget::on_unrealize()
{
printf("unrealize event on CImageWidget %08lX\n", (unsigned long) this);
printf("unrealize event on CImageWidget %p\n", (void*) this);
}

void CImageWidget::destroy_notify_()
{
printf("destroy event on CImageWidget %08lX\n", (unsigned long) this);
printf("destroy event on CImageWidget %p\n", (void*) this);
}

void CImageWidget::SetSize(int x, int y)
Expand Down
16 changes: 15 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,25 @@

CMainWindow *mainwindow;

#ifdef _WIN32
#include <windows.h>

int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
#else
int main (int argc, char *argv[])
#endif
{
Gsv::init();


#ifdef _WIN32
if (g_getenv("NK_WIN32_DEBUG") && AllocConsole()) {
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
}
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create("com.github.blackhole89.notekit");
#else
Glib::RefPtr<Gtk::Application> app = Gtk::Application::create(argc, argv, "com.github.blackhole89.notekit");
#endif

app->signal_activate().connect( [app,&mainwindow]() {
mainwindow=new CMainWindow(app);
Expand Down
10 changes: 9 additions & 1 deletion mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include "latex.h"
#endif

#ifdef _WIN32
#include <windows.h>
#endif

#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
Expand Down Expand Up @@ -510,9 +514,13 @@ void CMainWindow::FetchAndSave()
FILE *fl = fopen(tmp_filename.c_str(), "wb");
fwrite(str.c_str(),str.length(),1,fl);
fclose(fl);


#ifdef _WIN32
MoveFileExA(tmp_filename.c_str(), filename.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
#else
/* atomic replace */
rename(tmp_filename.c_str(), filename.c_str());
#endif
}

void CMainWindow::FetchAndExport()
Expand Down
21 changes: 16 additions & 5 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,29 @@ install_subdir('sourceview/', install_dir: get_option('datadir')/'notekit')

subdir('gnome')

executable('notekit',
src = [
'about.cpp',
'drawing.cpp',
'imagewidgets.cpp',
'main.cpp',
'mainwindow.cpp',
'navigation.cpp',
'notebook.cpp',
'settings.cpp',
dependencies: deps,
install : true
)
'settings.cpp'
]

if meson.version().version_compare('>=0.56.0')
executable('notekit', src,
dependencies: deps,
install : true,
win_subsystem: 'windows'
)
else
executable('notekit', src,
dependencies: deps,
install : true
)
endif

if has_devenv
meson.add_devenv(devenv)
Expand Down
2 changes: 1 addition & 1 deletion notebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ void CNotebook::SelectBox(float x0, float x1, float y0, float y1)
for(Gtk::Widget *w : get_children()) {
if(CBoundDrawing *d = CBoundDrawing::TryUpcast(w)) {
if(!seen.count(d)) {
printf("unsel %p\n",d);
printf("unsel %p\n",(void*)d);
d->Unselect();
}
}
Expand Down
14 changes: 9 additions & 5 deletions notebook_highlight.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
std::string CNotebook::GetHighlightProxyDir()
{
if(mkdir("/tmp/notekit.gsv",0777) && errno!=EEXIST) {
g_autofree gchar* dir = g_build_path("/", g_get_tmp_dir(), "notekit.gsv", NULL);
errno = 0;
if (g_mkdir_with_parents(dir, 0777) && errno!=EEXIST) {
printf("Failed to create a temporary directory for syntax highlighting data.\n");
return "";
}
if(!access("/tmp/notekit.gsv/markdownlisting.lang", R_OK)) {

g_autofree gchar* listing = g_build_path("/", dir, "markdownlisting.lang", NULL);
if(!access(listing, R_OK)) {
// file already exists
return "/tmp/notekit.gsv";
return std::string (dir);
}
FILE *fl = fopen("/tmp/notekit.gsv/markdownlisting.lang","wb");
FILE *fl = fopen(listing,"wb");
if(!fl) {
printf("Failed to create a language definition for syntax highlighting data.\n");
return "";
Expand Down Expand Up @@ -65,5 +69,5 @@ std::string CNotebook::GetHighlightProxyDir()

fclose(fl);

return "/tmp/notekit.gsv";
return std::string (dir);
}
110 changes: 0 additions & 110 deletions windows.patch

This file was deleted.

0 comments on commit 3dcf7e7

Please sign in to comment.