Skip to content

Commit

Permalink
julia.withPackages: add juliaCpuTarget option
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasjm committed Dec 4, 2024
1 parent 078f125 commit b69b526
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
11 changes: 11 additions & 0 deletions doc/languages-frameworks/julia.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ nix-shell -p 'julia.withPackages ["Plots"]' --run julia

This normally points at a special augmented version of the Julia [General packages registry](https://github.com/JuliaRegistries/General).
If you want to use a bleeding-edge version to pick up the latest package updates, you can plug in a later revision than the one in Nixpkgs.

* `juliaCpuTarget`: Allows you to set `JULIA_CPU_TARGET` when precompiling. Has no effect if `precompile=false`.

You may want to use this if you're building a Julia depot that will end up in a Nix cache and used on machines with
different CPUs.

Why? Julia will detect the CPU microarchitecture of the build machine and include this information in the precompiled
`*.ji` files. Starting in 1.10 Julia became more strict about checking the CPU target compatibility, so it may reject
your precompiled files if they were compiled on a different machine.
A good option to provide wide compatibility is to set this to `"generic"`, although this may reduce performance.
You can also set a semicolon-separated list of multiple different targets. See the Julia documentation for details.
19 changes: 10 additions & 9 deletions pkgs/development/julia-modules/default.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{ lib
, callPackage
, runCommand
{ callPackage
, fetchgit
, fontconfig
, git
, lib
, makeWrapper
, python3
, runCommand
, system
, writeText
, writeTextFile
, python3

# Artifacts dependencies
, fetchurl
Expand All @@ -23,19 +24,19 @@

# Other overridable arguments
, extraLibs ? []
, precompile ? true
, setDefaultDepot ? true
, juliaCpuTarget ? null
, makeTransitiveDependenciesImportable ? false # Used to support symbol indexing
, makeWrapperArgs ? ""
, packageOverrides ? {}
, makeTransitiveDependenciesImportable ? false # Used to support symbol indexing
, precompile ? true
, setDefaultDepot ? true
}:

packageNames:

let
util = callPackage ./util.nix {};


# Some Julia packages require access to Python. Provide a Nixpkgs version so it
# doesn't try to install its own.
pythonToUse = let
Expand Down Expand Up @@ -152,7 +153,7 @@ let
# Build a Julia project and depot. The project contains Project.toml/Manifest.toml, while the
# depot contains package build products (including the precompiled libraries, if precompile=true)
projectAndDepot = callPackage ./depot.nix {
inherit closureYaml extraLibs overridesToml packageImplications precompile;
inherit closureYaml extraLibs juliaCpuTarget overridesToml packageImplications precompile;
julia = juliaWrapped;
registry = minimalRegistry;
packageNames = if makeTransitiveDependenciesImportable
Expand Down
19 changes: 13 additions & 6 deletions pkgs/development/julia-modules/depot.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,18 @@

, closureYaml
, extraLibs
, juliaCpuTarget
, overridesToml
, packageNames
, packageImplications
, packageNames
, precompile
, registry
}:

runCommand "julia-depot" {
nativeBuildInputs = [curl git julia (python3.withPackages (ps: with ps; [pyyaml]))] ++ extraLibs;
inherit precompile registry;
} ''
nativeBuildInputs = [curl git julia (python3.withPackages (ps: with ps; [pyyaml]))] ++ extraLibs;
inherit precompile registry;
} (''
export HOME=$(pwd)
echo "Building Julia depot and project with the following inputs"
Expand All @@ -42,7 +43,9 @@ runCommand "julia-depot" {
# Only precompile if configured to below
export JULIA_PKG_PRECOMPILE_AUTO=0
'' + lib.optionalString (juliaCpuTarget != null) ''
export JULIA_CPU_TARGET="${juliaCpuTarget}"
'' + ''
# Prevent a warning where Julia tries to download package server info
export JULIA_PKG_SERVER=""
Expand Down Expand Up @@ -84,11 +87,15 @@ runCommand "julia-depot" {
Pkg.instantiate()
if "precompile" in keys(ENV) && ENV["precompile"] != "0" && ENV["precompile"] != ""
if isdefined(Sys, :CPU_NAME)
println("Precompiling with CPU_NAME = " * Sys.CPU_NAME)
end
Pkg.precompile()
end
end
# Remove the registry to save space
Pkg.Registry.rm("General")
'
''
'')

0 comments on commit b69b526

Please sign in to comment.