From 6cf8a880d0a649429255932b1bc50a4a83c1ef0d Mon Sep 17 00:00:00 2001 From: Greg Domjan Date: Wed, 6 Mar 2019 15:41:54 +1100 Subject: [PATCH 1/6] Apply precedence for binding type shared/static/other Automatic linking precedence is intended to be shared > static > plugin | jni | executable | none Last change caused change when multiple binding types are present, the order in handling libraries can lead to static overwriting shared. Update to static from lower types only if not already shared #368 --- src/main/java/com/github/maven_nar/NarLayout21.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/github/maven_nar/NarLayout21.java b/src/main/java/com/github/maven_nar/NarLayout21.java index 65a324f0..e858c35c 100644 --- a/src/main/java/com/github/maven_nar/NarLayout21.java +++ b/src/main/java/com/github/maven_nar/NarLayout21.java @@ -233,12 +233,13 @@ public final void prepareNarInfo(final File baseDir, final MavenProject project, } else { // if the binding is already set, then don't write it for // jni/executable/none. - if (narInfo.getBinding(aol, null) == null) { + String current = narInfo.getBinding(aol, null); + if ( current == null) { narInfo.setBinding(aol, type); - } else if (type.equals(Library.STATIC)) { + } else if (!Library.SHARED.equals(current) + && type.equals(Library.STATIC)) { //static lib is preferred over other remaining types; see #231 narInfo.setBinding(aol, type); - narInfo.setBinding(null, type); } if (narInfo.getBinding(null, null) == null) { From 6e556e8b407f8b1f573a8f2b948725232069a2ec Mon Sep 17 00:00:00 2001 From: Greg Domjan Date: Wed, 27 Jan 2021 17:35:30 +1100 Subject: [PATCH 2/6] Add unit test for multi lib type [shared|static] build --- .../it0040-dep-lib-default/pom.xml | 75 +++++++++++++++ .../src/main/c/HelloWorldExe.c | 28 ++++++ .../it0040-dep-lib-shared/pom.xml | 78 ++++++++++++++++ .../src/main/c/HelloWorldExe.c | 28 ++++++ .../it0040-dep-lib-static/pom.xml | 73 +++++++++++++++ .../src/main/c/HelloWorldExe.c | 28 ++++++ .../it0040-lib-sharedstatic/pom.xml | 93 +++++++++++++++++++ .../src/main/c/HelloWorldLib.c | 26 ++++++ .../src/main/include/HelloWorldLib.h | 43 +++++++++ .../src/test/c/HelloWorldTest.c | 28 ++++++ src/it/it0040-multi-libtype/pom.xml | 55 +++++++++++ 11 files changed, 555 insertions(+) create mode 100644 src/it/it0040-multi-libtype/it0040-dep-lib-default/pom.xml create mode 100644 src/it/it0040-multi-libtype/it0040-dep-lib-default/src/main/c/HelloWorldExe.c create mode 100644 src/it/it0040-multi-libtype/it0040-dep-lib-shared/pom.xml create mode 100644 src/it/it0040-multi-libtype/it0040-dep-lib-shared/src/main/c/HelloWorldExe.c create mode 100644 src/it/it0040-multi-libtype/it0040-dep-lib-static/pom.xml create mode 100644 src/it/it0040-multi-libtype/it0040-dep-lib-static/src/main/c/HelloWorldExe.c create mode 100644 src/it/it0040-multi-libtype/it0040-lib-sharedstatic/pom.xml create mode 100644 src/it/it0040-multi-libtype/it0040-lib-sharedstatic/src/main/c/HelloWorldLib.c create mode 100644 src/it/it0040-multi-libtype/it0040-lib-sharedstatic/src/main/include/HelloWorldLib.h create mode 100644 src/it/it0040-multi-libtype/it0040-lib-sharedstatic/src/test/c/HelloWorldTest.c create mode 100644 src/it/it0040-multi-libtype/pom.xml diff --git a/src/it/it0040-multi-libtype/it0040-dep-lib-default/pom.xml b/src/it/it0040-multi-libtype/it0040-dep-lib-default/pom.xml new file mode 100644 index 00000000..e6b0bc97 --- /dev/null +++ b/src/it/it0040-multi-libtype/it0040-dep-lib-default/pom.xml @@ -0,0 +1,75 @@ + + + + + 4.0.0 + + + com.github.maven-nar.its.nar + it0040-pom + 1.0-SNAPSHOT + + + it0040-dep-lib-default + nar + + NAR Executable and default Library + 1.0-SNAPSHOT + + Executable depending on a library from a mixed type with default linkage. + + + + true + + + + + + @project.groupId@ + nar-maven-plugin + true + + + + LIB_IMPORTS + + + + + executable + + + + + + + + + + + com.github.maven-nar.its.nar + it0040-lib-sharedstatic + 1.0-SNAPSHOT + nar + + + diff --git a/src/it/it0040-multi-libtype/it0040-dep-lib-default/src/main/c/HelloWorldExe.c b/src/it/it0040-multi-libtype/it0040-dep-lib-default/src/main/c/HelloWorldExe.c new file mode 100644 index 00000000..15f98cc3 --- /dev/null +++ b/src/it/it0040-multi-libtype/it0040-dep-lib-default/src/main/c/HelloWorldExe.c @@ -0,0 +1,28 @@ +/* + * #%L + * Native ARchive plugin for Maven + * %% + * Copyright (C) 2002 - 2014 NAR Maven Plugin developers. + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +#include +#include "HelloWorldLib.h" + +int main(int argc, char *argv[]) { + printf("%s\n", HelloWorldLib_sayHello()); + return 0; +} + + diff --git a/src/it/it0040-multi-libtype/it0040-dep-lib-shared/pom.xml b/src/it/it0040-multi-libtype/it0040-dep-lib-shared/pom.xml new file mode 100644 index 00000000..844bad02 --- /dev/null +++ b/src/it/it0040-multi-libtype/it0040-dep-lib-shared/pom.xml @@ -0,0 +1,78 @@ + + + + + 4.0.0 + + + com.github.maven-nar.its.nar + it0040-pom + 1.0-SNAPSHOT + + + it0040-dep-lib-shared + nar + + NAR Executable and Shared Library + 1.0-SNAPSHOT + + Executable depending on a shared library from a mixed type. + + + + true + + + + + + @project.groupId@ + nar-maven-plugin + true + + + + LIB_IMPORTS + + + + + executable + + + it0040-lib-sharedstatic:shared + + + + + + + + + + + com.github.maven-nar.its.nar + it0040-lib-sharedstatic + 1.0-SNAPSHOT + nar + + + diff --git a/src/it/it0040-multi-libtype/it0040-dep-lib-shared/src/main/c/HelloWorldExe.c b/src/it/it0040-multi-libtype/it0040-dep-lib-shared/src/main/c/HelloWorldExe.c new file mode 100644 index 00000000..15f98cc3 --- /dev/null +++ b/src/it/it0040-multi-libtype/it0040-dep-lib-shared/src/main/c/HelloWorldExe.c @@ -0,0 +1,28 @@ +/* + * #%L + * Native ARchive plugin for Maven + * %% + * Copyright (C) 2002 - 2014 NAR Maven Plugin developers. + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +#include +#include "HelloWorldLib.h" + +int main(int argc, char *argv[]) { + printf("%s\n", HelloWorldLib_sayHello()); + return 0; +} + + diff --git a/src/it/it0040-multi-libtype/it0040-dep-lib-static/pom.xml b/src/it/it0040-multi-libtype/it0040-dep-lib-static/pom.xml new file mode 100644 index 00000000..dee32022 --- /dev/null +++ b/src/it/it0040-multi-libtype/it0040-dep-lib-static/pom.xml @@ -0,0 +1,73 @@ + + + + + 4.0.0 + + + com.github.maven-nar.its.nar + it0040-pom + 1.0-SNAPSHOT + + + it0040-dep-lib-static + nar + + NAR Executable and Static Library + 1.0-SNAPSHOT + + Executable depending on a static library from a mixed type. + + + + true + + + + + + @project.groupId@ + nar-maven-plugin + true + + + + executable + + + it0040-lib-sharedstatic:static + + + + + + + + + + + com.github.maven-nar.its.nar + it0040-lib-sharedstatic + 1.0-SNAPSHOT + nar + + + diff --git a/src/it/it0040-multi-libtype/it0040-dep-lib-static/src/main/c/HelloWorldExe.c b/src/it/it0040-multi-libtype/it0040-dep-lib-static/src/main/c/HelloWorldExe.c new file mode 100644 index 00000000..15f98cc3 --- /dev/null +++ b/src/it/it0040-multi-libtype/it0040-dep-lib-static/src/main/c/HelloWorldExe.c @@ -0,0 +1,28 @@ +/* + * #%L + * Native ARchive plugin for Maven + * %% + * Copyright (C) 2002 - 2014 NAR Maven Plugin developers. + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +#include +#include "HelloWorldLib.h" + +int main(int argc, char *argv[]) { + printf("%s\n", HelloWorldLib_sayHello()); + return 0; +} + + diff --git a/src/it/it0040-multi-libtype/it0040-lib-sharedstatic/pom.xml b/src/it/it0040-multi-libtype/it0040-lib-sharedstatic/pom.xml new file mode 100644 index 00000000..87273bd9 --- /dev/null +++ b/src/it/it0040-multi-libtype/it0040-lib-sharedstatic/pom.xml @@ -0,0 +1,93 @@ + + + + + 4.0.0 + + + com.github.maven-nar.its.nar + it0040-pom + 1.0-SNAPSHOT + + + it0040-lib-sharedstatic + nar + + NAR Shared + Static Library + 1.0-SNAPSHOT + + A library with both shared and static and test file + + http://maven.apache.org/ + + + true + + + + + + @project.groupId@ + nar-maven-plugin + true + + + + + static + + + + + + + shared + + nar-download + nar-unpack + nar-compile + nar-test-unpack + nar-testCompile + nar-test + + + + + shared + + + + + LIB_EXPORTS + + + + + + + + + diff --git a/src/it/it0040-multi-libtype/it0040-lib-sharedstatic/src/main/c/HelloWorldLib.c b/src/it/it0040-multi-libtype/it0040-lib-sharedstatic/src/main/c/HelloWorldLib.c new file mode 100644 index 00000000..2611690b --- /dev/null +++ b/src/it/it0040-multi-libtype/it0040-lib-sharedstatic/src/main/c/HelloWorldLib.c @@ -0,0 +1,26 @@ +/* + * #%L + * Native ARchive plugin for Maven + * %% + * Copyright (C) 2002 - 2014 NAR Maven Plugin developers. + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +#include +#include "HelloWorldLib.h" + +char* HelloWorldLib_sayHello() { + return "Hello NAR LIB World!"; +} + diff --git a/src/it/it0040-multi-libtype/it0040-lib-sharedstatic/src/main/include/HelloWorldLib.h b/src/it/it0040-multi-libtype/it0040-lib-sharedstatic/src/main/include/HelloWorldLib.h new file mode 100644 index 00000000..f16109a7 --- /dev/null +++ b/src/it/it0040-multi-libtype/it0040-lib-sharedstatic/src/main/include/HelloWorldLib.h @@ -0,0 +1,43 @@ +/* + * #%L + * Native ARchive plugin for Maven + * %% + * Copyright (C) 2002 - 2014 NAR Maven Plugin developers. + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +#ifndef HelloWorldLib_H +#define HelloWorldLib_H + +#ifdef WIN32 +#ifdef LIB_EXPORTS +#pragma message( "Export" ) +#define LIB_EXPORT __declspec(dllexport) +#else +#ifdef LIB_IMPORTS +#pragma message( "Import" ) +#define LIB_EXPORT __declspec(dllimport) +#else +#pragma message( "Static" ) +#define LIB_EXPORT +#endif +#endif +#else +#define LIB_EXPORT +#endif + + +LIB_EXPORT extern char* HelloWorldLib_sayHello(); + +#endif diff --git a/src/it/it0040-multi-libtype/it0040-lib-sharedstatic/src/test/c/HelloWorldTest.c b/src/it/it0040-multi-libtype/it0040-lib-sharedstatic/src/test/c/HelloWorldTest.c new file mode 100644 index 00000000..15f98cc3 --- /dev/null +++ b/src/it/it0040-multi-libtype/it0040-lib-sharedstatic/src/test/c/HelloWorldTest.c @@ -0,0 +1,28 @@ +/* + * #%L + * Native ARchive plugin for Maven + * %% + * Copyright (C) 2002 - 2014 NAR Maven Plugin developers. + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +#include +#include "HelloWorldLib.h" + +int main(int argc, char *argv[]) { + printf("%s\n", HelloWorldLib_sayHello()); + return 0; +} + + diff --git a/src/it/it0040-multi-libtype/pom.xml b/src/it/it0040-multi-libtype/pom.xml new file mode 100644 index 00000000..c642ad31 --- /dev/null +++ b/src/it/it0040-multi-libtype/pom.xml @@ -0,0 +1,55 @@ + + + + + 4.0.0 + + + com.github.maven-nar.its.nar + it-parent + 1.0-SNAPSHOT + ../it-parent/pom.xml + + + it0040-pom + pom + + NAR Multi Module + 1.0-SNAPSHOT + + Simple Multi Module project + + http://maven.apache.org/ + + + integration-test + + + + + it0040-lib-sharedstatic + it0040-dep-lib-default + it0040-dep-lib-shared + it0040-dep-lib-static + + From 4048b7f6d67be5533fb430d16f6822b98303cc47 Mon Sep 17 00:00:00 2001 From: Greg Domjan Date: Wed, 27 Jan 2021 17:36:04 +1100 Subject: [PATCH 3/6] Allow config of binding to dependency --- src/main/java/com/github/maven_nar/NarCompileMojo.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/maven_nar/NarCompileMojo.java b/src/main/java/com/github/maven_nar/NarCompileMojo.java index 0ec7404d..7065a30f 100644 --- a/src/main/java/com/github/maven_nar/NarCompileMojo.java +++ b/src/main/java/com/github/maven_nar/NarCompileMojo.java @@ -371,8 +371,9 @@ private void createLibrary(final Project antProject, final Library library) // FIXME no handling of "local" - // FIXME, no way to override this at this stage - final String binding = dependency.getNarInfo().getBinding(getAOL(), Library.NONE); + String binding = getBinding(library, dependency); + if (binding == null) + binding = dependency.getNarInfo().getBinding(getAOL(), Library.NONE); getLog().debug("Using Binding: " + binding); AOL aol = getAOL(); aol = dependency.getNarInfo().getAOL(getAOL()); From 8113094b3cd87542006d5de538efcd2be0aae29e Mon Sep 17 00:00:00 2001 From: Greg Domjan Date: Mon, 26 Jul 2021 17:01:28 +1000 Subject: [PATCH 4/6] Add Java10+ support to build tests Using profile to skip javah from NAR add jni config for maven-compiler-plugin --- src/it/it-parent/pom.xml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/it/it-parent/pom.xml b/src/it/it-parent/pom.xml index 12af6e6c..e8dd2b6a 100644 --- a/src/it/it-parent/pom.xml +++ b/src/it/it-parent/pom.xml @@ -88,5 +88,33 @@ + + java-10+ + + [10,) + + + + + com.github.maven-nar + nar-maven-plugin + + + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + ${project.build.directory}/nar/javah-include + + + + + + From 224785d12fad0f02a9d9232cb85de2a5e0c391b8 Mon Sep 17 00:00:00 2001 From: Greg Domjan Date: Mon, 26 Jul 2021 17:04:16 +1000 Subject: [PATCH 5/6] Allow running IT from alternate folder Getting fatal error LNK1104: cannot open file 'it0031-push-deps-to-lowest-order-B-1.0-SNAPSHOT.lib' You may see this error when the path for filename expands to more than 260 characters. If needed, rearrange your directory structure or shorten your folder and file names to shorten the paths. Provide property default to match plugin default, and allow setting alternate from command line --- pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pom.xml b/pom.xml index c418f6f8..54bfa1d4 100644 --- a/pom.xml +++ b/pom.xml @@ -116,6 +116,7 @@ false + ${project.build.directory}/it dummy 3.0.4 UTF-8 @@ -541,6 +542,7 @@ maven-invoker-plugin 3.2.0 + ${invoker.workspace} true From 05994c1ad06bd718f598d24a74c9e3e2b1b5e5bc Mon Sep 17 00:00:00 2001 From: Greg Domjan Date: Mon, 26 Jul 2021 19:21:22 +1000 Subject: [PATCH 6/6] Add objdir support for mixed static + shared build --- src/main/java/com/github/maven_nar/NarCompileMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/github/maven_nar/NarCompileMojo.java b/src/main/java/com/github/maven_nar/NarCompileMojo.java index 7065a30f..d053bd0c 100644 --- a/src/main/java/com/github/maven_nar/NarCompileMojo.java +++ b/src/main/java/com/github/maven_nar/NarCompileMojo.java @@ -145,7 +145,7 @@ private void createLibrary(final Project antProject, final Library library) // object directory File objDir = new File(getTargetDirectory(), "obj"); - objDir = new File(objDir, getAOL().toString()); + objDir = new File(objDir, getAOL().toString() + "-" + library.getType()); objDir.mkdirs(); task.setObjdir(objDir);