How can I snapshot all Cargo compiler inputs for auditing on Mac OS? - macos

I am using Rust to cross compile a CLI.
An issue I am having is that typically the Rust compiler only works flawlessly when it compiles for the same OS/arch as the host it is running on (otherwise there are missing components, e.g. dynamic libs or compiler toolchains).
I want to release a binary that I have compiled on my Mac, but I want to be able to archive all inputs so that I can recreate the build for any future security audits.
For Linux I am using Docker containers which snapshot all files used as input to the cargo build process.
But for my Mac I have no idea how to isolate the cargo install, or what other toolchains or dynamic libs it may be calling out to.
Thanks

Related

how to bazel build a C++ windows executable w/o it needing vcruntime DLLs?

I want to know how to write a cc_binary() BUILD rule that produces a standalone executable. It's a console application. My current BUILD rule is making that exe to depend on both vcruntime140.dll and vcruntime140_1.dll
My current dev env is Bazel and Windows 8 with the latest MSVC community version, but I also wanted to write this BUILD rule in a way that I could run it in Linux too. (so I guess I can't just stuff non-portable flags like /MT there)

unable to cross compile from OSX to Linux

When I try to cross compile my golang project from OSX to Linux, then I get following error message:
# runtime/cgo
ld: unknown option: --build-id=none
clang: error: linker command failed
and the compilation aborts.
This is how I try to build my application:
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build
I also tried using gox:
gox -os="linux"
but it still did not work.
Everything works as expected if I do not use the GOOS=linux tag and I am able to build/run my project for/on my OSX machine successfully.
I can confirm that the command
$env CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -v main.go
works perfectly fine with a "Hello World" main.go file on MacOS X High Sierra without installing anything else than just go (see also here).
As already pointed out in the comments, you are probably trying to compile with cgo and obviously lack parts of the tool chain and/or headers and that is why your linker throws an error. Please provide an acceptable example, otherwise we won't be able to help you.
You need to install a proper toolchain to do that.
In order to build binaries for architectures different that your build
host, you need far more than just a cross-compiler - you need a
full-blown toolchain, which can be a real pain to create, as you
probably discovered.
A couple of approaches:
Use a proper Linux distribution in a virtual machine, such as
VirtualBox. If you only want to build binaries for Linux/i386 on an
MacOSX/x86_64 host, this is - in my opinion - the easiest, safest and
most clean solution. It is not a cross-compiler, of course, but it
works and it has the added advantage that you can actually test your
executables.
Use a script such crosstool-NG (a descendant of the original
crosstool) to automatically build the toolchain - definitely easier
than building it on your own, although you may have to compromise for
slightly older compiler versions.
Cross compiler for linux on mac os x

How to cross compile from Mac to Linux?

I wrote a little game using Rust, and I used cargo build --release to compile a release version on Mac.
I tried to share this with my friend who is using Ubuntu, but when he tried to run the binary, he got the following error:
cannot execute binary file: Exec format error
I searched for this but found no answers. Doesn't Rust claim to have "no runtime"? Shouldn't it be able to run anywhere in binary form?
Rust not having a runtime means that it doesn't have a lot of code running as part of the language (for example a garbage collector or bytecode interpreter). It does still need to use operating system primitives (i.e. syscalls), and these are different on MacOS and Linux.
What you want is a cross compiler. If you're using rustup, then installing a cross compiler should be simple:
# Install the toolchain to build Linux x86_64 binaries
rustup target add x86_64-unknown-linux-gnu
Then building is:
cargo build --release --target=x86_64-unknown-linux-gnu
Caveat: I don't have an OS X machine to test this on; please comment or edit to fix this if it works!
Well, it is because Rust has no runtime (unlike e.g. Java's JVM) that you can't just compile code on one OS and expect it to run on a different one; what you are looking for is cross-compilation. I haven't done it in Rust, but from what I can gather you can find relevant information on different cross-compilation Rust strategies on this GitHub repo.

Building a Linux kernel using Travis CI

How can I build a Linux kernel in Travis CI. I have added script: make menuconfig to my Travis config and it doesn't work and says
No output has been received in the last 10 minutes
How can I fix this?
Link to GitHub repo : https://github.com/ProjectPolyester/tegra_kernel and submit fixes in PRs if possible
Travis monitors your build process and if there is no output for about 10 minutes, it assumes that your process is stuck somewhere for unknown reasons, and then kills it.
Solution in your case :
You need to provide with the actual build command.
make menuconfig
actually just allows you to configure the kernel. It doesn't really starts the kernel build process. So there is no output of this command.
Also, the kernel should already be configured or you can download the appropriate .config file if its available some where online. And then there will be no need to execute:
make menuconfig
The build command
It can be simply
make
or something like
make -j3 modules ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LOCALVERSION=-$SOURCE_VERSION
The second one is actually to perform cross compilation.
You also need to set all the prerequisites like downloading the header file etc
You may want to take a look at this script , it crosscompiles the modules only, not the entire kernel.
If you want to use the old config for a new kernel, you can use make olddefconfig. Here is my example how to compile and boot a new kernel in travis: https://github.com/avagin/criu/blob/linux-next/scripts/travis/kexec.sh#L54
I know that this is an old thread but I was recently able to get Travis CI working on building a Linux kernel
https://github.com/GlassROM-devices/android_kernel_oneplus_msm8994/commit/6ed484812bbd4a25c3b22e730b7489eaaf668da1
GCC fix is for toolchains compiled on Debian unstable, arch, gentoo, etc. These toolchains will fail to compile on Ubuntu so you'll have to use the GCC fix for these toolchains
And you really want to upgrade GCC before you even try building a kernel. Travis CI has a very old GCC that will fail if you try to compile the kernel
In my commit I'm building it with GCC 8 linaro built by myself

Does server needs packages needed to compile executables for the server?

Do I need to install packages needed to compile executable for the server on the server itself?
For example, I localy compile php with zlib & then install on the server. Does php can use zlib functions because I included it when I compiled or do I still need that package present on the server?
OS: Slackware 13.37
In principle you should be able to compile software on another machine, but you need to make sure your architectures, dependencies (e.g. libraries like glibc and others) and compiler are compatible. If architectures don't match have a look into cross-compiling.
If this is just for you and your compile machine and server match in architecture make sure the have the same versions of dependencies installed.

Resources