mit-plv/fiat-crypto

Support Go build tags

Closed this issue · 3 comments

In Go, we generally don't have separate packages for different architectures, but separate files with build tags, comments that look like this and tell the compiler to only build on certain architectures. (There are two syntaxes because we are in the process of switching from the second to the first. It would probably be ok to only generate the first, since it will be the main one by Go 1.18.)

//go:build amd64 || s390x || arm64 || ppc64le
// +build amd64 s390x arm64 ppc64le

It would be nice if there was a way to get these comments in the generated file, either by configuring a custom header, or by passing a list of build tags, or automatically based on 32 vs 64 bits.

How about I give you a --prepend-header command line flag that accepts a string and sticks it at the beginning of the header in a comment? (Is it important that there's no space between // and go?). You could repeat the flag for multiple lines, or else include newlines in the string itself.

Awesome, thank you. My build is still running, but if it lets me make the file start with

// Code generated by Fiat Cryptography. DO NOT EDIT.
//
//go:build amd64 || s390x || arm64 || ppc64le
// +build amd64 s390x arm64 ppc64le
//

it's going to work.

The //go:build comment does need not to have a space, // +build is a legacy syntax, while now all comments understood by the toolchain start with //go:.

Since you need it without the space, you'll need --doc-prepend-header-raw. Invoking with the arguments --doc-prepend-header-raw '// Code generated by Fiat Cryptography. DO NOT EDIT.' --doc-prepend-header-raw '//' --doc-prepend-header-raw '//go:build amd64 || s390x || arm64 || ppc64le' --doc-prepend-header-raw '// +build amd64 s390x arm64 ppc64le' --doc-prepend-header-raw '//'
should do the trick.