|
| 1 | +# HAT Project Primer |
| 2 | + |
| 3 | +This is a fairly large project with Java and Native artifacts. |
| 4 | + |
| 5 | +We also rely on the `babylon` (JDK23+Babylon) project, and the project will initially be made available as a subproject |
| 6 | +called `hat` under [github.com/openjdk/babylon](https://github.com/openjdk/babylon) |
| 7 | + |
| 8 | +## Intellij and Clion |
| 9 | + |
| 10 | +Whilst I do use JetBrains' `IntelliJ` and `Clion` for dev work and plan to leave project artifacts in the tree. |
| 11 | +Care must be taken as these tools do not play well together, specifically we cannot have `Clion` and `Intellij` |
| 12 | +project artifacts rooted under each other or in the same dir. |
| 13 | + |
| 14 | +I have `intellij` and `clion` siblings which will act as roots |
| 15 | +for various tools and then use relative paths (or even symbolic links) in the various `.iml` files to locate the various source roots |
| 16 | + |
| 17 | +So far this has worked ok. |
| 18 | + |
| 19 | +### cmake and maven |
| 20 | + |
| 21 | +We use maven for java artifacts and cmake for native libs (backends) although the root level CMakeLists.txt can also create java artifacts. |
| 22 | + |
| 23 | +Generally to run any cmake target. |
| 24 | +```bash |
| 25 | +cd hat |
| 26 | +mkdir build |
| 27 | +cd build |
| 28 | +cmake .. |
| 29 | +cd .. |
| 30 | +cmake --build build --target <yourtarget> |
| 31 | +``` |
| 32 | + |
| 33 | +The maven build will build hat and will then delegate to cmake to build the backends. |
| 34 | + |
| 35 | +To build with maven |
| 36 | + |
| 37 | +```bash |
| 38 | +mvn clean compile assembly:single test |
| 39 | +``` |
| 40 | + |
| 41 | +### Initial Project Layout |
| 42 | + |
| 43 | + |
| 44 | +``` |
| 45 | +${BABYLON_JDK} |
| 46 | + └── hat |
| 47 | + │ |
| 48 | + ├── CMakeFile |
| 49 | + ├── build |
| 50 | + │ |
| 51 | + ├── intellij |
| 52 | + │ ├── .idea |
| 53 | + │ │ ├── compiler.xml |
| 54 | + │ │ ├── misc.xml |
| 55 | + │ │ ├── modules.xml |
| 56 | + │ │ ├── uiDesigner.xml |
| 57 | + │ │ ├── vcs.xml |
| 58 | + │ │ └── workspace.xml |
| 59 | + │ │ |
| 60 | + │ ├── hat.iml |
| 61 | + │ ├── backend_(spirv|mock|cuda|ptx|opencl).iml |
| 62 | + │ └── (mandel|violajones|experiments).iml |
| 63 | + │ |
| 64 | + ├── hat |
| 65 | + │ └── src |
| 66 | + │ └── java |
| 67 | + │ |
| 68 | + ├── backends |
| 69 | + │ └── (opencl|cuda|ptx|mock|shared) |
| 70 | + │ └── src |
| 71 | + │ ├── cpp |
| 72 | + │ ├── include |
| 73 | + │ ├── java |
| 74 | + │ └── services |
| 75 | + └── examples |
| 76 | + ├── mandel |
| 77 | + │ └── src |
| 78 | + │ └── java |
| 79 | + └── violajones |
| 80 | + └── src |
| 81 | + ├── java |
| 82 | + └── resources |
| 83 | +``` |
| 84 | +As you will note the `intellij` dir is somewhat self contained. the various `*.iml` |
| 85 | +files refer to the source dirs using relative paths. |
| 86 | + |
| 87 | +I tend to add `Intelli` modules by hand. There are gotchas ;) |
| 88 | + |
| 89 | +As with every intellij project, `.idea/modules.xml` 'points' to the iml files for each module (intellij's notion of module ;) ) |
| 90 | +```xml |
| 91 | +<!-- |
| 92 | + └──hat |
| 93 | + └── intellij |
| 94 | + └── .idea |
| 95 | + └── modules.xml |
| 96 | +--> |
| 97 | + <modules> |
| 98 | + <module fileurl="file://$PROJECT_DIR$/hat.iml" /> |
| 99 | + <module fileurl="file://$PROJECT_DIR$/backend_opencl.iml" /> |
| 100 | + <!-- yada yada --> |
| 101 | + </modules> |
| 102 | + |
| 103 | +``` |
| 104 | + |
| 105 | +The various `.iml` files then have relative paths to their source/resource dirs roots. |
| 106 | + |
| 107 | +```xml |
| 108 | +<module type="JAVA_MODULE" version="4"> |
| 109 | + <component name="NewModuleRootManager" inherit-compiler-output="true"> |
| 110 | + <exclude-output /> |
| 111 | + <content url="file://$MODULE_DIR$/../../../hat/src/java"> |
| 112 | + <sourceFolder url="file://$MODULE_DIR$/../../../hat/src/java" isTestSource="false" /> |
| 113 | + </content> |
| 114 | + <orderEntry type="inheritedJdk" /> |
| 115 | + <orderEntry type="sourceFolder" forTests="false" /> |
| 116 | + <orderEntry type="module" module-name="hat" /> |
| 117 | + </component> |
| 118 | +</module> |
| 119 | + |
| 120 | +``` |
| 121 | +### How intellij stores run configurations |
| 122 | + |
| 123 | +I also tend to hand hack run configurations so will leave this here for reference |
| 124 | + |
| 125 | +```xml |
| 126 | +<component name="RunManager" selected="Application.MandelTest"> |
| 127 | + <configuration name="Mandel" type="Application" |
| 128 | + factoryName="Application" temporary="true" |
| 129 | + nameIsGenerated="true"> |
| 130 | + <option name="MAIN_CLASS_NAME" value="mandel.Mandel" /> |
| 131 | + <module name="mandel" /> |
| 132 | + <option name="VM_PARAMETERS" value=" |
| 133 | + --enable-preview |
| 134 | + --add-exports=java.base/java.lang.reflect.code.descriptor.impl=ALL-UNNAMED |
| 135 | + --add-exports=java.base/java.lang.foreign.mapper=ALL-UNNAMED |
| 136 | + --patch-module=java.base=$PROJECT_DIR$/out/production/java_base_patch |
| 137 | + -Djava.lang.foreign.mapper.debug=true" /> |
| 138 | + <extension name="coverage"> |
| 139 | + <pattern> |
| 140 | + <option name="PATTERN" value="mandel.*" /> |
| 141 | + <option name="ENABLED" value="true" /> |
| 142 | + </pattern> |
| 143 | + </extension> |
| 144 | + <method v="2"> |
| 145 | + <option name="Make" enabled="true" /> |
| 146 | + </method> |
| 147 | + </configuration> |
| 148 | + <!-- more configs --> |
| 149 | +</component> |
| 150 | +``` |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | + |
0 commit comments