[debugger] Ports from dotnet/runtime to maintain compatibility (#21653)
[mono-project.git] / man / mkbundle.1
blob458c326f6b7f9474029b1f96115e2b74e27d929e
1 .\" 
2 .\" mkbundle manual page.
3 .\" (C) 2004 Ximian, Inc. 
4 .\" Author:
5 .\"   Miguel de Icaza (miguel@gnu.org)
6 .\"
7 .de Sp \" Vertical space (when we can't use .PP)
8 .if t .sp .5v
9 .if n .sp
11 .TH Mono "mkbundle"
12 .SH NAME
13 mkbundle, mkbundle2 \- Creates a bundled executable.
14 .SH SYNOPSIS
15 .PP
16 .B mkbundle [options] assembly1 [assembly2 ...]
17 .SH DESCRIPTION
18 \fImkbundle\fP generates an executable program that will contain
19 static copies of the assemblies listed on the command line.  By
20 default only the assemblies specified in the command line will be
21 included in the bundle.  To automatically include all of the
22 dependencies referenced, use the "--deps" command line option.
23 .PP
24 There are two modes of operation, one uses an existing Mono binary or
25 a server-hosted list of binaries and is enabled when you use either
26 the 
27 .B --cross,
28 .B --sdk
29 or the
30 .B --runtime
31 command line options.   
32 .PP
33 An older mechanism creates a small C stub that links against the
34 libmono library to produce a self-contained executable and requires a
35 C compiler.   It is described in the "OLD EMBEDDING" section below.
36 .PP
37 For example, to create a bundle for hello world, use the following
38 command:
39 .nf
41         $ mkbundle -o hello --simple hello.exe
43 .fi
44 .PP
45 You can configure options to be passed to the Mono runtime directly
46 into your executable, for this, use the 
47 .I --options
48 flag.  For example, the following disables inlining, by passing the
49 "-O=-inline" command line option to the embedded executable:
50 .nf
52         $ mkbundle -o hello --options -O=-inline --simple hello.exe
54 .PP
55 The simple version allows for cross-compiling, this requires a Mono
56 runtime to be installed in the ~/.mono/targets/TARGET/mono to be
57 available.   You can use the "--local-targets" to list all available
58 targets, and the "--cross" argument to specify the target, like this:
59 .nf
61         $ mkbundle --local-targets      
62         Available targets:
63                 default - Current System Mono
64                 4.4.0-macosx-x86
65                 4.4.0-debian-8-arm64
66         $ mkbundle --cross 4.4.0-debian-8-powerpc hello.exe -o hello-debian
68 .fi
69 .PP
70 The above will bundle your native library into hello-debian for
71 a Debian 8 system running on a PowerPC machine.
72 .PP
73 We provide pre-packages binaries for Mono for various architectures,
74 which allow you to cross compile, use the
75 .B --list-targets
76 to get a list of all targets supported, and use the 
77 .B --fetch-target
78 flag to retrieve a target that you do not have installed, like this:
79 .nf
80         
81         $ mkbundle --list-targets
82         Cross-compilation targets available:
83         4.4.0-linux-libc2.13-amd64
84         4.4.0-linux-libc2.13-armel
85         4.4.0-linux-libc2.13-armhf
86         4.4.0-linux-libc2.13-i386
87         4.4.0-macos-10.7-amd64
88         4.4.0-macos-10.7-i386
89         4.4.2-linux-libc2.13-amd64
90         4.4.2-linux-libc2.13-armel
91         4.4.2-linux-libc2.13-armhf
92         4.4.2-linux-libc2.13-i386
93         4.4.2-macos-10.7-amd64
94         4.4.2-macos-10.7-i386
96         $ mkbundle --fetch-target 4.4.2-macos-10.7-i386
98 .fi
99 .PP
100 And then you can produce a binary that will run on 32-bit Mono on
101 MacOS:
104         $ mkbundle --cross 4.4.2-macos-10.7-i386 hello.exe -o hello-macos
108 Downloaded targets are stored
109 .B ~/.mono/targets
110 directory.
111 .SH OPTIONS
112 .TP 
113 .I "--config FILE"
114 Specifies that a DLLMAP Mono config file must be bundled as well.   In
115 the simple and cross compiler modes, if no config file is specified
116 the one for the current target is picked (either the system one in the
117 case of the simple mode, or the one that came from the cross
118 compilation target for the cross compiling mode).
120 .I "--config-dir DIR"
121 When passed, DIR will be set for the MONO_CFG_DIR environment variable
123 .I "--cross target"
124 Use this to request mkbundle generate a cross-compiled binary.  It
125 Creates a bundle for the specified target platform.  The target must
126 be a directory in ~/.mono/targets/ that contains an SDK installation
127 as produced by the mono-package-runtime tool.  You can get a list of
128 the precompiled versions of the runtime using --list-targets and you
129 can fetch a specific target using the --fetch-target command line
130 option.
132 This flag is mutually exclusive with 
133 .I --sdk
134 which is used to specify an absolute path to resolve the Mono runtime
135 from and the --runtime option which is used to manually construct the
136 cross-platform package.
138 .I "--deps"
139 This option will bundle all of the referenced assemblies for the
140 assemblies listed on the command line option.  This is useful to
141 distribute a self-contained image.
143 .I "--env KEY=VALUE"
144 Use this to hardcode an environment variable at runtime for KEY to be
145 mapped to VALUE.   This is useful in scenarios where you want to
146 enable certain Mono runtime configuration options that are controlled
147 by environment variables.
149 .I "--fetch-target target"
150 Downloads a precompiled runtime for the specified target from the Mono
151 distribution site.
153 .I "--i18n encoding"
154 Specified which encoding tables to ship with the executable.   By
155 default, Mono ships the supporting I18N.dll assembly and the
156 I18N.West.dll assembly.   If your application will use the
157 System.Text.Encoding.GetEncoding with encodings other than the West
158 encodings, you should specify them here.
160 You can use the
161 .B none
162 parameter to request that no implicit encodings should be bundled,
163 including the supporting I18N.dll, use this option if you have ran a
164 linker on your own.
166 You can use the 
167 .B all
168 flag to bundle all available encodings.
170 Or you can use a comma delimited list of the workds CJK, MidWest,
171 Other, Rare and West to specificy which encoding assemblies to distribute.
173 .I "-L path"
174 Adds the `path' do the search list for assemblies.  The rules are the
175 same as for the compiler -lib: or -L flags.
177 .I "--library [LIB,]PATH"
178 Embeds the dynamic library file pointed to by `PATH' and optionally
179 give it the name `LIB' into the bundled executable.   This is used to
180 ship native library dependencies that are unpacked at startup and
181 loaded from the runtime. Multiple libraries should be specified in
182 dependency order, where later ones on the command line depend on
183 earlier ones.
185 .I "--lists-targets"
186 Lists all of the available local cross compilation targets available
187 as precompiled binaries on the Mono distribution server.
189 .I "--local-targets"
190 Lists all of the available local cross compilation targets.
192 .I "--cil-strip PATH"
193 Provides a CIL stripper that mkbundle will use if able to.
194 The intended use is to help reduce file size on AOT.
196 .I "--in-tree path/to/mono/source/root"
197 Provides mkbundle with a mono source repository from which to pull the necessary headers for compilation.
198 This allows mkbundle to run out of the project's source tree, useful for working with multiple runtimes and for
199 testing without installing.
201 .I "--managed-linker PATH"
202 Provides mkbundle access to a managed linker to preprocess the assemblies.
204 .I "--machine-config FILE"
205 Uses the given FILE as the machine.config file for the generated
206 application.  The machine config contains an XML file that is used by
207 System.Configuration APIs to configure the .NET stack.  Typically this
209 .I $prefix/etc/mono/4.5/machine.config.
211 If you want to disable this automatic bundling, you can use the
212 .I "--no-machine-config"
213 flag. In the simple and cross compiler modes, if no machine.config file is specified
214 the one for the current target is picked (either the system one in the
215 case of the simple mode, or the one that came from the cross
216 compilation target for the cross compiling mode).
218 .I "--no-config"
219 In simple or cross compiling mode, this prevents mkbundle from
220 automatically bundling a config file.   
222 .I  "--nodeps"
223 This is the default: \fImkbundle\fP will only include the assemblies that
224 were specified on the command line to reduce the size of the resulting
225 image created.
227 .I "--no-machine-config"
228 In simple or cross compiling mode, this prevents mkbundle from
229 automatically bundling a machine.config file.   
231 .I "-o filename"
232 Places the output on `out'.  If the flag -c is specified, this is the
233 C host program.  If not, this contains the resulting executable.
235 .I "--options OPTS"
236 Since the resulting executable will be treated as a standalone
237 program, you can use this option to pass configuration options to the
238 Mono runtime and bake those into the resulting executable.  These
239 options are specified as 
240 .I OPTS.
242 You can use the above to configure options that you would typically
243 pass on the command line to Mono, before the main program is
244 executed.   
246 Additionally, users of your binary can still configure their own
247 options by setting the 
248 .I MONO_ENV_OPTIONS
249 environment variable.
251 .I "--sdk SDK_PATH"
252 Use this flag to specify a path from which mkbundle will resolve the
253 Mono SDK from.   The SDK path should be the prefix path that you used
254 to configure a Mono installation.   And would typically contain files
256 .I SDK_PATH/bin/mono
258 .I SDK_PATH/lib/mono/4.5
259 and so on.
261 When this flag is specified,
262 .I mkbundle
263 will resolve the runtime, the framework libraries, unmanaged resources
264 and configuration files from the files located in this directory.
266 This flag is mutually exlusive with 
267 .I --cross
270 .I "--target-server SERVER"
271 By default the mkbundle tool will download from a Mono server the
272 target runtimes, you can specify a different server to provide
273 cross-compiled runtimes.
275 .I "--mono-api-struct-path FILE"
276 FILE points to a file with the definition of the \fIBundleMonoAPI\fP structure which contains the
277 required pointers to various Mono API functions used throughout the generated code. This mechanism
278 is meant to be used by third parties which embed the Mono runtime and dynamically load and initialize
279 it as part of the application startup, in which case the Mono APIs will not be available for the shared
280 library loader and the bundle will fail to work (one example of such an embedding third party is
281 Xamarin.Android).
283 After providing the definition FILE, the embedder must call the \fIvoid initialize_mono_api (const BundleMonoAPI *info)\fP
284 function found in the generated code
285 .B before
286 calling \fIvoid mono_mkbundle_init ()\fP. The structure passed to \fIinitialize_mono_api\fP doesn't need
287 to be dynamically allocated as its contents is copied to the local structure in the generated code and no
288 pointer to the passed structure is retained or used after \fIinitialize_mono_api\fP returns.
290 The list of pointers is not documented here. Instead, please look at the \fIbundle-mono-api.inc\fP file
291 found in the mkbundle source directory in your Mono source tree (\fImcs/tools/mkbundle\fP) or in the Mono's
292 GitHub repository, https://github.com/mono/mono/blob/master/mcs/tools/mkbundle/bundle-mono-api.inc
294 Please note that your structure must match the one expected by your version of the Mono runtime.
296 The file must also define the \fImkbundle_log_error\fP function with the following signature:
299         static void mkbundle_log_error (const char *format, ...) {}
302 The function should implement logging API specific to the embedder.
304 .SH OLD EMBEDDING
306 The old embedding system compiles a small C stub that embeds the
307 C code and compiles the resulting executable using the system
308 compiler.   This requires both a working C compiler installation and
309 only works to bundle binaries for the current host.
311 The feature is still available, but we recommend the simpler, faster
312 and more convenient new mode.
314 For example, to create a bundle for hello world, use the following
315 command:
318         $ mkbundle -o hello hello.exe
321 The above will pull hello.exe into a native program called "hello".  Notice
322 that the produced image still contains the CIL image and no
323 precompilation is done.
325 In addition, it is possible to control whether \fImkbundle\fP should compile
326 the resulting executable or not with the -c option.  This is useful if
327 you want to link additional libraries or control the generated output
328 in more detail. For example, this could be used to link some libraries
329 statically:
332         $ mkbundle -c -o host.c -oo bundles.o --deps hello.exe
334         $ cc host.c bundles.o /usr/lib/libmono.a -lc -lrt
337 You may also use \fImkbundle\fP to generate a bundle you can use when
338 embedding the Mono runtime in a native application.  In that case, use
339 both the -c and --nomain options.  The resulting host.c file will
340 not have a main() function.  Call mono_mkbundle_init() before
341 initializing the JIT in your code so that the bundled assemblies
342 are available to the embedded runtime.
343 .SH OLD EMBEDDING OPTIONS
344 These options can only be used instead of using the 
345 .B --cross, --runtime 
347 .B --simple 
348 options.
350 .I "-c"
351 Produce the stub file, do not compile the resulting stub.
353 .I "-oo filename"
354 Specifies the name to be used for the helper object file that contains
355 the bundle.
357 .I "--keeptemp"
358 By default \fImkbundle\fP will delete the temporary files that it uses to
359 produce the bundle.  This option keeps the file around.
361 .I "--nomain"
362 With the -c option, generate the host stub without a main() function.
364 .I "--static"
365 By default \fImkbundle\fP dynamically links to mono and glib.  This option
366 causes it to statically link instead.
368 .I "-z"
369 Compresses the assemblies before embedding. This results in smaller
370 executable files, but increases startup time and requires zlib to be
371 installed on the target system.
373 .SH AOT Options
374 These options support an mkbundle using AOT compilation with static linking. A native compiler
375 toolchain is required.
377 .I "--aot-runtime PATH"
378 Provide the path to the mono runtime to use for AOTing assemblies.
380 .I "--aot-dedup"
381 (Experimental) Deduplicate AOT'ed methods based on a unique mangling of method names.
383 .I "--aot-mode MODE"
384 MODE can be either "full", "llvmonly" or "hybrid" at this time.
385 Currently, mkbundle supports four AOT modes. The default mode (this option unset)
386 will AOT methods but will fall back on runtime codegen where it is much faster or offers
387 a more full compatibility profile. The "full" setting will generate the necessary stubs to
388 not require runtime code generation. The "llvmonly" setting does the same as the "full" mode,
389 but forces all codegen to go through the llvm backend. The "hybrid" mode allows the IL to be
390 stripped, similar to the "full" mode, but without fully disabling JIT.
392 .SH WINDOWS
393 If you are using the old embedding on Windows systems, it possible to use
394 a Unix-like toolchain like cygwin's and install gcc, gcc-mingw packages or
395 use Visual Studio 2015/2017 VC toolchain together with Clang for Visual Studio as assembler.
396 Clang can be installed as an individual component, "Clang/C2", using Visual Studio installer.
398 Using Visual Studio toolchain, mkbundle will, by default, use latest installed Visual Studio compiler
399 and linker as well as Windows SDK. If executed from one of the Visual Studio developer command prompts,
400 mkbundle will retrieve information directly from that build environment.
401 .SH ENVIRONMENT VARIABLES
403 .I "AS"
404 Assembler command. The default is "as". For Visual Studio, default is "clang.exe".
405 If "clang.exe" for Visual Studio is not installed, mkbundle will fall back using "as".
407 .I "CC"
408 C compiler command. The default is "cc" for Linux, "gcc"
409 for cygwin and "cl.exe" for Visual Studio.
411 .I "MONO_BUNDLED_OPTIONS"
412 Options to be passed to the bundled
413 Mono runtime, separated by spaces. See the mono(1) manual page or run mono --help.
414 .SH WINDOWS VISUAL STUDIO ENVIRONMENT VARIABLES
416 .I "VisualStudioVersion"
417 Visual Studio version used in mkbundle build.
418 Default, latest installed Visual Studio version.
419 Values, "14.0" for Visual Studio 2015 or "15.0" for Visual Studio 2017.
421 .I "WindowsSdkVersion"
422 Windows SDK version used in mkbundle build.
423 Default/unknown, latest installed Windows SDK.
424 Values, "8.1", "10.0.10240.0", "10.0.15063.0" etc.
426 .I "VSCMD_ARG_TGT_ARCH"
427 Output target architecture used in mkbundle build.
428 Default/unknown, use architecture of .NET runtime executing mkbundle.
429 Values, "x86" or "x64".
430 NOTE, when running from a Visual Studio command prompt, this variable should already be set
431 by the command prompt and match the rest of that build environment.
433 .I "INCLUDE"
434 Override all custom include paths passed to "cl.exe".
435 Predefined by Visual Studio developer command prompt or auto detected by mkbundle when undefined.
437 .I "LIB"
438 Override all custom library paths passed to "link.exe".
439 Predefined by Visual Studio developer command prompt or auto detected by mkbundle when undefined.
441 .I "MONOPREFIX"
442 Use a custom Mono SDK install root matching the output target architecture (x86/x64).
443 Default, mkbundle will look for installed Mono SDK’s matching targeted architecture.
445 .I "MONOLIB"
446 Use a different mono library name or an absolute path to the mono library passed to linker.
447 Default, mkbundle will use default mono library name depending on mkbundle dynamic/static use case.
448 NOTE, supplied mono library needs to match mkbundle dynamic/static use case and target architecture.
450 .I "VCCRT"
451 Override C-runtime library linker settings.
452 Default "MD", mkbundle will use dynamic C-runtime linking on Windows compatible with Mono SDK distribution.
453 If a custom built Mono runtime using static C-Runtime linkage is used, setting this variable to "MT"
454 will link using static C-runtime libraries.
456 .I "VCSUBSYSTEM"
457 Override Windows subsystem.
458 Default, "windows". If console subsystem is preferred, use "console".
459 NOTE, if console output is expected from output target process then
460 set this variable to "console".
461 .SH FILES
462 This program will load referenced assemblies from the Mono assembly
463 cache. 
465 Targets are loaded from ~/.mono/targets/TARGETNAME/mono
466 .SH BUGS
467 .SH MAILING LISTS
468 Visit http://lists.ximian.com/mailman/listinfo/mono-devel-list for details.
469 .SH WEB SITE
470 Visit: http://www.mono-project.com for details
471 .SH SEE ALSO
472 .BR mcs (1),
473 .BR mono (1),
474 .BR mono-config (5)