cygwin.cygwinDllLinkHook: add tests

This commit is contained in:
David McFarland
2026-02-08 19:47:42 -04:00
parent dcebaab623
commit f1d9560d40
17 changed files with 264 additions and 0 deletions
@@ -10,4 +10,6 @@ makeSetupHook {
substitutions = {
objdump = "${lib.getBin binutils-unwrapped}/${stdenv.targetPlatform.config}/bin/objdump";
};
passthru.tests = callPackage ./tests { };
} ./cygwin-dll-link.sh
@@ -0,0 +1,130 @@
{
dieHook,
lib,
stdenv,
testers,
runCommand,
}:
rec {
dll = stdenv.mkDerivation {
name = "dll";
src = ./dll;
outputs = [
"out"
"dev"
];
buildInputs = [ dll2 ];
strictDeps = true;
};
dll2 = stdenv.mkDerivation {
name = "dll2";
src = ./dll2;
outputs = [
"out"
"dev"
];
};
exe = stdenv.mkDerivation {
name = "exe";
src = ./exe;
buildInputs = [ dll ];
nativeBuildInputs = [ dieHook ];
strictDeps = true;
doCheck = true;
postFixup = ''[[ -e "$out"/bin/cyghello2.dll ]] || die missing indirect dependency'';
};
link-dll = exe.overrideAttrs {
name = "link-dll";
preFixup = ''
ln -s ${lib.getLib dll}/bin/cyghello.dll "$out"/bin/
'';
};
user32 = stdenv.mkDerivation {
name = "user32";
src = ./user32;
allowedImpureDLLs = [ "USER32.dll" ];
};
impure-dll = testers.testBuildFailure (
user32.overrideAttrs {
name = "impure-dll";
allowedImpureDLLs = [ ];
}
);
user32-dll = stdenv.mkDerivation {
name = "user32-dll";
src = ./user32-dll;
outputs = [
"out"
"dev"
];
allowedImpureDLLs = [ "USER32.dll" ];
};
user32-exe = stdenv.mkDerivation {
name = "user32-exe";
src = ./user32-exe;
buildInputs = [ user32-dll ];
strictDeps = true;
doCheck = true;
};
link-dir-dll = exe.overrideAttrs {
name = "link-dir-dll";
preFixup = ''
mkdir "$out"/libexec
ln -s ${lib.getLib user32-dll}/bin/cygpeek.dll "$out"/libexec/
linkDLLsDir="$out"/bin linkDLLs "$out"/libexec/cygpeek.dll
'';
};
link-dir-exe = exe.overrideAttrs {
name = "link-dir-exe";
preFixup = ''
mkdir "$out"/libexec
ln -s ${lib.getLib user32-exe}/bin/{peek.exe,cygpeek.dll} "$out"/libexec/
linkDLLsDir="$out"/bin linkDLLs "$out"/libexec/peek.exe
'';
};
link-user32-dll = exe.overrideAttrs {
name = "link-user32-dll";
preFixup = ''
ln -s ${lib.getLib user32-dll}/bin/cygpeek.dll "$out"/bin/
'';
};
copy-dll-impure = testers.testBuildFailure (
user32-exe.overrideAttrs {
name = "copy-dll-impure";
preFixup = ''
cp ${lib.getLib user32-dll}/bin/cygpeek.dll "$out"/bin/
'';
}
);
copy-dll = user32-exe.overrideAttrs {
name = "copy-dll";
preFixup = ''
cp ${lib.getLib user32-dll}/bin/cygpeek.dll "$out"/bin/
linkDLLs "$out"/bin/cygpeek.dll
'';
allowedImpureDLLs = [ "USER32.dll" ];
};
double-link = user32-exe.overrideAttrs {
name = "double-link";
preFixup = ''linkDLLs "$out"'';
};
utf8-glob = runCommand "utf8-glob" { } ''
touch NetLock_Arany_=Class_Gold=_Főtanstvny:49412ce40010.crt
ls -l NetLock* > "$out"
'';
}
@@ -0,0 +1,16 @@
.PHONY: all install
all: cyghello.dll
install: $(out)/bin/cyghello.dll $(out)/lib/libhello.dll.a $(out)/include/hello.h
cyghello.dll libhello.dll.a: hello.c
$(CC) -o $@ $^ -shared -Wl,--out-implib,libhello.dll.a -Wl,--export-all-symbols -lhello2
$(out)/bin/cyghello.dll: cyghello.dll
install -m755 -D $< $@
$(out)/lib/libhello.dll.a: libhello.dll.a
install -m644 -D $< $@
$(out)/include/hello.h: hello.h
install -m644 -D $< $@
@@ -0,0 +1,7 @@
#include "hello.h"
#include <stdio.h>
#include <hello2.h>
void hello() {
hello2();
}
@@ -0,0 +1,2 @@
#pragma once
void hello();
@@ -0,0 +1,16 @@
.PHONY: all install
all: cyghello2.dll
install: $(out)/bin/cyghello2.dll $(out)/lib/libhello2.dll.a $(out)/include/hello2.h
cyghello2.dll libhello2.dll.a: hello2.c
$(CC) -o $@ $^ -shared -Wl,--out-implib,libhello2.dll.a -Wl,--export-all-symbols
$(out)/bin/cyghello2.dll: cyghello2.dll
install -m755 -D $< $@
$(out)/lib/libhello2.dll.a: libhello2.dll.a
install -m644 -D $< $@
$(out)/include/hello2.h: hello2.h
install -m644 -D $< $@
@@ -0,0 +1,6 @@
#include <stdio.h>
#include "hello2.h"
void hello2() {
printf("Hello, World!\n");
}
@@ -0,0 +1,2 @@
#pragma once
void hello2();
@@ -0,0 +1,13 @@
.PHONY: all check install
all: hello.exe
install: $(out)/bin/hello.exe
hello.exe: main.c
$(CC) -o $@ $^ -lhello
check: hello.exe
./hello.exe
$(out)/bin/hello.exe: hello.exe
install -m755 -D $< $@
@@ -0,0 +1,6 @@
#include <hello.h>
int main() {
hello();
return 0;
}
@@ -0,0 +1,16 @@
.PHONY: all install
all: cygpeek.dll
install: $(out)/bin/cygpeek.dll $(out)/lib/libpeek.dll.a $(out)/include/peek.h
cygpeek.dll libpeek.dll.a: peek.c
$(CC) -o $@ $^ -shared -Wl,--out-implib,libpeek.dll.a -Wl,--export-all-symbols
$(out)/bin/cygpeek.dll: cygpeek.dll
install -m755 -D $< $@
$(out)/lib/libpeek.dll.a: libpeek.dll.a
install -m644 -D $< $@
$(out)/include/peek.h: peek.h
install -m644 -D $< $@
@@ -0,0 +1,7 @@
#include <windows.h>
int peek()
{
MSG msg;
PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
}
@@ -0,0 +1,2 @@
#pragma once
void peek();
@@ -0,0 +1,13 @@
.PHONY: all check install
all: peek.exe
install: $(out)/bin/peek.exe
peek.exe: main.c
$(CC) -o $@ $^ -lpeek
check: peek.exe
./peek.exe
$(out)/bin/peek.exe: peek.exe
install -m755 -D $< $@
@@ -0,0 +1,6 @@
#include <peek.h>
int main() {
peek();
return 0;
}
@@ -0,0 +1,13 @@
.PHONY: all check install
all: hello.exe
install: $(out)/bin/hello.exe
hello.exe: main.c
$(CC) -o $@ $^
check: hello.exe
./hello.exe
$(out)/bin/hello.exe: hello.exe
install -m755 -D $< $@
@@ -0,0 +1,7 @@
#include <windows.h>
int main()
{
MSG msg;
PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
}