Easiest way to "compile" program to single file

Hi, I have the following issue:

I want to use julia at a coding competition:

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?

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.)

1 Like

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…

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?

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.

1 Like

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.

1 Like

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”.

1 Like