containers / ocicrypt

Encryption libraries for Encrypted OCI Container images
Apache License 2.0
133 stars 31 forks source link

Add build constraints for other unsupported OS #34

Closed lumjjb closed 3 years ago

lumjjb commented 3 years ago

Signed-off-by: Brandon Lum lumjjb@gmail.com

lumjjb commented 3 years ago

We probably need a better way to do this, to provide better semantics for non-supported OSes. There is a dependency of pkcs11config on pkcs11helpers. I don't think this PR does it justice... since i'm not 100% certain what the semantics for the functions are relative to each other.

stefanberger commented 3 years ago

Which parts are not working/compiling where and what are the error message? At least miekg's pkcs11 project does seem to be supported on quite a few platforms:

https://github.com/miekg/pkcs11/blob/master/pkcs11.go#L13-L28

/*
#cgo windows CFLAGS: -DPACKED_STRUCTURES
#cgo linux LDFLAGS: -ldl
#cgo darwin LDFLAGS: -ldl
#cgo openbsd LDFLAGS: -ldl
#cgo freebsd LDFLAGS: -ldl
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "pkcs11go.h"
#ifdef _WIN32
#include <windows.h>
[...]
lumjjb commented 3 years ago

Darwin build is failing on scoped, buildah

On Sat, Oct 17, 2020, 5:15 PM Stefan Berger notifications@github.com wrote:

Which parts are not working/compiling where and what are the error message? At least miekg's pkcs11 project does seem to be supported on quite a few platforms:

https://github.com/miekg/pkcs11/blob/master/pkcs11.go#L13-L28

/*

cgo windows CFLAGS: -DPACKED_STRUCTURES

cgo linux LDFLAGS: -ldl

cgo darwin LDFLAGS: -ldl

cgo openbsd LDFLAGS: -ldl

cgo freebsd LDFLAGS: -ldl

include

include

include

include

include "pkcs11go.h"

ifdef _WIN32

include

[...]

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/containers/ocicrypt/pull/34#issuecomment-711081391, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAXLDBQI33GR4VJM7NHB22LSLICQRANCNFSM4SUTFCGQ .

stefanberger commented 3 years ago

That may be a matter of adding dependencies to the build. I haven't seen the build output. Do you have a link?

lumjjb commented 3 years ago

https://github.com/containers/skopeo/pull/1080

lumjjb commented 3 years ago

@Gsealy if you have any insight on ways we can handle this, please join the discussion :)

Gsealy commented 3 years ago

containers/skopeo#1080 try with MINGW64 , github.com/containers/image/v5/signature also build failed

Gsealy@DESKTOP-GRLMLGJ MINGW64 /d/GoWorkSpaces/src/github.com/containers/skopeo (pr/1080)
$ GOOS=linux GOARCH=amd64 GO111MODULE=off go build ./...
# github.com/containers/skopeo/vendor/github.com/containers/ocicrypt/crypto/pkcs11
vendor\github.com\containers\ocicrypt\crypto\pkcs11\pkcs11helpers.go:45:20: undefined: pkcs11.OAEPParams
vendor\github.com\containers\ocicrypt\crypto\pkcs11\pkcs11helpers.go:253:32: undefined: pkcs11.Ctx
vendor\github.com\containers\ocicrypt\crypto\pkcs11\pkcs11helpers.go:253:78: undefined: pkcs11.SessionHandle
vendor\github.com\containers\ocicrypt\crypto\pkcs11\pkcs11helpers.go:271:82: undefined: pkcs11.Ctx
vendor\github.com\containers\ocicrypt\crypto\pkcs11\pkcs11helpers.go:271:102: undefined: pkcs11.SessionHandle
vendor\github.com\containers\ocicrypt\crypto\pkcs11\pkcs11helpers.go:322:24: undefined: pkcs11.Ctx
vendor\github.com\containers\ocicrypt\crypto\pkcs11\pkcs11helpers.go:322:44: undefined: pkcs11.SessionHandle
vendor\github.com\containers\ocicrypt\crypto\pkcs11\pkcs11helpers.go:330:25: undefined: pkcs11.Ctx
vendor\github.com\containers\ocicrypt\crypto\pkcs11\pkcs11helpers.go:330:45: undefined: pkcs11.SessionHandle
vendor\github.com\containers\ocicrypt\crypto\pkcs11\pkcs11helpers.go:330:101: undefined: pkcs11.ObjectHandle
vendor\github.com\containers\ocicrypt\crypto\pkcs11\pkcs11helpers.go:45:20: too many errors
# github.com/containers/skopeo/vendor/github.com/containers/image/v5/signature
vendor\github.com\containers\image\v5\signature\mechanism_gpgme.go:16:16: undefined: gpgme.Context
vendor\github.com\containers\image\v5\signature\mechanism_gpgme.go:66:44: undefined: gpgme.Context
vendor\github.com\containers\image\v5\signature\mechanism_gpgme.go:67:14: undefined: gpgme.New
vendor\github.com\containers\image\v5\signature\mechanism_gpgme.go:71:27: undefined: gpgme.ProtocolOpenPGP
vendor\github.com\containers\image\v5\signature\mechanism_gpgme.go:75:28: undefined: gpgme.ProtocolOpenPGP
vendor\github.com\containers\image\v5\signature\mechanism_gpgme.go:97:20: undefined: gpgme.NewDataBytes
vendor\github.com\containers\image\v5\signature\mechanism_gpgme.go:126:20: undefined: gpgme.NewDataBytes
vendor\github.com\containers\image\v5\signature\mechanism_gpgme.go:131:18: undefined: gpgme.NewDataWriter
vendor\github.com\containers\image\v5\signature\mechanism_gpgme.go:135:25: undefined: gpgme.Key
vendor\github.com\containers\image\v5\signature\mechanism_gpgme.go:135:61: undefined: gpgme.SigModeNormal
vendor\github.com\containers\image\v5\signature\mechanism_gpgme.go:135:61: too many errors
Gsealy commented 3 years ago

I don‘t know why...

stefanberger commented 3 years ago

The troubles are related to the C code. You may need to add CGO_ENABLED=1 to your command line but that may cause other issues. We tried this as well but cross building C code seems not work as expected.

stefanberger commented 3 years ago

Example of a cross build for arm64 on a Linux machine with CC set to an arm compiler on Fedora:

$ go version
go version go1.14.4 linux/amd64
$ CC=arm-none-eabi-gcc  CGO_ENABLED=1 make bin/skopeo.linux.arm64
arm-none-eabi-gcc: error: unrecognized command line option '-pthread'
make: *** [Makefile:130: bin/skopeo.linux.arm64] Error 2
stefanberger commented 3 years ago

Ah, that was a bad cross compiler. Here's with a 'better' one:

 CC=arm-linux-gnu-gcc CGO_ENABLED=1 make bin/skopeo.linux.arm64
GOOS=linux GOARCH=arm64 GO111MODULE=on go build -mod=vendor -ldflags '-X main.gitCommit=344bb3513aebc7dbae00a4b32800f8bd88e4a4e4 ' -tags "containers_image_openpgp    " -o bin/skopeo.linux.arm64 ./cmd/skopeo
# runtime/cgo
_cgo_export.c:3:10: fatal error: stdlib.h: No such file or directory
    3 | #include <stdlib.h>
      |          ^~~~~~~~~~
compilation terminated.
make: *** [Makefile:130: bin/skopeo.linux.arm64] Error 2
stefanberger commented 3 years ago

LGTM

stefanberger commented 3 years ago

You can merge I think.

lumjjb commented 3 years ago

Testing with other stuff first, in case there's some edge cases, then will merge.

lumjjb commented 3 years ago

Tests passed for skopeo and buildah, crio CI has some problems unrelated to PR.

Gsealy commented 3 years ago

learned a lot. Thanks !