zig icon indicating copy to clipboard operation
zig copied to clipboard

Add CompileStep APIs to Build.Module.

Open AdamGoertz opened this issue 2 years ago • 3 comments

Closes #14719. Adding these APIs to Build.Module allows for needed include paths and libraries to be declared at the module's creation site (in the dependency) rather than in the dependee's code.

var mod = b.addModule(.{
    .name = "mymodule",
    .source_file = "...",
});
mod.addIncludePath(include_dir);

I'm not sure of the full set of CompileStep functions that need to be ported to Build.Module, but I made a start on the most obvious ones.

Functions added to Build.Module so far:

  • addIncludePath
  • addConfigHeader
  • addLibraryPath
  • linkLibC
  • linkLibCpp
  • linkLibrary
  • linkSystemLibrary
  • linkSystemLibraryNeeded
  • linkSystemLibraryWeak
  • linkSystemLibraryName
  • linkSystemLibraryNeededName
  • linkSystemLibraryWeakName
  • installHeader
  • installConfigHeader
  • installHeadersDirectory
  • installHeadersDirectoryOptions
  • installLibraryHeaders
  • linkFramework
  • linkFrameworkNeeded
  • linkFrameworkWeak
  • addSystemIncludePath
  • addRPath
  • addFrameworkPath
  • linkSystemLibraryPkgConfigOnly
  • linkSystemLibraryNeededPkgConfigOnly

AdamGoertz avatar Feb 26 '23 00:02 AdamGoertz

Great, looking forward to having this! Thanks for having addModule() return the module as well.

From the compiler meeting this week, it sounds like Module should have installHeader() and friends too.

hryx avatar Feb 26 '23 04:02 hryx

Is this ready for review?

andrewrk avatar Mar 01 '23 20:03 andrewrk

Is this ready for review?

Yes, I think so. Soliciting some more reviews was on my to-do list for this evening. Thanks for the reminder

AdamGoertz avatar Mar 01 '23 23:03 AdamGoertz

Since the issues are so similar, I've also added an addOptions function to Module, which closes #14979.

AdamGoertz avatar Apr 01 '23 02:04 AdamGoertz

I will take this from here - thank you

andrewrk avatar Apr 20 '23 23:04 andrewrk

Sounds good. I've been on work travel for most of the past few weeks, so I haven't had a chance to resolve conflicts. I'm back now, so just let me know if there's anything else I can do on this. Otherwise I'll leave it to you.

AdamGoertz avatar Apr 20 '23 23:04 AdamGoertz

Hi! Andrew's comments here tie into some changes I was planning on doing to the CLI, where you pass a main module instead of a main file - I was actually waiting on a few changes, this PR included, just to avoid potential nasty merges.

@andrewrk, what're the chances of intern-pool-2 being looked at soon? One of the genuinely very confusing things when working on said CLI rework was the current overloading of the term "module" in the compiler source, since it turned into a semi-major rework of module lifetimes; so if it's possible to get on with renaming Module any time soon that would be fantastic. But if that'll still be a wait, I can push ahead with the CLI changes anyway and just hope I don't go insane :p

mlugg avatar Apr 21 '23 01:04 mlugg

#16172 might be fixed by this?

edyu avatar Jun 28 '23 17:06 edyu