An introduction to Mono.Merge 12

Posted by Jb Evain Mon, 06 Nov 2006 08:57:00 GMT

There’s something I’ve been willing to do since I started Cecil. Imagine a tool that takes a set of assemblies, and merge them in a single one. That’s not too hard to do using Cecil, but I’ve never took the time to do it. Well, thanks to Alex Prudkiy, who also contributed a few patches to the linker, we now have a brand new monomerge tool.

Let’s take an easy example. This new monomerge tool have only one dependency beside of the core, Mono.Cecil. That means that if you want to send your tool to someone, you’ll have to ship a copy of Mono.Cecil.dll also. But why not shipping only one assembly?

Let’s merge the merger! As usual, I’m pretty disappointed I can’t show you some meaningful and colorful screen shots, but heh, that’s a command tool, let’s have a look at my console snapshot.

jbevain@avalon:/tmp/merge$ ls -l
total 364
-rwxr-xr-x 1 jbevain jbevain 337920 2006-10-31 14:02 Mono.Cecil.dll
-rwxr-xr-x 1 jbevain jbevain 24064 2006-10-31 14:06 monomerge.exe
drwxr-xr-x 2 jbevain jbevain 4096 2006-10-31 14:15 output
jbevain@avalon:/tmp/merge$ ~/devel/bin/mono monomerge.exe -out output/monomerge.exe monomerge.exe Mono.Cecil.dll
jbevain@avalon:/tmp/merge$ cd output && ls -l
total 348
-rw-r--r-- 1 jbevain jbevain 351744 2006-10-31 14:16 monomerge.exe
jbevain@avalon:/tmp/merge/output$ ~/devel/bin/mono monomerge.exe
Mono CIL Merge
monomerge [options] -out result_file primary assemly [files...]
 --about About the Mono CIL Merge
 --version Print the version number of the Mono CIL Merge
 -out Specify the output file

 Sample: monomerge -out output.exe input.exe input_lib.dll
jbevain@avalon:/tmp/merge/output$
 Here we are, we have now a single monomerge.exe assembly, which contains both the merger and Mono.Cecil. Pretty neat isnt’it? Hmm, I’m sure you already seen where I want to go with this. Imagine a tool chain like:

  1. use the Linker to reduce the size of a set of assemblies
  2. use the Merger to ship them in a single assembly
  3. use mkbundle to ship this single assembly plus the linker core in a single binary

That’s the less space wasting solution I know for Mono and embedded users. Pretty cool huh? Anyway, if you want to give it a try, the code now lives in the /cecil/merge module of the SVN

Thanks Алексей for this tool!

Mono Meeting

Posted by Jb Evain Wed, 13 Sep 2006 17:31:00 GMT

Thanks to db4o who is sponsoring my trip, I’ll be attending the Mono Meeting at the end of October. I’ll have two talks here:

  • One about db4o, the leading object database,
  • The other about Cecil, our assembly manipulation library.

See you there!

Mono.Cecil 0.4.3 released

Posted by Jb Evain Wed, 23 Aug 2006 22:58:00 GMT

Here is a new version of Cecil.

This is mainly a bug fix release, in the 0.4 serie, but if you look carefuly, you may find find one new feature or two. The bigger one is maybe an AssemblyResolver, which helps you find an assembly depending on its name. It’s quite simple, but so far, it worked great for the new linker.

It will be used in the next releases to read some parts of an assembly that depends upon informations in a referenced assembly.

Whatever, here are the interesting bits

Dear users, please upgrade.

Linking all the way down 10

Posted by Jb Evain Tue, 22 Aug 2006 20:44:00 GMT

Do you remember this post?

If you do so, I’m sure you know, what I’m going to show you. A formidable use of the new linker.

What do you need? First you need an application. I’ve reused a very small program I wrote a bunch of month with db4o. It simply allows you to persist a few objects Person in a db4o database, and to retrieve them. But it’s sooo cool that I’d like to make it a standalone application.

It has a very friendly command line interface:

Very nice isn’t it? So now, let’s link it so that I have the minimum set of the assemblies my program use.

jbevain@avalon:/tmp/linker$ mono linker.exe -o persons -a persons.exe -p false
jbevain@avalon:/tmp/linker$ cp persons.yap persons/
jbevain@avalon:/tmp/linker$ cd persons/

The yap file is db4o’s database.

Please note that in SVN, I’ve disabled the ability to link the assembly mscorlib.dll. It’s a very special assembly which is of course very close to the runtime. So if ever you want to remove stuff from it, you have to be very frugal, so you don’t remove stuff used within the runtime. And it seems that I’ve not identified everything used. So it tend to be pretty unstable :)

But for the time being, it’s fine. Now, let’s create a standalone application from this great piece of code.

jbevain@avalon:/tmp/linker/persons$ mkbundle
OS is: Linux
Sources: 0 Auto-dependencies: False
Usage is: mkbundle [options] assembly1 [assembly2...]

Options:
    -c              Produce stub only, do not compile
    -o out          Specifies output filename
    -oo obj         Specifies output filename for helper object file
    -L path         Adds `path' to the search path for assemblies
    --nodeps        Turns off automatic dependency embedding (default)
    --deps          Turns on automatic dependency embedding
    --keeptemp      Keeps the temporary files
    --config F      Bundle system config file `F'
    --config-dir D  Set MONO_CFG_DIR to `D'
    --static        Statically link to mono libs
    -z          Compress the assemblies before embedding.

jbevain@avalon:/tmp/linker/persons$ mkbundle -o persons --nodeps ./persons.exe ./db4o.dll ./mscorlib.dll
OS is: Linux
Sources: 3 Auto-dependencies: False
   embedding: /tmp/linker/persons/persons.exe
   embedding: /tmp/linker/persons/db4o.dll
   embedding: /tmp/linker/persons/mscorlib.dll
Compiling:
as -o /tmp/tmp47dda943.tmp.o temp.s
cc -ggdb -o persons -Wall temp.c `pkg-config --cflags --libs mono`  /tmp/tmp47dda943.tmp.o
Done
jbevain@avalon:/tmp/linker/persons$ mkdir standalone
jbevain@avalon:/tmp/linker/persons$ mv persons standalone/
jbevain@avalon:/tmp/linker/persons$ mv persons.yap standalone/
jbevain@avalon:/tmp/linker/persons$ cd standalone/
jbevain@avalon:/tmp/linker/persons/standalone$ ./persons
Persons manager
l
All persons:
Person, name: Anaelle, age: 19
Person, name: Jb Evain, age: 23
Person, name: Reg, age: 24
q
jbevain@avalon:/tmp/linker/persons/standalone$

Et voil , we now have a standalone application that works like a charm, and which contains, well almost, only what’s needed to use it. That’s so great!

Ok, let’s go back to the code, I need to make the linking against corlib working.

Older posts: 1 ... 7 8 9 10 11