BinaryBuilder.jl is amazing ~ Automatically cross-compile with Docker and convert c and Fortran code into Julia library

Have you ever seen a package named jll, like Arpack_jll, when using Julia? Most of the time, when you install some package, you will probably have a package with jll as a dependency. In fact, this package with jll is a compilation of code written in a language other than Julia. When installing, the binary will be downloaded automatically according to the OS.

This is achieved BinaryBuilder.jl https://github.com/JuliaPackaging/BinaryBuilder.jl It is a package called.

I https://www.youtube.com/watch?v=3IyXsBwqll8 I knew the existence by seeing this.

Apparently, Docker is used to cross-compile and compile code on various platforms of Mac, Windows, and Linux. At that time, if it does not work for each OS, it seems that the compilation method is modified as appropriate.

It's a very interesting library, so I tried it.

This time I put in C-LIME. https://usqcd-software.github.io/c-lime/ A data format for lattice QCD (lattice quantum chromodynamics). I'm not familiar with it at all, but the scale was just right so I tried it.

environment

Julia 1.5.2 Mac OS 10.15

Install BinaryBuilder.jl

First, you need Docker, so put Docker in it. Please find out how to install Docker. For Mac

$ brew install docker
$ brew cask install docker

It looks like it can be done.

Then in Julia, press] to enter package mode,

add BinaryBuilder

will do. However, as of October 17, 2020, something has changed on GitHub that doesn't work with the current version, so instead of the above

add BinaryBuilder#f126fe7

You need to put in the modified version as.

How to use

After putting it in

using BinaryBuilder
BinaryBuilder.run_wizard()

And run wizard.

Make a platform selection
 > All Supported Platforms
   Select by Operating System
   Fully Custom Platform Choice

Then select All Supported Platforms and

Please enter a URL (git repository or compressed archive) containing the source code to build:

Now specify the github address or file of the software you want to compile. here,

https://github.com/usqcd-software/c-lime.git

It was made. Then follow the instructions. The first question is which of the git branches to choose, but let's leave this as master. This code does not require any additional source code or libraries. As you proceed, There are things like giving a name and giving a version, so I will put it in as appropriate.

As you proceed

sandbox:${WORKSPACE}/srcdir

Something like that will come out. Now compile the code. In this case,

cd c-lime/
./autogen.sh 
./configure --prefix=${prefix} --build=${MACHTYPE} --host=${target}
make 
make install

You can compile the code with. Then press Ctrl + D to log out. next

Your build script was:

	cd $WORKSPACE/srcdir
	cd c-lime/
	./autogen.sh 
	./configure --prefix=${prefix} --build=${MACHTYPE} --host=${target}
	make
	make install
	
Would you like to edit this script now? [y/N]: n

Since the compilation method is summarized, set it to n if there is no particular problem. Then what do you compile? Something like that will appear, so press a and then d. After that, compile on various OSs and platforms while pushing enter.

Well, after it's done,

How should we deploy this build recipe?
 > Prepare a pull request against the community buildtree, Yggdrasil
   Write to a local file
   Print to stdout

Will be asked. If you choose the first, you will make a pull request to Yggdrasil on GitHub. This means putting information here on how to compile.

Would you like to actually open the pull request or just prepare it?
 > Go ahead, open it
   No, just prepare it and let me look at it first

After that, you will make a pull request with your github account name.

If it finishes successfully, a pull request will be made automatically. And if there is no problem, it will be merged into Yggdrasil. Once merged, https://github.com/JuliaBinaryWrappers/ Will be registered in. If you register here, you're done. https://github.com/JuliaBinaryWrappers/CLIME_jll.jl Is already registered,

Linux aarch64 {libc=glibc} (aarch64-linux-gnu)
Linux aarch64 {libc=musl} (aarch64-linux-musl)
Linux armv7l {call_abi=eabihf, libc=glibc} (armv7l-linux-gnueabihf)
Linux armv7l {call_abi=eabihf, libc=musl} (armv7l-linux-musleabihf)
Linux i686 {libc=glibc} (i686-linux-gnu)
Linux i686 {libc=musl} (i686-linux-musl)
Windows i686 (i686-w64-mingw32)
Linux powerpc64le {libc=glibc} (powerpc64le-linux-gnu)
macOS x86_64 (x86_64-apple-darwin)
Linux x86_64 {libc=glibc} (x86_64-linux-gnu)
Linux x86_64 {libc=musl} (x86_64-linux-musl)
FreeBSD x86_64 (x86_64-unknown-freebsd)
Windows x86_64 (x86_64-w64-mingw32)

It is said that the platform can provide binaries.

How to use Julia as a library

After that

add CLIME_jll

Then you can install it. This CLIME is not a library but a type to execute, so https://juliapackaging.github.io/BinaryBuilder.jl/dev/jll/ With reference to

using CLIME_jll
lime_contents() do exe
    run(`$exe`)
end

By doing so, you can execute the executable file lime_contents on Julia. Note that this code actually requires arguments, so use it in the form of `run (` $ exe lime_file_test`) `.

This time I ran BinaryBuilder.jl on a Mac, but that alone created a Julia library for various platforms. I'm surprised.

Recommended Posts

BinaryBuilder.jl is amazing ~ Automatically cross-compile with Docker and convert c and Fortran code into Julia library
Hello World with Docker and C
Link Java and C ++ code with SWIG
Experience .NET 5 with Docker and Visual Studio Code