Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. # Basic Setup
  2.  
  3. add PackageCompiler@0.5.1
  4.  
  5. If you are trying different julia versions, you need to move the folder where sys.dll ends up in so it does it brand new.
  6.  
  7. Every deps.jl in any dependent package that has a built library, such as MbedTLS.jl or Rmath.jl or SpecialFunctions.jl
  8. all need to be modified to not use absolute paths on the harddrive to make deployment managable.
  9.  
  10. Change them from the generated code that came out of BinaryDependancy.jl
  11.  
  12. ```
  13. libxxxxx = joinpath(currentpath_for_deps, "usr","lib","libxxx.dll")
  14. ```
  15. to
  16. ```
  17. libxxxxx = "libxxx.dll"
  18. ```
  19.  
  20. Now you will need to copy dlls into the runpath or dll search path for each place you are planning on running from.
  21.  
  22. The package will get built into the root_modules but won't get listed properly. To enable proper listing as a baked in package,
  23. you can either look it up using the UUID at runtime with something like:
  24.  
  25. ```
  26. MyCustomPackage = Base.root_module(Base.PkgId(Base.UUID("abcdef0123-xxxx-xxxx-xxxx-xxxxxxxxxxxx"), "MyCustomPackage"))
  27. ```
  28. or you can spoof into the StdLibs. This feels more elegant for the end use of the function but is a little hacky up front.
  29. You have to put in a fake StdLib folder for your module, with an empty `src` folder, and make a simple project file.
  30.  
  31. A generic way to do that follows:
  32. ```
  33. function make_package_placeholder_in_stdlib(pkg_name)
  34. stdlib_path = joinpath(dirname(Base.julia_cmd().exec[1]), "..", "share", "julia", "stdlib", "v"*string(VERSION)[1:3])
  35. # make the destination folder structure
  36. new_dir = joinpath(stdlib_path, pkg_name, "src")
  37. @show new_dir
  38. mkpath(new_dir)
  39. @assert isdir(new_dir)
  40.  
  41. # write an empty MyPackage.jl file under src
  42. open(io->write(io, ""), joinpath(stdlib_path, pkg_name, "src", pkg_name * ".jl"), "w")
  43. # write a TOML file with just the package name and the uuid
  44. pkg_uuid = try
  45. # string(Base.module_keys[findfirst(x-> x.name == pkg_name, Base.module_keys)].uuid)
  46. Pkg.TOML.parsefile(joinpath(Pkg.API.dir(pkg_name),"Project.toml"))["uuid"]
  47. catch e
  48. @show findfirst(x-> x.name == pkg_name, Base.module_keys)
  49. error("Failed to find $pkg_name 's uuid in its Project.toml")
  50. end
  51.  
  52. stdlib_project_toml_file = joinpath(stdlib_path, pkg_name, "Project.toml")
  53.  
  54. # open(io->Pkg.TOML.print(io, Dict("name"=>pkg_name, "uuid"=>pkg_uuid)), stdlib_project_toml_file, "w")
  55. open(stdlib_project_toml_file, "w") do io
  56. Pkg.TOML.print(io, Dict("name"=>pkg_name, "uuid"=>pkg_uuid))
  57. end
  58.  
  59. @show stdlib_project_toml_file
  60. @assert isfile(stdlib_project_toml_file)
  61. end
  62. ```
  63. BUT using this function will gimp julia/loading.jl later. So when you are done compiling, you should clean up
  64. and remove this spoofed folder.
  65.  
  66. You can now build a custom julia sys library using
  67.  
  68. ```
  69. PackageCompiler.compile_package("MyCustomPackage"; force = false, reuse = false, cpu_target = "x86-64")
  70. ```
  71.  
  72. # Troubleshooting
  73.  
  74. If you fail to remove the spoofed folder in `StdLib` you end up with the following error when using `Pkg.test`
  75.  
  76. ```
  77. (MyCustomPackage) pkg> test MyCustomPackage
  78. Testing MyCustomPackage
  79. Resolving package versions...
  80. WARNING: --output requested, but no modules defined during run
  81. ┌ Warning: The call to compilecache failed to create a usable precompiled cache file for MyCustomPackage [abcdef0123-xxxx-xxxx-xxxx-xxxxxxxxxxxx]
  82. │ exception = ArgumentError: Invalid header in cache file /Users/username/.julia/compiled/v1.0/MyCustomPackage/xGNPz.ji.
  83. └ @ Base loading.jl:969
  84. ERROR: LoadError: KeyError: key MyCustomPackage [abcdef0123-xxxx-xxxx-xxxx-xxxxxxxxxxxx] not found
  85. Stacktrace:
  86. [1] getindex at ./dict.jl:478 [inlined]
  87. [2] root_module at ./loading.jl:898 [inlined]
  88. [3] require(::Base.PkgId) at ./loading.jl:864
  89. [4] require(::Module, ::Symbol) at ./loading.jl:853
  90. [5] include at ./boot.jl:317 [inlined]
  91. [6] include_relative(::Module, ::String) at ./loading.jl:1044
  92. [7] include(::Module, ::String) at ./sysimg.jl:29
  93. [8] include(::String) at ./client.jl:392
  94. [9] top-level scope at none:0
  95. in expression starting at /Users/username/development/packages/MyCustomPackage/test/runtests.jl:5
  96. ERROR: Package MyCustomPackage errored during testing
  97. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement