Fossil Forum

coz.eduardo.hernandez 1 month, 1 week ago

Post: I managed to compile FNC on Windows

Just a heads up, I looked for a way to split commits at the hunk level under Windows, without needing to create patches, and after some effort I managed to compile fnc. I had to do it under Cygwin as MSYS2 wasn't compatible enough. Maybe knowing what I changed will be useful to someone who wants a partial / interactive / selective stash right now.

The Cygwin packages that I installed are:

  • fossil
  • gcc-core
  • libbsd-devel
  • libncurses-devel
  • libssl1.1
  • make
  • vim
  • zlib-devel

This is the diff:

diff d0db20bfdf09e033ac102d1a93283f87d5b5599b /home/coz/fnc [~] fnc.bld.mk | 2 1 1 +- [~] include/fnc.h | 2 1 1 +- [~] lib/sqlite3.c | 10 6 4 ++++++---- [~] src/diff.c | 2 2 0 ++ [~] src/fnc.c | 6 5 1 +++++-

5 files changed, 15 insertions(+), 7 deletions(-)

Index: fnc.bld.mk

hash - 09559fb6c16860937e8ad5f0ee60d55bb418707d6642df2af6d40ddb3e7bc778 hash + 041ed6bb08d1d6f1717cd9a0c972e338f3b87e3cf418dc8a695800a871a8079e --- fnc.bld.mk +++ fnc.bld.mk @@ -47,11 +47,11 @@ FNC_CFLAGS = ${CFLAGS} -Wstrict-prototypes -Wmissing-proto # FLAGS NEEDED TO BUILD FNC FNC_CFLAGS = ${CFLAGS} -Wstrict-prototypes -Wmissing-prototypes -fPIC \ -Wunused-variable -I./lib -I./include -I/usr/include/ncursesw \ -DFNC_VERSION=${VERSION} -DFNC_HASH=${HASH} -DFNC_DATE="${DATE}"

-FNC_LDFLAGS = ${LDFLAGS} -lm -lutil -lz -lpthread +FNC_LDFLAGS = ${LDFLAGS} -lm -lutil -lz -lpthread -lbsd

# Compile-time checks and runtime protection mechanisms from the compiler # hardening document: https://best.openssf.org/Compiler-Hardening-Guides HARDEN = -Wstrict-overflow -Wformat -Werror=format-security \ -Werror=implicit -Werror=incompatible-pointer-types \

Index: include/fnc.h

hash - 8a96a0ef26f6688e7308b5de5a70c65f761d10422eb6ca946a61c0c62e90ef98 hash + d9f91da17de75fe64afddcfa90987e4a8178c897458d504bd5d6dba7e23b29f8 --- include/fnc.h +++ include/fnc.h @@ -22,11 +22,11 @@ / #if defined(OpenBSD) || defined(FreeBSD) || defined(APPLE) #define fnc_progname(_arg) memccpy(fnc__progname, getprogname(), \ '\0', sizeof(fnc__progname)) #elif defined(_GNU_SOURCE) -extern char program_invocation_short_name; +extern __declspec(dllimport) char *program_invocation_short_name;

#define fnc_progname(_arg) memccpy(fnc__progname, \ program_invocation_short_name, \ '\0', sizeof(fnc__progname)) #else

Index: lib/sqlite3.c

hash - 817858ea76a1e2a4a2418c083cd35adfba8f3d546ebc9b711cae3009dce7ba85 hash + 546ba14c71441fbe6bcb5cef5cdcf7e22aaa8207e0b2e31d735c45425629f522 --- lib/sqlite3.c +++ lib/sqlite3.c @@ -31334,12 +31334,12 @@ SQLITE_PRIVATE sqlite3_mutex_methods const *sqlite3De # define ALIGN128 __declspec(align(128)) #else # define ALIGN128 #endif

-#pragma warning(push) -#pragma warning(disable: 4324) +//#pragma warning(push) +//#pragma warning(disable: 4324) / ** Each SQLite mutex is an instance of the following structure. ** ** The ALIGN128 macro attempts to force 128-byte alignment on mutexes, ** so that adjacent mutex objects are always on different cache lines @@ -31358,11 +31358,11 @@ struct sqlite3_mutex { volatile int nRef; / Number of entrances / volatile DWORD owner; / Thread holding this mutex / volatile LONG trace; / True to trace changes */ #endif }; -#pragma warning(pop) +//#pragma warning(pop)

#ifdef SQLITE_DEBUG /* ** The sqlite3_mutex_held() and sqlite3_mutex_notheld() routine are ** intended for use only inside assert() statements. @@ -50051,18 +50051,20 @@ SQLITE_API void sqlite3_win32_sleep(DWORD millisecond

SQLITE_API void sqlite3_win32_sleep(DWORD milliseconds){ osSleep(milliseconds); }

+/ #if SQLITE_MAX_WORKER_THREADS>0 && SQLITE_THREADSAFE>0 SQLITE_PRIVATE DWORD sqlite3Win32Wait(HANDLE hObject){ DWORD rc; while( (rc = osWaitForSingleObjectEx(hObject, INFINITE, TRUE))==WAIT_IO_COMPLETION ){} return rc; } #endif +/

#ifdef SQLITE_WIN32_MALLOC / ** Allocate nBytes of memory. / @@ -53996,11 +53998,11 @@ static int winFullPathnameNoMutex( rc = SQLITE_CANTOPEN_BKPT; }

         if( rc==SQLITE_OK ){
           nByte = osReadlink(zIn, zDel, nFull-1);
  • if( nByte ==(DWORD)-1 ){
  • if( (unsigned int)(nByte) ==(DWORD)-1 ){ rc = winLogError(SQLITE_CANTOPEN_BKPT, (DWORD)osErrno, "readlink", zIn); }else{ if( zDel[0]!='/' ){ int n;

Index: src/diff.c

hash - 6b89266f7e4804827ff7665fb6537414435fff055c7e1a41038c33869c19fe1d hash + 87c01d6d17e0b78f0b599938b4bec33a71017e3f942dbd7d07a061951538dcb0 --- src/diff.c +++ src/diff.c @@ -31,10 +31,12 @@ * been imported with the author's blessing to hack on for fnc's opinionated * diff features. */

#include "fnc_compat.h" + +#define _GNU_SOURCE

#include #include #include #include

Index: src/fnc.c

hash - c47914822fb4fbfdf8744e8094d5d1e048b1c4dd3a8e52e7029677008816ae8b hash + 0b2828c1f9a72b821d2b1941557028d1d7099815f6c3c1cca1659dbcb1331287 --- src/fnc.c +++ src/fnc.c @@ -12,12 +12,15 @@ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + +#define _GNU_SOURCE

#include "fnc_compat.h" +

#include #include #include #include @@ -31,17 +34,18 @@ #endif

#include #include #include -#define _XOPEN_SOURCE_EXTENDED / curses wide-character functions / +//#define _XOPEN_SOURCE_EXTENDED / curses wide-character functions / #include #include #include #include #include #include +#include #include #include #include #include #include

stephan 1 month, 1 week ago

I managed to compile FNC on Windows

While attempting to merge this in the canonical fnc tree, these stuck out to me:

-#pragma warning(push)
-#pragma warning(disable: 4324)
+//#pragma warning(push)
+//#pragma warning(disable: 4324)

i'm very hesitant to remove any warnings because Mark is especially conscientious about such things. We've not heard from him in a while, but fnc is still hosted on his system, so i'd prefer his blessing before making changes like the warnings.

i'll get the cast-related bits merged in, in any case.

Thank you!

stephan 1 month, 1 week ago

I managed to compile FNC on Windows

While attempting to merge this in the canonical fnc tree, these stuck out to me:

-#pragma warning(push)
-#pragma warning(disable: 4324)
+//#pragma warning(push)
+//#pragma warning(disable: 4324)

i'm very hesitant to remove any warnings because Mark is especially conscientious about such things. We've not heard from him in a while, but fnc is still hosted on his system, so i'd prefer his blessing before making changes like the warnings.

i'll get the cast-related bits merged in, in any case. Edit: i missed that many of those changes are from sqlite3.c. Those won't be patched upstream (except maybe the cast).

Thank you!

mgagnon 1 month, 1 week ago

Also, to add to what Stephan said, SQLite3 by itself is already fully supported on windows (on many environments like msvc, msys2, cygwin, etc..)

Fossil can already be compiled for those with unmodified sqlite3 amalgamation file.

coz.eduardo.hernandez 1 month ago

The #pragma warning change would actually reenable the warning, but I agree with your cautiousness, I just changed things willy nilly in a way that 'probably' won't break anything, so I can't really guarantee anything. Regarding that warning, there's probably a similar one for GCC, so I'd say some testing would be needed to ensure the changes mirror the behavior as much as possible with GCC.

Any patches should probably be surrounded by #ifdefs that target Cygwin and GCC, so other platforms don't break.

But my post was really aimed at showing fnc can be compiled under Windows, for anyone who wants to mess with fnc's code at their own discretion. I'm happy if it's useful for anyone at all.

coz.eduardo.hernandez 1 month ago
Thank you!

Welcome.

The #pragma warning change would actually reenable the warning, but I agree with your cautiousness, I just changed things willy nilly in a way that 'probably' won't break anything, so I can't really guarantee anything. Regarding that warning, there's probably a similar one for GCC, so I'd say some testing would be needed to ensure the changes mirror the behavior as much as possible with GCC.

Any patches should probably be surrounded by #ifdefs that target Cygwin and GCC, so other platforms don't break.

But my post was really aimed at showing fnc can be compiled under Windows, for anyone who wants to mess with fnc's code at their own discretion. I'm happy if it's useful for anyone at all.

mark 1 month ago

Just a heads up, I looked for a way to split commits at the hunk level under Windows, without needing to create patches, and after some effort I managed to compile fnc. I had to do it under Cygwin as MSYS2 wasn't compatible enough. Maybe knowing what I changed will be useful to someone who wants a partial / interactive / selective stash right now.

this is really cool! i'd never have the chance to port fnc to windows as i don't have a windows machine, so thank you :)

fnc stash is one of my most frequently used commands. i recently added the 's' and 'e' options to split and edit hunks, too, which was something i wanted for a while. and more recently, fnc histedit to fold and drop commits has gotten a lot of mileage

i'm very hesitant to remove any warnings because Mark is especially conscientious about such things. We've not heard from him in a while, but fnc is still hosted on his system, so i'd prefer his blessing before making changes like the warnings.

thanks, Stephan! i trust your judgement implicitly, though, so please feel free to make whichever changes you decide :)

and sorry for my extended absence. i had to relocate to Sydney a while back when amazon had the RTO policy so i'm in the office all week, and on the weekends i would travel back down south to renovate the property; time for open source has been really hard to come by. i hope you're doing well!

coz.eduardo.hernandez 1 month ago
this is really cool! i'd never have the chance to port fnc to windows as i don't have a windows machine, so thank you :)

Heh, I ditched Windows but then I got an e-mail from my job saying I was connecting with an unapproved system, so I was forced to use Windows. I largely prefer other operating systems, so I often develop across them.

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button