Skip to content

Commit

Permalink
Migrate to MinGW32, remove slipstream, statically link ijl15
Browse files Browse the repository at this point in the history
  • Loading branch information
jchv committed Jul 21, 2024
1 parent 1c974a1 commit 845ee1e
Show file tree
Hide file tree
Showing 75 changed files with 268 additions and 2,307 deletions.
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
82 changes: 15 additions & 67 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
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 := \
LIBPATH $(WATCOM)/lib386 \
LIBPATH $(WATCOM)/lib386/nt
LDFLAGS := -nodefaultlibs -nostartfiles -lkernel32 -luser32 -Wl,--enable-stdcall-fixup -s

OBJS := \
obj/dll/rugburn/main.o \
Expand All @@ -37,78 +19,44 @@ 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/ijl.o \
obj/json.o \
obj/patch.o \
obj/regex.o

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

LDFLAGS_MSVCRT := third_party/msvcrt/msvcrt.lib third_party/msvcrt/exceptlist.o

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.

10 changes: 5 additions & 5 deletions rugburn.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<Link>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<ModuleDefinitionFile>exportvs.def</ModuleDefinitionFile>
<ModuleDefinitionFile>export.def</ModuleDefinitionFile>
<EntryPointSymbol>DllMain</EntryPointSymbol>
<AdditionalDependencies>kernel32.lib;user32.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
Expand All @@ -124,7 +124,7 @@
<Link>
<SubSystem>Console</SubSystem>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<ModuleDefinitionFile>exportvs.def</ModuleDefinitionFile>
<ModuleDefinitionFile>export.def</ModuleDefinitionFile>
<EntryPointSymbol>DllMain</EntryPointSymbol>
<AdditionalDependencies>kernel32.lib;user32.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
Expand All @@ -147,7 +147,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<ModuleDefinitionFile>exportvs.def</ModuleDefinitionFile>
<ModuleDefinitionFile>export.def</ModuleDefinitionFile>
<EntryPointSymbol>DllMain</EntryPointSymbol>
<AdditionalDependencies>kernel32.lib;user32.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
Expand All @@ -170,7 +170,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<ModuleDefinitionFile>exportvs.def</ModuleDefinitionFile>
<ModuleDefinitionFile>export.def</ModuleDefinitionFile>
<EntryPointSymbol>DllMain</EntryPointSymbol>
<AdditionalDependencies>kernel32.lib;user32.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
Expand All @@ -196,7 +196,7 @@
<ClCompile Include="src\hooks\projectg\us852\ranking.c" />
</ItemGroup>
<ItemGroup>
<None Include="exportvs.def" />
<None Include="export.def" />
<None Include="LICENSE.md" />
<None Include="README.md" />
<None Include="src\third_party\lend\COPYING" />
Expand Down
Loading

0 comments on commit 845ee1e

Please sign in to comment.