Procházet zdrojové kódy

Merge pull request #2600 from Hyrtwol/icon-for-odin-exe

Icon for odin.exe
Jeroen van Rijn před 10 měsíci
rodič
revize
791b05b14f
7 změnil soubory, kde provedl 198 přidání a 6 odebrání
  1. 3 0
      .gitignore
  2. 33 6
      build.bat
  3. 75 0
      examples/demo/demo.rc
  4. binární
      misc/emblem.ico
  5. 8 0
      misc/odin.manifest
  6. 79 0
      misc/odin.rc
  7. binární
      misc/sourcefile.ico

+ 3 - 0
.gitignore

@@ -266,6 +266,9 @@ bin/
 *.exe
 *.obj
 *.pdb
+*.res
+desktop.ini
+Thumbs.db
 
 # - Linux/MacOS
 odin

+ 33 - 6
build.bat

@@ -22,9 +22,9 @@ if "%VSCMD_ARG_TGT_ARCH%" neq "x64" (
 for /f "usebackq tokens=1,2 delims=,=- " %%i in (`wmic os get LocalDateTime /value`) do @if %%i==LocalDateTime (
 	set CURR_DATE_TIME=%%j
 )
-
 set curr_year=%CURR_DATE_TIME:~0,4%
 set curr_month=%CURR_DATE_TIME:~4,2%
+set curr_day=%CURR_DATE_TIME:~6,2%
 
 :: Make sure this is a decent name and not generic
 set exe_name=odin.exe
@@ -45,7 +45,19 @@ if "%2" == "1" (
 	set nightly=0
 )
 
-set odin_version_raw="dev-%curr_year%-%curr_month%"
+if %release_mode% equ 0 (
+	set V1=%curr_year%
+	set V2=%curr_month%
+	set V3=%curr_day%
+) else (
+	set V1=%curr_year%
+	set V2=%curr_month%
+	set V3=0
+)
+set V4=0
+set odin_version_full="%V1%.%V2%.%V3%.%V4%"
+set odin_version_raw="dev-%V1%-%V2%"
+
 
 set compiler_flags= -nologo -Oi -TP -fp:precise -Gm- -MP -FC -EHsc- -GR- -GF
 rem Parse source code as utf-8 even on shift-jis and other codepages
@@ -53,18 +65,29 @@ rem See https://learn.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-a
 set compiler_flags= %compiler_flags% /utf-8
 set compiler_defines= -DODIN_VERSION_RAW=\"%odin_version_raw%\"
 
+rem fileversion is defined as {Major,Minor,Build,Private: u16} so a bit limited
+set rc_flags=-nologo ^
+-DV1=%V1% -DV2=%V2% -DV3=%V3% -DV4=%V4% ^
+-DVF=%odin_version_full% -DNIGHTLY=%nightly%
+
 if not exist .git\ goto skip_git_hash
 for /f "tokens=1,2" %%i IN ('git show "--pretty=%%cd %%h" "--date=format:%%Y-%%m" --no-patch --no-notes HEAD') do (
 	set odin_version_raw=dev-%%i
 	set GIT_SHA=%%j
 )
-if %ERRORLEVEL% equ 0 set compiler_defines=%compiler_defines% -DGIT_SHA=\"%GIT_SHA%\"
+if %ERRORLEVEL% equ 0 (
+	set compiler_defines=%compiler_defines% -DGIT_SHA=\"%GIT_SHA%\"
+	set rc_flags=%rc_flags% -DGIT_SHA=%GIT_SHA% -DVP=%odin_version_raw%:%GIT_SHA%
+) else (
+	set rc_flags=%rc_flags% -DVP=%odin_version_raw%
+)
 :skip_git_hash
 
 if %nightly% equ 1 set compiler_defines=%compiler_defines% -DNIGHTLY
 
 if %release_mode% EQU 0 ( rem Debug
 	set compiler_flags=%compiler_flags% -Od -MDd -Z7
+	set rc_flags=%rc_flags% -D_DEBUG
 ) else ( rem Release
 	set compiler_flags=%compiler_flags% -O2 -MT -Z7
 	set compiler_defines=%compiler_defines% -DNO_ARRAY_BOUNDS_CHECK
@@ -82,6 +105,8 @@ set libs= ^
 	kernel32.lib ^
 	Synchronization.lib ^
 	bin\llvm\windows\LLVM-C.lib
+set odin_res=misc\odin.res
+set odin_rc=misc\odin.rc
 
 rem DO NOT TOUCH!
 rem THIS TILDE STUFF IS FOR DEVELOPMENT ONLY!
@@ -93,7 +118,7 @@ if %tilde_backend% EQU 1 (
 rem DO NOT TOUCH!
 
 
-set linker_flags= -incremental:no -opt:ref -subsystem:console
+set linker_flags= -incremental:no -opt:ref -subsystem:console -MANIFEST:EMBED
 
 if %release_mode% EQU 0 ( rem Debug
 	set linker_flags=%linker_flags% -debug /NATVIS:src\odin_compiler.natvis
@@ -102,19 +127,21 @@ if %release_mode% EQU 0 ( rem Debug
 )
 
 set compiler_settings=%compiler_includes% %compiler_flags% %compiler_warnings% %compiler_defines%
-set linker_settings=%libs% %linker_flags%
+set linker_settings=%libs% %odin_res% %linker_flags%
 
 del *.pdb > NUL 2> NUL
 del *.ilk > NUL 2> NUL
 
+rc %rc_flags% %odin_rc%
 cl %compiler_settings% "src\main.cpp" "src\libtommath.cpp" /link %linker_settings% -OUT:%exe_name%
+mt -nologo -inputresource:%exe_name%;#1 -manifest misc\odin.manifest -outputresource:%exe_name%;#1 -validate_manifest -identity:"odin, processorArchitecture=amd64, version=%odin_version_full%, type=win32"
 if %errorlevel% neq 0 goto end_of_build
 
 call build_vendor.bat
 if %errorlevel% neq 0 goto end_of_build
 
 rem If the demo doesn't run for you and your CPU is more than a decade old, try -microarch:native
-if %release_mode% EQU 0 odin run examples/demo -vet -strict-style -- Hellope World
+if %release_mode% EQU 0 odin run examples/demo -vet -strict-style -resource:examples/demo/demo.rc -- Hellope World
 
 rem Many non-compiler devs seem to run debug build but don't realize.
 if %release_mode% EQU 0 echo: & echo Debug compiler built. Note: run "build.bat release" if you want a faster, release mode compiler.

+ 75 - 0
examples/demo/demo.rc

@@ -0,0 +1,75 @@
+
+#define Filename "demo.exe"
+#define FileDescription "Odin demo project."
+#define ProductName "Odin Programming Language Demo"
+
+#include "winres.h"
+
+LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
+#pragma code_page(65001)
+
+#define IDI_ICON1                       101
+
+#define Q(x) #x
+#define QUOTE(x) Q(x)
+#define FMTVER(x,y,z,w) QUOTE(x.y.z.w)
+
+#ifndef V1
+#define V1 1
+#endif
+#ifndef V2
+#define V2 0
+#endif
+#ifndef V3
+#define V3 0
+#endif
+#ifndef V4
+#define V4 0
+#endif
+#ifndef ODIN_VERSION
+#define ODIN_VERSION FMTVER(V1,V2,V3,V4)
+#endif
+#ifndef GIT_SHA
+#define GIT_SHA _
+#endif
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION V1,V2,V3,V4
+ PRODUCTVERSION V1,V2,V3,V4
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "0409FDE9"
+        BEGIN
+            VALUE "CompanyName", "https://odin-lang.org/"
+            VALUE "FileDescription", "Odin Demo"
+            VALUE "FileVersion", FMTVER(V1,V2,V3,V4)
+            VALUE "InternalName", "demo.exe"
+            VALUE "LegalCopyright", "Copyright (c) 2016-2024 Ginger Bill. All rights reserved."
+            VALUE "OriginalFilename", "demo.exe"
+            VALUE "ProductName", "Odin Programming Language Demo"
+            VALUE "ProductVersion", QUOTE(ODIN_VERSION)
+            VALUE "Comments", QUOTE(ODIN_VERSION)
+			// PrivateBuild
+			// SpecialBuild
+			// custom values
+            VALUE "GitSha", QUOTE(GIT_SHA)
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        //0xFDE9=65001=CP_UTF8
+        VALUE "Translation", 0x0409, 0xFDE9
+    END
+END
+
+IDI_ICON1   ICON    "..\\..\\misc\\sourcefile.ico"

binární
misc/emblem.ico


+ 8 - 0
misc/odin.manifest

@@ -0,0 +1,8 @@
+<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
+<assembly xmlns='urn:schemas-microsoft-com:asm.v3' manifestVersion='1.0'>
+	<application>
+		<windowsSettings xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">
+			<activeCodePage>UTF-8</activeCodePage>
+		</windowsSettings>
+	</application>
+</assembly>

+ 79 - 0
misc/odin.rc

@@ -0,0 +1,79 @@
+
+#include "winres.h"
+
+// https://learn.microsoft.com/en-us/windows/win32/menurc/stringfileinfo-block
+
+LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
+#pragma code_page(65001) // CP_UTF8
+
+#define IDI_ICON1                       101
+#define IDI_ICON2                       102
+
+#ifndef V1
+#define V1 1
+#endif
+#ifndef V2
+#define V2 0
+#endif
+#ifndef V3
+#define V3 0
+#endif
+#ifndef V4
+#define V4 0
+#endif
+#ifndef VF
+#define VF "1.0.0.0"
+#endif
+#ifndef VP
+#define VP "1.0.0.0"
+#endif
+#ifndef GIT_SHA
+#define GIT_SHA 0
+#endif
+#ifndef NIGHTLY
+#define NIGHTLY 0
+#endif
+
+#define Q(x) #x
+#define QUOTE(x) Q(x)
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION V1,V2,V3,V4
+ PRODUCTVERSION V1,V2,V3,V4
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+    BLOCK "StringFileInfo"
+    BEGIN
+        BLOCK "0409FDE9"
+        BEGIN
+            VALUE "CompanyName", "https://odin-lang.org/"
+            VALUE "FileDescription", "Odin general-purpose programming language." // note this is shown in the task manager
+            VALUE "FileVersion", QUOTE(VF)
+            VALUE "InternalName", "odin.exe"
+            VALUE "LegalCopyright", "Copyright (c) 2016-2024 Ginger Bill. All rights reserved."
+            VALUE "OriginalFilename", "odin.exe"
+            VALUE "ProductName", "The Odin Programming Language"
+            VALUE "ProductVersion", QUOTE(VP)
+            VALUE "Comments", QUOTE(git-sha: GIT_SHA)
+			// custom values
+            VALUE "GitSha", QUOTE(GIT_SHA)
+            VALUE "NightlyBuild", QUOTE(NIGHTLY)
+        END
+    END
+    BLOCK "VarFileInfo"
+    BEGIN
+        //0xFDE9=65001=CP_UTF8
+        VALUE "Translation", 0x0409, 0xFDE9
+    END
+END
+
+IDI_ICON1   ICON    "emblem.ico"
+IDI_ICON2   ICON    "sourcefile.ico"

binární
misc/sourcefile.ico