clj.native-image开源项目

我要开发同款
匿名用户2021年11月17日
46阅读
开发技术JavaScript
所属分类应用工具、终端/远程登录
授权协议MIT License

作品详情

clj.native-image

BuildGraalVMnativeimagesusingClojureDepsandCLItools.

Thisshouldbeusefulforcreatinglightweight,nativeCLIexecutablesusingClojureanddeps.edn.Seeclj.native-cliforastarterprojecttemplate.

Thisprojectdependsontools.deps.alphaandshouldbeconsideredalphaitself.

Prerequisites

ClojureCLItools

GraalVM

NOTE:AsofGraalVM19.0.0,native-imageisnolongerincludedbydefault:

NativeImagewasextractedfromthebaseGraalVMdistribution.Currentlyitisavailableasanearlyadopterplugin.Toinstallit,run:guinstallnative-image.Afterthisadditionalstep,thenative-imageexecutablewillbeinthebindirectory,asforthepreviousreleases.

➜$GRAALVM_HOME/bin/guinstallnative-imageDownloading:Componentcatalogfromwww.graalvm.orgProcessingcomponentarchive:NativeImageDownloading:Componentnative-image:NativeImagefromgithub.comInstallingnewcomponent:NativeImagelicencefiles(org.graalvm.native-image,version19.0.0)Usage

Assumingaprojectstructurelikethis:

.├──deps.edn└──src└──core.clj

Inyourdeps.ednspecifyanaliaswithadependencyonclj.native-image:

{:aliases{:native-image{:main-opts["-m""clj.native-image""core""--initialize-at-build-time";;optionalnativeimagenameoverride"-H:Name=core"]:jvm-opts["-Dclojure.compiler.direct-linking=true"]:extra-deps{clj.native-image/clj.native-image{:git/url"https://github.com/taylorwood/clj.native-image.git":sha"7708e7fd4572459c81f6a6b8e44c96f41cdd92d4"}}}}}

Wherecore.cljisaclasswith-mainentrypoint,forexample:

(nscore(:gen-class))(defn-main[&args](println"Hello,World!"))

Fromyourprojectdirectory,invokeclojurewiththenative-imagealias,specifyingthemainnamespace(coreinexampleabove):

➜clojure-A:native-imageLoadingcoreCompilingcoreBuildingnativeimage'core'withclasspath'classes:src:etc.'classlist:1,944.26ms8<----------------------[total]:38,970.37ms

Note:EitherGRAALVM_HOMEenvironmentvariablemustbeset,orGraalVM'snative-imagepathmustbepassedasanargument,andanyadditionalargumentswillbepassedtonative-imagee.g.:

➜clojure-A:native-image--verbose

Youcannowexecutethenativeimage:

➜./coreHello,World!

SeethisGistforanotherexample.

ExampleProjects

Thereareexampledeps.ednprojectsinthelein-native-imagerepo:

jdnsmith-CLIJSON-to-EDNtransformerhttp-api-simpleHTTPAPIserverclojurl-cURL-liketoolusingclojure.spec,HTTPS,hiccupCaveats

The--no-serverflagispassedtonative-imagebydefault,toavoidcreatingorphanedbuildservers.

Alsoseecaveatssectionoflein-native-image.

References

GraalVMNativeImageAOTCompilation

Thisprojectwasinspiredbydepstar.

Contributing

You'llneedClojureCLItoolingandGraalVMinstalledtotestlocally.Justchangethesourceoftheclj.native-imagedependencytoa:local/rootinsteadof:git/url.

Issues,PRs,andsuggestionsarewelcome!

License

Copyright©2018TaylorWood.

DistributedundertheMITLicense.

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论