Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: Go 2: Permit running code at compile-time using "comptime" keyword #39216

Closed
donutloop opened this issue May 22, 2020 · 4 comments
Closed
Labels
Milestone

Comments

@donutloop
Copy link
Contributor

donutloop commented May 22, 2020

Problem

I want to read in the content of files while compiling time to simplify the shipping of template files with a binary.

Solution

using the comptime keyword to run arbitrary code at compilation-time.

Ref: https://ziglang.org/documentation/master/#Introducing-the-Compile-Time-Concept

Design idea

func main() {
    content := comptime os.Open("./code.json")
   ....
}
@gopherbot gopherbot added this to the Proposal milestone May 22, 2020
@ianlancetaylor ianlancetaylor added v2 A language change or incompatible library change LanguageChange labels May 22, 2020
@ianlancetaylor
Copy link
Contributor

We aren't going to permit arbitrary code to run at compile time.

The specific topic of embedding files in a compiled binary is #35950.

@beoran
Copy link

beoran commented May 23, 2020

Also there is go generate which should be used instead for code generation.

@ianlancetaylor
Copy link
Contributor

For the reasons mentioned above, this is a likely decline. Leaving open for four weeks for final comments.

@griesemer griesemer changed the title proposal: Go 2: Comptime proposal: Go 2: Permit running code at compile-time using comptime keyword May 26, 2020
@griesemer griesemer changed the title proposal: Go 2: Permit running code at compile-time using comptime keyword proposal: Go 2: Permit running code at compile-time using comptime keyword May 26, 2020
@griesemer griesemer changed the title proposal: Go 2: Permit running code at compile-time using comptime keyword proposal: Go 2: Permit running code at compile-time using "comptime" keyword May 26, 2020
@ianlancetaylor
Copy link
Contributor

No further comments.

@golang golang locked and limited conversation to collaborators Jun 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants