premake / premake/premake-core

Build Command with Multiple Inputs and Multiple Outputs

Open
#2,160 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

support-request
Dominant language
C
Stars
3.6k
Forks
654
Avg merge
1d 1h
Merged PRs (30d)
13

Description

What are you trying to do?

I am trying to use a Premake custom build command for a program which generates code that takes multiple inputs and creates multiple outputs. However, I can't figure out the Premake to take multiple inputs and generate multiple outputs.

What have you tried so far?

The Protocol Buffer compiler protoc is one such program that operates in this way that I will use for demonstration. This script works for taking all of the .proto files and compiling them individually:

workspace "CustomBuildCommandTesting"
    configurations { "Debug", "Release" }
    location "build"

project "custom-buildcommand-test"
    kind "ConsoleApp"
    language "C++"
    targetdir "build/%{cfg.buildcfg}/bin"

    files { "src/**.cpp", "src/**.proto" }
    includedirs { "%{cfg.objdir}/generated" }

    -- Using protoc for demo, but the question applies to anything with multiple inputs
    filter 'files:**.proto'
        buildcommands {
            'mkdir -p "%{cfg.objdir}/generated"',
            'protoc --proto_path=../src --cpp_out="%{cfg.objdir}/generated" "%{file.relpath}"',
        }

        buildoutputs {
            '%{cfg.objdir}/generated/%{file.basename}.pb.h',
            '%{cfg.objdir}/generated/%{file.basename}.pb.cc',
        }

This creates rules in Make that look like this (cleaned a bit for clarity):

obj/Debug/generated/foo.pb.h: ../src/foo.proto
    mkdir -p "obj/Release/generated"
	protoc --proto_path=../src --cpp_out="obj/Release/generated" "../src/foo.proto"

obj/Debug/generated/bar.pb.h: ../src/bar.proto
	mkdir -p "obj/Debug/generated"
	protoc --proto_path=../src --cpp_out="obj/Debug/generated" "../src/bar.proto"

As an aside, there is no mention of the .pb.cc files that get generated anywhere, which is not ideal. It seems like that should get picked up from buildoutputs, but I must be missing how to make that happen.

What problem are you having?

The real problem here is this isn't the way you're supposed to use protoc. For protoc, you want to use all of the inputs to generate all of the outputs in one pass. A more-correct rule in Make would look like this:

obj/Debug/generated/bar.pb.h  \
obj/Debug/generated/bar.pb.cc \
obj/Debug/generated/foo.pb.h  \
obj/Debug/generated/foo.pb.cc \
        &:                    \
        ../src/bar.proto      \
        ../src/foo.proto
	mkdir -p "obj/Debug/generated"
	protoc --proto_path=../src --cpp_out="obj/Debug/generated" $^

How do you write a Premake command that can take multiple inputs and generate multiple outputs? If that isn't possible with custom commands, then what mechanism is available in Premake?

What version of Premake are you using?

premake5 (Premake Build Script Generator) 5.0.0-dev (it's from the beta 2 binary)

Anything else we should know?

For completeness, here's the full demo source tree.

.
├── premake5.lua
└── src
    ├── bar.proto
    ├── foo.proto
    └── main.cpp

src/foo.proto:

syntax = "proto3";

message Foo {
    uint64 value = 1;
}

src/bar.proto:

syntax = "proto3";

import "foo.proto";

message Bar {
    Foo foo = 1;
}

src/main.cpp:

#include "bar.pb.h"

int main()
{
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the minimal premake5.lua example from the issue with foo.proto and bar.proto, then inspect the generated Make rules. Trace Premake’s custom build-command and build-output handling to determine how grouped inputs and outputs could be represented; done means one rule includes all .proto inputs and generated .pb.h/.pb.cc outputs and invokes protoc once.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, lua
Domain
build-system, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.