Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to MinGW32, remove slipstream, statically link ijl15 #24

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Watcom CI
name: MinGW32 CI
on:
push:
branches: [ master ]
Expand All @@ -15,7 +15,7 @@ jobs:
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Configure
run: nix develop --command make -j4 slipstream
run: nix develop --command make -j8 all
- name: Upload
uses: actions/upload-artifact@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
gglog.txt
/.tmp/
/compile_flags.txt

/compile_commands.json
81 changes: 14 additions & 67 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
GO := go

WATCOM ?= /usr/bin/watcom
WCC := $(WATCOM)/binl64/wcc386
WLINK := $(WATCOM)/binl64/wlink
CC := i686-w64-mingw32-gcc
RM := rm
SRCDIR := src/
OBJDIR := obj/
WEBASSETDIR := web/asset/
WEBDISTDIR := web/dist/
VERSION ?= $(shell git describe --tags --always --dirty)

CFLAGS := \
-i$(WATCOM)/h \
-i$(WATCOM)/h/nt \
-i$(WATCOM)/h/nt/ddk \
-zl \
-s \
-bd \
-os \
-d0 \
-fr= \
-zq
CFLAGS :=

LDFLAGS := -nodefaultlibs -nostartfiles -lkernel32 -luser32 -Wl,--enable-stdcall-fixup -s

LDFLAGS := \
LIBPATH $(WATCOM)/lib386 \
LIBPATH $(WATCOM)/lib386/nt
LDFLAGS_MSVCRT := third_party/msvcrt/msvcrt.lib third_party/msvcrt/rtsyms.o

OBJS := \
obj/dll/rugburn/main.o \
Expand All @@ -37,78 +21,41 @@ OBJS := \
obj/hooks/comctl32/dynamic_patch.o \
obj/hooks/hooks.o \
obj/ld.o \
obj/bootstrap.o \
obj/common.o \
obj/config.o \
obj/hex.o \
obj/ijlfwd.o \
obj/json.o \
obj/patch.o \
obj/regex.o

IJL15OBJS := $(wildcard third_party/ijl/*.obj)

TESTOBJS := \
$(OBJS) \
obj/exe/test/main.o

WEBASSET := \
web/dist/index.html \
web/dist/style.css \
web/dist/main.js \
web/dist/wasm_exec.js

OUT := out/rugburn.dll
OUTEM := slipstrm/embedded/rugburn.dll
VEREM := slipstrm/embedded/version.txt
INSS := third_party/ijl/ijl15.dll
OUTSS := out/ijl15.dll
OUT := out/ijl15.dll
TESTOUT := out/test.exe
WEBOUT := web/dist/patcher.wasm
FLYPROJECT := rugburn-gg

ifneq ($(OS),Windows_NT)
EXECWIN := wine
endif

all: $(OUT) $(OUTEM) $(VEREM) $(TESTOUT) $(WEBOUT)
slipstream: $(OUTSS)
all: $(OUT) $(TESTOUT)

.PHONY: clean slipstream $(VEREM)
.PHONY: check clean

# Rugburn
$(OBJDIR)%.o: $(SRCDIR)%.c
@mkdir -p "$(dir $@)"
$(WCC) $(CFLAGS) "$<" "-fo=$@"
$(CC) -c $(CFLAGS) "$<" -o "$@"
$(OUT): $(OBJS)
@mkdir -p "$(dir $@)"
$(WLINK) $(LDFLAGS) NAME "$@" @export.def FILE {$(OBJS)}
$(OUTEM): $(OUT)
@cp $(OUT) $(OUTEM)
$(VEREM): $(OUTEM)
@echo -n "$(VERSION)" > $(VEREM)
$(CC) $(OBJS) $(IJL15OBJS) $(LDFLAGS_MSVCRT) $(LDFLAGS) -shared -o "$@" export.def -Wl,-e_DllMain
$(TESTOUT): $(TESTOBJS)
@mkdir -p "$(dir $@)"
$(WLINK) $(LDFLAGS) NAME "$@" @test.def FILE {${TESTOBJS}}

# Slipstream
$(INSS):
@echo "Error: $(INSS) binary missing - cannot use Slipstream."
@exit 1
$(OUTSS): $(OUT) $(INSS)
$(GO) run ./slipstrm/cmd/slipstrm $(INSS) $(OUT) $(OUTSS) $(VERSION)

# Website/web patcher
$(WEBDISTDIR)%: $(WEBASSETDIR)%
cp "$<" "$@"
web/dist/wasm_exec.js:
cp "$(shell go env GOROOT)/misc/wasm/wasm_exec.js" "$@"
$(WEBOUT): $(OUT) $(WEBASSET) web/patcher/patcher.go
GOOS=js GOARCH=wasm $(GO) build -o "$@" "./web/patcher"
watch:
while rm -f $(WEBOUT) && make $(WEBOUT) && go run ./web/testsrv.go -watch ./; do :; done
deploy:
nix run nixpkgs#skopeo -- --insecure-policy --debug copy docker-archive:"$(shell nix build .#dockerImage --print-out-paths)" docker://registry.fly.io/$(FLYPROJECT):latest --dest-creds x:"$(shell nix run nixpkgs#flyctl auth token)" --format v2s2
nix run nixpkgs#flyctl -- deploy -i registry.fly.io/$(FLYPROJECT):latest --remote-only
$(CC) $(TESTOBJS) $(LDFLAGS) -o "$@" -Wl,-e_start
check: out/test.exe
$(EXECWIN) out/test.exe | tappy
clean:
$(RM) -f $(OBJS) $(OUT) $(OUTSS) $(TESTOUT)
$(RM) -f $(OBJS) $(TESTOBJS) $(OUT) $(TESTOUT)
26 changes: 8 additions & 18 deletions export.def
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
FORMAT windows dll
RUNTIME windows = 4.0
ALIAS __DLLstart_ = '_DllMain@12'

OPTION START = '_DllMain@12'
OPTION STACK = 8k
OPTION ALIGN = 512
OPTION NODEFAULTLIBS
OPTION ELIMINATE
OPTION QUIET

EXPORT ijlGetLibVersion.1 = '_ijlGetLibVersion@0'
EXPORT ijlInit.2 = '_ijlInit@4'
EXPORT ijlFree.3 = '_ijlFree@4'
EXPORT ijlRead.4 = '_ijlRead@8'
EXPORT ijlWrite.5 = '_ijlWrite@8'
EXPORT ijlErrorStr.6 = '_ijlErrorStr@4'
EXPORT SlipstrmDllMain.7 = '_SlipstrmDllMain@12'
LIBRARY IJL15
EXPORTS
ijlGetLibVersion @1
ijlInit @2
ijlFree @3
ijlRead @4
ijlWrite @5
ijlErrorStr @6
8 changes: 0 additions & 8 deletions exportvs.def

This file was deleted.

102 changes: 60 additions & 42 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,95 @@
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
outputs =
{
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
common = {

# Common dependencies
nativeBuildInputs = [
pkgs.makeWrapper
pkgs.bear
pkgs.pkgsCross.mingw32.stdenv.cc
];

nativeCheckInputs = [ pkgs.python3Packages.tappy ];

# Rugburn derivation
rugburn = pkgs.stdenv.mkDerivation {
name = "rugburn";
src = self;
nativeBuildInputs = with pkgs; [
# Build
makeWrapper
go_1_22
open-watcom-v2

# Test
python3Packages.tappy
wine
];

inherit nativeBuildInputs;

nativeCheckInputs = nativeCheckInputs ++ [ pkgs.wine ];

checkPhase = ''
runHook preCheck

export WINEPREFIX="$TMPDIR/.wine"
make check

runHook postCheck
'';

buildPhase = ''
make
runHook preBuild

bear -- make -j

runHook postBuild
'';

installPhase = ''
install -D -t $out/lib out/rugburn.dll
cp -r web/dist $out/dist
runHook preInstall

install -D -t $out/lib out/ijl15.dll
install -D --mode=0644 -t $out compile_commands.json

runHook postInstall
'';
vendorHash = (pkgs.lib.fileContents ./go.mod.sri);
WATCOM = "${pkgs.open-watcom-v2.out}";
};
rugburn = pkgs.buildGo122Module common;
devShell = pkgs.mkShell (common // {
nativeBuildInputs = with pkgs; [
# Build
makeWrapper
go_1_22
open-watcom-v2

# Test
python3Packages.tappy

# Development
gopls
clang-tools
];
});

# Dev shell
devShell = pkgs.mkShell { nativeBuildInputs = nativeBuildInputs ++ nativeCheckInputs; };

# Clangd setup
setupClangd = pkgs.writeShellScriptBin "setup-clangd.sh" ''
export WATCOM="${pkgs.open-watcom-v2.out}";
exec ${./scripts/setup-clangd.sh} "$@"
'';
updateVendorHash = pkgs.writeShellScriptBin "update-vendor-hash.sh" ''
export PATH="${pkgs.lib.makeBinPath [ pkgs.go_1_22 ]}:$PATH"
exec ${./scripts/update-vendor-hash.sh} "$@"
install -D --mode=0644 -t . ${rugburn}/compile_commands.json
'';

# Website setup
caddyfile = pkgs.writeText "caddyfile" ''
:8080
root * ${rugburn}/dist
file_server
'';

web = pkgs.writeShellScriptBin "web.sh" ''
exec ${pkgs.caddy}/bin/caddy run --adapter caddyfile --config ${caddyfile}
'';

dockerImage = pkgs.dockerTools.buildImage {
name = "rugburn-docker";
config.Cmd = [ "${web}/bin/web.sh" ];
};
in {
in
{
inherit devShell;
packages = {
inherit rugburn setupClangd updateVendorHash web dockerImage;
inherit
rugburn
setupClangd
web
dockerImage
;
default = rugburn;
};
}
Expand Down
40 changes: 0 additions & 40 deletions fly.toml

This file was deleted.

Loading
Loading