Skip to content

Commit db55277

Browse files
committed
Work on windows installer.
We will probably shift to NSIS as the default installation method for windows. Shipping around a single binary just doesn't cut it if we want to be able to reliably use tools like `jpm` to build things.
1 parent 7581821 commit db55277

File tree

11 files changed

+517
-63
lines changed

11 files changed

+517
-63
lines changed

assets/icon.ico

99.7 KB
Binary file not shown.

assets/icon_svg.svg

+11
Loading

build_win.bat

+6-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ for %%f in (src\boot\*.c) do (
5353
)
5454
%JANET_LINK% /out:build\janet_boot.exe build\boot\*.obj
5555
@if errorlevel 1 goto :BUILDFAIL
56-
build\janet_boot build\core_image.c JANET_PATH "C:/Janet/Library"
56+
build\janet_boot build\core_image.c
5757

5858
@rem Build the core image
5959
@%JANET_COMPILE% /Fobuild\core_image.obj build\core_image.c
@@ -65,14 +65,17 @@ for %%f in (src\core\*.c) do (
6565
@if errorlevel 1 goto :BUILDFAIL
6666
)
6767

68+
@rem Build the resources
69+
rc /nologo /fobuild\janet_win.res janet_win.rc
70+
6871
@rem Build the main client
6972
for %%f in (src\mainclient\*.c) do (
7073
@%JANET_COMPILE% /Fobuild\mainclient\%%~nf.obj %%f
7174
@if errorlevel 1 goto :BUILDFAIL
7275
)
7376

7477
@rem Link everything to main client
75-
%JANET_LINK% /out:janet.exe build\core\*.obj build\mainclient\*.obj build\core_image.obj
78+
%JANET_LINK% /out:janet.exe build\core\*.obj build\mainclient\*.obj build\core_image.obj build\janet_win.res
7679
@if errorlevel 1 goto :BUILDFAIL
7780

7881
@rem Gen amlag
@@ -132,6 +135,7 @@ copy src\include\janetconf.h dist\janetconf.h
132135
copy tools\cook.janet dist\cook.janet
133136
copy tools\highlight.janet dist\highlight.janet
134137
copy tools\jpm dist\jpm
138+
copy tools\jpm.bat dist\jpm.bat
135139
exit /b 0
136140

137141
:TESTFAIL

janet-installer.nsi

+147-40
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,162 @@
1+
# Use the modern UI
12
!define MULTIUSER_EXECUTIONLEVEL Highest
23
!define MULTIUSER_MUI
34
!define MULTIUSER_INSTALLMODE_COMMANDLINE
4-
!define MULTIUSER_INSTALLMODE_INSTDIR "janet"
55
!include "MultiUser.nsh"
66
!include "MUI2.nsh"
7-
7+
!include ".\tools\EnvVarUpdate.nsh"
8+
9+
# Basics
810
Name "Janet"
9-
OutFile "janet-install.exe"
10-
11-
!define MUI_ABORTWARNING
12-
11+
OutFile "janet-installer.exe"
12+
13+
# Some Configuration
14+
!define APPNAME "Janet"
15+
!define DESCRIPTION "The Janet Programming Language"
16+
!define HELPURL "http://janet-lang.org"
17+
18+
# MUI Configuration
19+
!define MUI_ICON "assets\icon.ico"
20+
!define MUI_UNICON "assets\icon.ico"
21+
!define MUI_HEADERIMAGE
22+
!define MUI_HEADERIMAGE_BITMAP "assets\janet-w200.png"
23+
!define MUI_HEADERIMAGE_RIGHT
24+
25+
# Show a welcome page first
1326
!insertmacro MUI_PAGE_WELCOME
27+
28+
# License page
1429
!insertmacro MUI_PAGE_LICENSE "LICENSE"
15-
!insertmacro MUI_PAGE_COMPONENTS
30+
31+
# Pick Install Directory
1632
!insertmacro MULTIUSER_PAGE_INSTALLMODE
1733
!insertmacro MUI_PAGE_DIRECTORY
1834

19-
!insertmacro MUI_PAGE_INSTFILES
35+
page instfiles
2036

21-
!insertmacro MUI_PAGE_FINISH
37+
# Need to set a language.
38+
!insertmacro MUI_LANGUAGE "English"
39+
40+
function .onInit
41+
setShellVarContext all
42+
functionEnd
2243

23-
!insertmacro MUI_UNPAGE_CONFIRM
24-
!insertmacro MUI_UNPAGE_INSTFILES
44+
section "install"
45+
createDirectory "$INSTDIR\Library"
46+
createDirectory "$INSTDIR\C"
47+
createDirectory "$INSTDIR\bin"
48+
setOutPath $INSTDIR
49+
50+
file /oname=bin\janet.exe dist\janet.exe
51+
file /oname=logo.ico assets\icon.ico
52+
53+
file /oname=Library\cook.janet dist\cook.janet
54+
55+
file /oname=C\janet.h dist\janet.h
56+
file /oname=C\janetconf.h dist\janetconf.h
57+
file /oname=C\janet.lib dist\janet.lib
58+
file /oname=C\janet.exp dist\janet.exp
59+
file /oname=C\janet.c dist\janet.c
60+
61+
file /oname=bin\jpm.janet dist\jpm
62+
file /oname=bin\jpm.bat dist\jpm.bat
2563

26-
!insertmacro MUI_LANGUAGE "English"
64+
# Uninstaller - See function un.onInit and section "uninstall" for configuration
65+
writeUninstaller "$INSTDIR\uninstall.exe"
66+
67+
# Start Menu
68+
createShortCut "$SMPROGRAMS\Janet.lnk" "$INSTDIR\janet.exe" "" "$INSTDIR\logo.ico"
69+
70+
# HKLM (all users) vs HKCU (current user)
71+
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" JANET_PATH "$INSTDIR\Library"
72+
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" JANET_HEADERPATH "$INSTDIR\C"
73+
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" JANET_BINDIR "$INSTDIR\bin"
74+
75+
WriteRegExpandStr HKCU "Environment" JANET_PATH "$INSTDIR\Library"
76+
WriteRegExpandStr HKCU "Environment" JANET_HEADERPATH "$INSTDIR\C"
77+
WriteRegExpandStr HKCU "Environment" JANET_BINDIR "$INSTDIR\bin"
78+
79+
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
80+
81+
# Update path
82+
${EnvVarUpdate} $0 "PATH" "A" "HKCU" "$INSTDIR\bin" ; Append
83+
${EnvVarUpdate} $0 "PATH" "A" "HKLM" "$INSTDIR\bin" ; Append
84+
85+
# Registry information for add/remove programs
86+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Janet" "DisplayName" "Janet"
87+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Janet" "UninstallString" "$INSTDIR\uninstall.exe"
88+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Janet" "QuietUninstallString" "$INSTDIR\uninstall.exe /S"
89+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Janet" "InstallLocation" "$INSTDIR"
90+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Janet" "DisplayIcon" "$INSTDIR\logo.ico"
91+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Janet" "Publisher" "Janet-Lang.org"
92+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Janet" "HelpLink" "${HELPURL}"
93+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Janet" "URLUpdateInfo" "${HELPURL}"
94+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Janet" "URLInfoAbout" "${HELPURL}"
95+
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Janet" "DisplayVersion" "0.6.0"
96+
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Janet" "VersionMajor" 0
97+
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Janet" "VersionMinor" 6
98+
# There is no option for modifying or repairing the install
99+
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Janet" "NoModify" 1
100+
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Janet" "NoRepair" 1
101+
# Set the INSTALLSIZE constant (!defined at the top of this script) so Add/Remove Programs can accurately report the size
102+
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Janet" "EstimatedSize" 1000
103+
sectionEnd
104+
105+
# Uninstaller
106+
107+
function un.onInit
108+
SetShellVarContext all
109+
110+
#Verify the uninstaller - last chance to back out
111+
MessageBox MB_OKCANCEL "Permanantly remove Janet?" IDOK next
112+
Abort
113+
next:
114+
functionEnd
115+
116+
section "uninstall"
117+
118+
# Remove Start Menu launcher
119+
delete "$SMPROGRAMS\Janet.lnk"
120+
121+
# Remove files
122+
delete $INSTDIR\logo.ico
123+
124+
delete $INSTDIR\C\janet.c
125+
delete $INSTDIR\C\janet.h
126+
delete $INSTDIR\C\janet.lib
127+
delete $INSTDIR\C\janet.exp
128+
delete $INSTDIR\C\janetconf.h
129+
130+
delete $INSTDIR\bin\jpm.janet
131+
delete $INSTDIR\bin\jpm.bat
132+
delete $INSTDIR\bin\janet.exe
133+
134+
delete $INSTDIR\Library\cook.janet
135+
136+
# Remove env vars
137+
138+
DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" JANET_PATH
139+
DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" JANET_HEADERPATH
140+
DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" JANET_BINDIR
141+
142+
DeleteRegValue HKCU "Environment" JANET_PATH
143+
DeleteRegValue HKCU "Environment" JANET_HEADERPATH
144+
DeleteRegValue HKCU "Environment" JANET_BINDIR
145+
146+
# Unset PATH
147+
${un.EnvVarUpdate} $0 "PATH" "R" "HKCU" "$INSTDIR\bin" ; Remove
148+
${un.EnvVarUpdate} $0 "PATH" "R" "HKLM" "$INSTDIR\bin" ; Remove
149+
150+
# make sure windows knows about the change
151+
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
152+
153+
# Always delete uninstaller as the last action
154+
delete $INSTDIR\uninstall.exe
155+
156+
rmDir "$INSTDIR\Library"
157+
rmDir "$INSTDIR\C"
158+
rmDir "$INSTDIR\bin"
27159

28-
Section "Janet" BfWSection
29-
SetOutPath $INSTDIR
30-
File "janet.exe"
31-
WriteUninstaller "$INSTDIR\janet-uninstall.exe"
32-
33-
# Start Menu
34-
CreateShortCut "$SMPROGRAMS\Janet.lnk" "$INSTDIR\janet.exe" "" ""
35-
SectionEnd
36-
37-
Function .onInit
38-
!insertmacro MULTIUSER_INIT
39-
!insertmacro MUI_LANGDLL_DISPLAY
40-
FunctionEnd
41-
42-
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
43-
!insertmacro MUI_DESCRIPTION_TEXT ${BfWSection} "The Janet programming language."
44-
!insertmacro MUI_FUNCTION_DESCRIPTION_END
45-
46-
Section "Uninstall"
47-
Delete "$INSTDIR\janet.exe"
48-
Delete "$INSTDIR\janet-uninstall.exe"
49-
RMDir "$INSTDIR"
50-
SectionEnd
51-
52-
Function un.onInit
53-
!insertmacro MULTIUSER_UNINIT
54-
!insertmacro MUI_UNGETLANGUAGE
55-
FunctionEnd
160+
# Remove uninstaller information from the registry
161+
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Janet"
162+
sectionEnd

janet_win.rc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
IDI_MYICON ICON "assets\icon.ico"

src/boot/boot.janet

+4-3
Original file line numberDiff line numberDiff line change
@@ -1605,13 +1605,14 @@
16051605
(var module/*syspath*
16061606
"The path where globally installed libraries are located.
16071607
The default is set at build time and is /usr/local/lib/janet on linux/posix, and
1608-
on Windows is C:/Janet/Library."
1608+
on Windows is the empty string."
16091609
(or (process/opts "JANET_PATH") ""))
16101610

16111611
(var module/*headerpath*
16121612
"The path where the janet headers are installed. Useful for building
1613-
native modules or compiling code at runtime."
1614-
(process/opts "JANET_HEADERPATH"))
1613+
native modules or compiling code at runtime. Default on linux/posix is
1614+
/usr/local/include/janet, and on Windows is the empty string."
1615+
(or (process/opts "JANET_HEADERPATH") ""))
16151616

16161617
# Version of fexists that works even with a reduced OS
16171618
(if-let [has-stat (_env 'os/stat)]

src/mainclient/init.janet

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
(var *compile-only* false)
1313

1414
(if-let [jp (os/getenv "JANET_PATH")] (set module/*syspath* jp))
15+
(if-let [jp (os/getenv "JANET_HEADERPATH")] (set module/*headerpath* jp))
1516

1617
# Flag handlers
1718
(def handlers :private

0 commit comments

Comments
 (0)