Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dotnet-compile-native.bat « scripts « src - github.com/mono/corert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f90b4d0e80716070c97ed578e3b80d9259a7c793 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
@echo off
setlocal EnableDelayedExpansion

REM
REM Script to compile a MSIL assembly to native code. 
REM 
REM Supported code-generators: CPPCODEGEN, RyuJIT
REM

if "%VS140COMNTOOLS%" == "" (
	echo Please install Microsoft Visual Studio 2015.
	goto InvalidArgs
)

set __BuildArch=x64
set __Infile=
set __Outfile=
set __LibPath=
set __Temp=%temp%\
set __AppDepSdk=
set __ILCompiler=%~dp0
set __CompileMode=cpp
set __LogFilePath=%__Temp%
set __CodegenPath=
set __ObjgenPath=
set __LinkLibs=
set __AdditionalRefs=

:Arg_Loop
if "%1" == "" goto :ArgsDone
if /i "%1" == "x64"    (set __BuildArch=x64&&shift&goto Arg_Loop)

if /i "%1" == "debug"    (set __BuildType=Debug&shift&goto Arg_Loop)
if /i "%1" == "release"   (set __BuildType=Release&shift&goto Arg_Loop)

if /i "%1" == "/in" (set __Infile=%2&shift&shift&goto Arg_Loop)
if /i "%1" == "/out" (set __Outfile=%2&shift&shift&goto Arg_Loop)
if /i "%1" == "/appdepsdk" (set __AppDepSdk=%2&shift&shift&goto Arg_Loop)
if /i "%1" == "/mode" (set __CompileMode=%2&shift&shift&goto Arg_Loop)
if /i "%1" == "/logpath" (set __LogFilePath=%2&shift&shift&goto Arg_Loop)
if /i "%1" == "/codegenpath" (set __CodegenPath=%2&shift&shift&goto Arg_Loop)
if /i "%1" == "/objgenpath" (set __ObjgenPath=%2&shift&shift&goto Arg_Loop)
if /i "%1" == "/linklibs" (set __LinkLibs=%2&shift&shift&goto Arg_Loop)
if /i "%1" == "/reference" (set __AdditionalRefs=%__AdditionalRefs% -r %2&shift&shift&goto Arg_Loop)

echo Invalid command line argument: %1
goto :InvalidArgs

:ArgsDone

REM Do we have valid arguments?
if "%__Infile%" == "" (
	echo Please specify MSIL assembly to be compiled.
	goto :InvalidArgs
)	
if "%__Outfile%" == "" (
	echo Please specify the native executable to be generated.
	goto :InvalidArgs
)

if "%__AppDepSdk%" == "" (
	echo Please specify the path to the extracted Microsoft.DotNet.AppDep nuget package.
	goto :InvalidArgs
)

if "%__CompileMode%" == "" (
	echo Please specify a valid compilation mode.
	goto :InvalidArgs
)

REM Set path contain Runtime.lib/PortableRuntime.lib and System.Private.Corelib.dll
set __LibPath=%__ILCompiler%

REM Initialize environment to invoke native tools
call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" amd64

REM Extract the name of the MSIL file we are compiling
set AssemblyFileName=
set AssemblyExt=
for /f %%i IN (%__Infile%) DO (
	set AssemblyFileName=%%~ni
	set AssemblyExt=%%~xi
)

set Assembly=%AssemblyFileName%%AssemblyExt%

REM Validate the code-generation mode
if /i "%__CompileMode%" == "cpp" goto :ModeCPP
if /i "%__CompileMode%" == "ryujit" goto :ModeRyuJIT
echo Please specify a valid compilation mode.
goto :InvalidArgs

:ModeRyuJIT
REM *** RyuJIT Codegen ***
REM Generate the obj file for the MSIL assembly

set ObjFileName=%__Infile%.obj
call :DeleteFile %ObjFileName%
set libBootstrapper=%__LibPath%\bootstrapper.lib
set libRuntime=%__LibPath%\Runtime.lib

if not exist "%__CodegenPath%\%__CompileMode%.dll" (
	echo Unable to find %__CodegenPath%\%__CompileMode%.dll to compile application!
	goto :InvalidArgs
)

if not exist "%__ObjgenPath%\objwriter.dll" (
	echo Unable to find %__ObjgenPath%\objwriter.dll to generate generate binaries for application!
	goto :InvalidArgs
)

setlocal
REM Setup the path to include the location of the codegenerator and binary file generator
REM so that they can be located by the OS loader.
set path=%__CodegenPath%;%__ObjgenPath%;%path%
echo Generating app obj file
"%__ILCompiler%\corerun.exe" "%__ILCompiler%\ilc.exe" %__Infile% -r "%__ILCompiler%\System.Private.CoreLib.dll" -r %__AppDepSdk%\*.dll -out %ObjFileName% %__AdditionalRefs% > %__LogFilePath%\ILCompiler.App.log
endlocal

set EXITCode=%ERRORLEVEL%
if %EXITCode% GEQ 1 (
	echo Unable to generate App object file.
	goto :FailedExit
)

REM We successfully generated the object file, so proceed to link phase
goto :LinkObj

:ModeCPP
REM *** CPPCodegeneration ***
set CPPFileName=%__Infile%.cpp
set ObjFileName=%__Infile%.cpp.obj
set libBootstrapper=%__LibPath%\bootstrappercpp.lib
set libRuntime=%__LibPath%\PortableRuntime.lib

REM Perform basic cleanup
call :DeleteFile "%CPPFileName%"
call :DeleteFile "%ObjFileName%"
call :DeleteFile "%__Outfile%"


REM Generate the CPP file for the MSIL assembly
echo Generating source file
"%__ILCompiler%\ilc.exe" %__Infile% -r "%__ILCompiler%\System.Private.CoreLib.dll" -r %__AppDepSdk%\*.dll -out "%CPPFileName%" -cpp %__AdditionalRefs% > %__LogFilePath%\ILCompiler.MSILToCpp.log
if ERRORLEVEL 1 (
	echo Unable to generate CPP file.
	goto :FailedExit
)

set DefinesDebug=/ZI /nologo /W3 /WX- /sdl /Od /D CPPCODEGEN /D WIN32 /D _DEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline

set DefinesRelease=/Zi /nologo /W3 /WX- /sdl /O2 /Oi /GL /D CPPCODEGEN /D WIN32 /D NDEBUG /D _CONSOLE /D _LIB /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline

set LinkDebug=
set LinkRelease=/INCREMENTAL:NO /OPT:REF /OPT:ICF /LTCG:incremental


set CPPDefines=%DefinesDebug%
set LinkOpts=%LinkDebug%
if "%__BuildType%" == "Release" (
	set CPPDefines=%DefinesRelease%
	set LinkOpts=%LinkRelease%
)

REM Now compile the CPP file to platform specific executable.

echo Compiling application source files
"CL.exe" /c /I %__AppDepSdk%\CPPSdk\Windows_NT /I %__AppDepSdk%\CPPSdk\ %CPPDefines% /Fo"%ObjFileName%" /Gd /TP /wd4477 /errorReport:prompt %CPPFileName% > %__LogFilePath%\ILCompiler.App.log
if ERRORLEVEL 1 (
	echo Unable to compile app source file.
	goto :FailedExit
)

:LinkObj
echo Generating native executable
"link.exe" /ERRORREPORT:PROMPT /OUT:"%__Outfile%" /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib %libRuntime% %libBootstrapper% %__LinkLibs% /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /Debug /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT %LinkOpts% /MACHINE:%__BuildArch% "%ObjFileName%" > %__LogFilePath%\ILCompiler.Link.log
if ERRORLEVEL 1 (
	echo Unable to link native executable.
	goto :FailedExit
)

:BuildComplete
echo Build successfully completed.
exit /B 0

:DeleteFile
if exist %1 del %1
goto :eof

:InvalidArgs
echo Invalid command line
echo.
echo Usage: dotnet-compile-native arch buildType /in path-to-MSIL-assembly /out path-to-native executable /appdepsdk path to contents of Microsoft.DotNet.AppDep nuget package [/mode cpp|ryujit /codegenpath path to contents of Microsoft.DotNet.RyuJit package /objgenpath path to contents of Microsoft.DotNet.ObjWriter package] [/logpath path to drop logfiles in]

:FailedExit
exit /B 1