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

Add ability to pass build arguments via command line #631

Open
dnestoro opened this issue Oct 28, 2024 · 7 comments
Open

Add ability to pass build arguments via command line #631

dnestoro opened this issue Oct 28, 2024 · 7 comments
Labels
enhancement New feature or request maven-plugin Related to Maven plugin

Comments

@dnestoro
Copy link
Collaborator

dnestoro commented Oct 28, 2024

Is your feature request related to a problem? Please describe.
As @alina-yur suggested: Right now there is no way to pass build args to builds that are invoked via Maven, such as for Spring apps. Currently this can only be done via Maven profiles, writing which is a lot of overhead for passing arguments

Describe the solution you'd like
We need to provide a way to do something like mvn -Pnative native:compile -DbuildArg=<...>, so that arguments can be passed via command line. This should also support passing several arguments, andalso the argument -o for specifying the image name.

@dnestoro dnestoro added enhancement New feature or request maven-plugin Related to Maven plugin labels Oct 28, 2024
@dnestoro dnestoro changed the title Add ability to pass build arguments via command line [Maven] Add ability to pass build arguments via command line Oct 28, 2024
@melix
Copy link
Collaborator

melix commented Oct 28, 2024

In general this isn't such a good idea. Arguments passed by command line are by nature undocumented, opaque. Imagine build reproducibility: everything should be found in the build files, or it means that only god knows what was used to produce an artifact.

@olpaw
Copy link
Member

olpaw commented Oct 29, 2024

everything should be found in the build files

I agree. That's what we have the bundle feature for (https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/Bundles.md). If you want a self-contained file that allows you to replay a NI build, this should be your first choice.

BTW, the above is already possible even without adding support for -DbuildArg=<...> by using the NATIVE_IMAGE_OPTIONS environment variable. See https://github.com/oracle/graal/blob/master/docs/reference-manual/native-image/BuildOutput.md#picked-up-native_image_options cc @fniephaus

@alina-yur
Copy link
Member

Hello. My use case is that if I want to customize the build process of the same application, such as for benchmarking, when I need an instrumented version, a plain Native Image version, and a Native Image version with all optimizations, this is what I have to do at the moment:

	<profiles>
		<profile>
			<id>instrumented</id>
			<build>
				<plugins>
					<plugin>
						<groupId>org.graalvm.buildtools</groupId>
						<artifactId>native-maven-plugin</artifactId>
						<configuration>
							<imageName>demo-instrumented</imageName>
							<buildArgs>
								<buildArg>--pgo-instrument</buildArg>
							</buildArgs>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>
		<profile>
			<id>optimized</id>
			<build>
				<plugins>
					<plugin>
						<groupId>org.graalvm.buildtools</groupId>
						<artifactId>native-maven-plugin</artifactId>
						<configuration>
							<imageName>demo-optimized</imageName>
							<buildArgs>
								<buildArg>--gc=G1</buildArg>
								<buildArg>--pgo=${project.basedir}/default.iprof</buildArg>
								<buildArg>-march=native</buildArg>
							</buildArgs>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>
		<profile>
			<id>monitored</id>
			<build>
				<plugins>
					<plugin>
						<groupId>org.graalvm.buildtools</groupId>
						<artifactId>native-maven-plugin</artifactId>
						<configuration>
							<imageName>demo-monitored</imageName>
							<buildArgs>
								<buildArg>--pgo=${project.basedir}/default.iprof</buildArg>
								<buildArg>-march=native</buildArg>
								<buildArg>--enable-monitoring=heapdump,jfr,jvmstat</buildArg>
							</buildArgs>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>

The same applies if I need to add SBOM, -Os, or any other customization while keeping a clean default version of the build for comparison.

@fniephaus
Copy link
Member

the above is already possible even without adding support for -DbuildArg=<...> by using the NATIVE_IMAGE_OPTIONS environment variable.

That's correct. Nonetheless, the discoverability of this env var is relatively poor. In the context of the NBTs, we either need to document this more, or provide the ability to inject args via an user property. I would be in favor of a dedicated user property, for example -Dnative-image.build.args="--pgo-instrument", similar to exec:exec's -Dexec.args="-X myproject:dist", because that will feel most intuitive for Maven users.

@olpaw
Copy link
Member

olpaw commented Oct 29, 2024

I would be in favor of a dedicated user property, for example -Dnative-image.build.args="--pgo-instrument", similar to exec:exec's -Dexec.args="-X myproject:dist", because that will feel most intuitive for Maven users.

Adding support for something like -Dnative-image.build.args=<extra-native-image-args> to the native-maven-plugin is fine for me. I was not suggesting it to be a bad idea. I was trying to make an argument that ways to influence the behavior of a tool for the sake on convenience/debugging are common and useful.

@fniephaus
Copy link
Member

I was not suggesting it to be a bad idea.

And I was not suggesting that. ;) I think providing users with different ways to achieve the same is not always bad, at least they can choose what they want to use.

@vjovanov vjovanov changed the title [Maven] Add ability to pass build arguments via command line Add ability to pass build arguments via command line Dec 2, 2024
@vjovanov
Copy link
Member

vjovanov commented Dec 9, 2024

From the meeting, we want to support this flag and the flag would add flags to the existing buildArgs. We should also output a note that this is not to be used in CI, but only for command line experimentation and that build tools will not track file dependencies from the command line. We also need to mention in the docs that this is only for experimentation on the command line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request maven-plugin Related to Maven plugin
Projects
None yet
Development

No branches or pull requests

6 participants