diff --git a/doc/languages-frameworks/julia.section.md b/doc/languages-frameworks/julia.section.md index 235861ac528fb6..4e7d9d365a39e5 100644 --- a/doc/languages-frameworks/julia.section.md +++ b/doc/languages-frameworks/julia.section.md @@ -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. diff --git a/pkgs/development/julia-modules/default.nix b/pkgs/development/julia-modules/default.nix index 737cb9345a4bf6..411e091e1343f9 100644 --- a/pkgs/development/julia-modules/default.nix +++ b/pkgs/development/julia-modules/default.nix @@ -1,13 +1,14 @@ -{ lib -, callPackage -, runCommand +{ callPackage , fetchgit , fontconfig , git +, lib , makeWrapper +, python3 +, runCommand +, system , writeText , writeTextFile -, python3 # Artifacts dependencies , fetchurl @@ -23,11 +24,12 @@ # 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: @@ -35,7 +37,6 @@ 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 @@ -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 diff --git a/pkgs/development/julia-modules/depot.nix b/pkgs/development/julia-modules/depot.nix index 017bc19acd503b..b2363c63e679d5 100644 --- a/pkgs/development/julia-modules/depot.nix +++ b/pkgs/development/julia-modules/depot.nix @@ -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" @@ -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="" @@ -84,6 +87,10 @@ 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 @@ -91,4 +98,4 @@ runCommand "julia-depot" { # Remove the registry to save space Pkg.Registry.rm("General") ' -'' +'')