# Easiest way to "compile" program to single file

**URL:** <https://discourse.julialang.org/t/easiest-way-to-compile-program-to-single-file/76616>\
**Category:** General Usage\
**Tags:** question, package\
**Created:** [February 17, 2022, 9:03am UTC](https://discourse.julialang.org/t/easiest-way-to-compile-program-to-single-file/76616 "2022-02-17T09:03:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![peteole](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peteole/32/209790_2.png) [@peteole](https://discourse.julialang.org/u/peteole)\
**Post date:** [February 17, 2022, 9:03am UTC](https://discourse.julialang.org/t/easiest-way-to-compile-program-to-single-file/76616/1 "2022-02-17T09:03:12Z")

</div>

Hi, I have the following issue:

I want to use julia at a coding competition:  
[https://codingcompetitions.withgoogle.com/kickstart](https://codingcompetitions.withgoogle.com/kickstart)  
It works fine for old problems. However there is the issue that sometimes I want to use a package (for example DataStructures.jl), but the package manager is disabled for the submissions and I can only submit a single file.  
Is there a nice way to output all the code that has been evaluated when running a program locally (the code from the packages imported and the code I wrote) to a single file?

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [February 17, 2022, 2:00pm UTC](https://discourse.julialang.org/t/easiest-way-to-compile-program-to-single-file/76616/2 "2022-02-17T14:00:31Z")

</div>

Would this not be considered cheating? Also, would this not infringe the license of the libraries (many probably are liberal enough but are all)? Did you check if `DataStructures.jl` is not already imported? (I had the same problem with another platform and discovered they kept a curated set of packages already loaded, to make it fairer compared to languages with data structures in the base library.)

---

<div class="post-metadata">

**Author:** ![peteole](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peteole/32/209790_2.png) [@peteole](https://discourse.julialang.org/u/peteole)\
**Post date:** [February 17, 2022, 6:51pm UTC](https://discourse.julialang.org/t/easiest-way-to-compile-program-to-single-file/76616/3 "2022-02-17T18:51:34Z")

</div>

Unfortunately it is not imported already. I did not find anything in the FAQ indicating if it is legal, so I just emailed regarding this matter, also asking if they could just import the package by default.

The license is MIT, so I would have to copy the copyright notice into the solution.

But yes, it’s a bit unfair that other languages already have heaps, queues ect by default…

---

<div class="post-metadata">

**Author:** ![peteole](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peteole/32/209790_2.png) [@peteole](https://discourse.julialang.org/u/peteole)\
**Post date:** [February 17, 2022, 7:58pm UTC](https://discourse.julialang.org/t/easiest-way-to-compile-program-to-single-file/76616/4 "2022-02-17T19:58:20Z")

</div>

The team just replied to my email, it’s totally fine from their side. So the question remains: is it technically possible to do so?

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [February 18, 2022, 12:27am UTC](https://discourse.julialang.org/t/easiest-way-to-compile-program-to-single-file/76616/5 "2022-02-18T00:27:30Z")

</div>

I am not aware of an automated solution. Theoretically, for each package you need to copy the main source file, and then, recursively replace each line with `include` by the whole text contained in the respective included file. Then you copy this single file with a gigantic module containing all the package code to your final file, and repeat the process for any packages imported by this newly added code. After this, the single final file will have multiple separate `module` declarations above your own code and every `using`/`import` of yours would change from `using X` to `using .X`. If the imported modules themselves import module from other packages also copied to the final file then their imports probably need to be changed to `using ..X`.

As Julia makes use of precompilation, I think Julia itself do not do exactly that, it already uses the precompiled files (`.ji`), so I am nor sure where you would find this machinery ready to use. For one or two dependencies that have themselves no other dependencies it is doable by hand, but more than that quickly becomes intractable.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [February 18, 2022, 4:22am UTC](https://discourse.julialang.org/t/easiest-way-to-compile-program-to-single-file/76616/6 "2022-02-18T04:22:02Z")

</div>

Maybe you can ask them to support a select few third-party libraries that are relevant to the sort of challenges they offer? For example, they support NumPy and SciPy for Python, at least from what I’ve read. That would be a far saner approach than using a `ShoveEverythingInOneSourceFile.jl` package to generate submissions. I’m sure they don’t want those kind of submissions because the Rules state a 100KB limit on source file size. I also have a feeling they would frown upon copy-pasting source code of any size, whether manually or automatically.

---

<div class="post-metadata">

**Author:** ![peteole](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peteole/32/209790_2.png) [@peteole](https://discourse.julialang.org/u/peteole)\
**Post date:** [February 19, 2022, 10:38pm UTC](https://discourse.julialang.org/t/easiest-way-to-compile-program-to-single-file/76616/7 "2022-02-19T22:38:23Z")

</div>

> [@Benny](#):
>
> Maybe you can ask them to support a select few third-party libraries that are relevant to the sort of challenges they offer

That’s what I did. You are right, this would be by far the most elegant solution. They said they will “pass on the feedback and see what they can do”.
