Skip to content

Commit

Permalink
asdf
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronmondal committed May 24, 2024
1 parent a43b3c3 commit a1dcb60
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 55 deletions.
17 changes: 0 additions & 17 deletions local-remote-execution/lre-mojo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,7 @@
}:

let
# This environment is shared between toolchain autogen images and the final
# toolchain image.
Env = mojoEnv;
# [
# # Add all tooling here so that the generated toolchains use `/nix/store/*`
# # paths instead of `/bin` or `/usr/bin`. This way we're guaranteed to use
# # binary identical toolchains during local and remote execution.
# ("PATH="
# + (lib.strings.concatStringsSep ":" [
# "${gcc}/bin"
# "${mojo-sdk}/bin"
# ]))
# "MODULAR_HOME=${mojo-sdk}"
# "MOJO_COMPILER=${mojo-sdk}/bin/mojo"
# "MOJO_CC_PATH=${gcc}/bin:${mojo-sdk}/bin"
# "MOJO_LIBRARY_PATH=${zlib}/lib:${ncurses}/lib"
# "MOJO_PYTHON_LIBRARY=${python312}/lib"
# ];
in
buildImage {
name = "lre-mojo";
Expand Down
7 changes: 1 addition & 6 deletions modules/defaultMojoEnv.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
{ pkgs, mojo-sdk, ... }:

[
# "PATH=${pkgs.lib.makeBinPath mojo-sdk.passthru.mojoBinPath}"
"MODULAR_HOME=${mojo-sdk}"
"MOJO_COMPILER=${mojo-sdk}/bin/mojo"
"MOJO_CC_PATH=${pkgs.lib.makeBinPath mojo-sdk.passthru.mojoBinPath}"
"MOJO_LIBRARY_PATH=${pkgs.lib.makeLibraryPath mojo-sdk.passthru.mojoLibraryPath}"
"LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath mojo-sdk.passthru.mojoLibraryPath}"

# "MOJO_LIBRARY_PATH=${pkgs.zlib-ng.override{withZlibCompat=true;}}/lib:${pkgs.ncurses}/lib"

# TODO(aaronmondal): This needs to be set during runtime. Let's just add it to
# a mojo wrapper script.
# TODO(aaronmondal): This needs to be set during runtime.
# "MOJO_PYTHON_LIBRARY=${pkgs.python312}/lib/libpython3.12.so.1.0"
]
18 changes: 4 additions & 14 deletions mojo-sdk.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ stdenv.mkDerivation rec {

nativeBuildInputs = [ autoPatchelfHook zstd makeWrapper ];

# nativeBuildInputs = [ autoPatchelfHook zstd makeWrapper ];

unpackPhase = ''
zstd -d $src -c | tar xvf -
'';
Expand All @@ -61,11 +59,6 @@ stdenv.mkDerivation rec {
# that is `libedit.so.2.0.72` in Ubuntu.
ln -s ${libedit}/lib/libedit.so.0 lib/libedit.so.2
# Brute-force copy tinfo into the same directory as the mojo sources.
# It appears that mojo can't figure out how to find libtinfo otherwise.
cp ${tinfo}/lib/libtinfo.so.6.4 lib/libtinfo.so.6.4
ln -s libtinfo.so.6.4 lib/libtinfo.so.6
# The mojo command uses this config file to determine the
# locations to bundled dependencies. Remap it to /nix/store.
sed -i "s|\$_self.install_path|$out|g" modular.cfg
Expand All @@ -87,9 +80,8 @@ stdenv.mkDerivation rec {
#
# WARNING: At the moment linking phase can't figure out how to link tinfo.
# To work around this we allow leaving the tinfo symbols undefined and
# unlinked. This is a very risky and dangerous practice that might trigger
# random segfaults during runtime.
sed -i "s|system_libs = -lrt,-ldl,-lpthread,-lm,-lz,-ltinfo;|system_libs = -fuse-ld=mold,-lrt,-ldl,-lpthread,-lm,-L,${zlib}/lib,-Xlinker,-rpath=${zlib}/lib,-Xlinker,-L,${tinfo}/lib,-Xlinker,-rpath=${tinfo}/lib,-Xlinker,-rpath=${stdenv.cc.cc.lib}/lib,--verbose,-Xlinker,--verbose,-Xlinker,-v,-Xlinker,--allow-shlib-undefined,-Xlinker,--unresolved-symbols=ignore-all;|g" modular.cfg
# unlinked. This is a risky practice and might trigger segfaults at runtime.
sed -i "s|system_libs = -lrt,-ldl,-lpthread,-lm,-lz,-ltinfo;|system_libs = -fuse-ld=mold,-lrt,-ldl,-lpthread,-lm,-Xlinker,-rpath=${glibc}/lib,-L,${zlib}/lib,-Xlinker,-rpath=${zlib}/lib,-Xlinker,-L,${tinfo}/lib,-Xlinker,-rpath=${tinfo}/lib,-Xlinker,-rpath=${stdenv.cc.cc.lib}/lib,-Xlinker,--unresolved-symbols=ignore-in-object-files,--verbose;|g" modular.cfg
'';

installPhase = ''
Expand All @@ -108,11 +100,9 @@ stdenv.mkDerivation rec {
postInstall = ''
wrap_with_env() {
wrapProgram $1 \
--set MODULAR_HOME $out \
--prefix PATH : ${clang}/bin:${mold}/bin:${uutils-coreutils-noprefix}/bin \
--prefix MODULAR_HOME : $out \
--prefix LIBRARY_PATH : ${makeLibraryPath [ tinfo ncurses zlib stdenv.cc.cc.lib ]} \
--prefix LD_LIBRARY_PATH : ${makeLibraryPath [ tinfo ncurses zlib stdenv.cc.cc.lib ]} \
--set LD_LIBRARY_PATH ${makeLibraryPath [ tinfo ncurses zlib stdenv.cc.cc.lib ]}
--prefix LD_LIBRARY_PATH : ${makeLibraryPath [ tinfo ncurses zlib stdenv.cc.cc.lib glibc ]}
}
wrap_with_env $out/bin/mojo
Expand Down
6 changes: 2 additions & 4 deletions mojo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ load("//mojo:toolchain.bzl", "mojo_toolchain")
"MODULAR_HOME",
"MOJO_COMPILER",
"MOJO_CC_PATH",
"MOJO_LIBRARY_PATH",
"MOJO_PYTHON_LIBRARY",
"LD_LIBRARY_PATH",
"MOJO_DYNAMIC_LINKER",
"MOJO_PYTHON_LIBRARY",

# Unset values default to an empty string.
"MOJO_UNSET",
Expand All @@ -27,10 +25,10 @@ toolchain_type(name = "toolchain_type")

mojo_toolchain(
name = "mojo_toolchain_x86_64-unknown-linux-gnu",
LD_LIBRARY_PATH = ":LD_LIBRARY_PATH",
MODULAR_HOME = ":MODULAR_HOME",
MOJO_CC_PATH = ":MOJO_CC_PATH",
MOJO_COMPILER = ":MOJO_COMPILER",
MOJO_LIBRARY_PATH = ":MOJO_LIBRARY_PATH",
MOJO_PYTHON_LIBRARY = ":MOJO_PYTHON_LIBRARY",
visibility = ["//visibility:public"],
)
Expand Down
14 changes: 2 additions & 12 deletions mojo/mojo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,7 @@ def _mojo_library_impl(ctx):
tools = [toolchain.symbolizer],
use_default_shell_env = False,
env = {
# "PATH": toolchain.MOJO_CC_PATH,
# "MODULAR_HOME": toolchain.MODULAR_HOME,
# "LIBRARY_PATH": toolchain.MOJO_LIBRARY_PATH,
# "MOJO_PYTHON_LIBRARY": toolchain.MOJO_PYTHON_LIBRARY,
# "LLVM_SYMBOLIZER_PATH": toolchain.symbolizer.path,
# "LD_LIBRARY_PATH": toolchain.MOJO_LIBRARY_PATH,
"LLVM_SYMBOLIZER_PATH": toolchain.symbolizer.path,
},
)

Expand Down Expand Up @@ -199,12 +194,7 @@ def _mojo_binary_impl(ctx):
tools = [toolchain.symbolizer],
use_default_shell_env = False,
env = {
# "MODULAR_HOME": toolchain.MODULAR_HOME,
# "PATH": toolchain.MOJO_CC_PATH,
# "LIBRARY_PATH": toolchain.MOJO_LIBRARY_PATH,
# "LD_LIBRARY_PATH": toolchain.MOJO_LIBRARY_PATH,
# "MOJO_PYTHON_LIBRARY": toolchain.MOJO_PYTHON_LIBRARY,
# "LLVM_SYMBOLIZER_PATH": toolchain.symbolizer.path,
"LLVM_SYMBOLIZER_PATH": toolchain.symbolizer.path,
},
)

Expand Down
4 changes: 2 additions & 2 deletions mojo/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def _mojo_toolchain_impl(ctx):
MODULAR_HOME = ctx.attr.MODULAR_HOME[BuildSettingInfo].value,
MOJO_COMPILER = ctx.attr.MOJO_COMPILER[BuildSettingInfo].value,
MOJO_CC_PATH = ctx.attr.MOJO_CC_PATH[BuildSettingInfo].value,
MOJO_LIBRARY_PATH = ctx.attr.MOJO_LIBRARY_PATH[BuildSettingInfo].value,
LD_LIBRARY_PATH = ctx.attr.LD_LIBRARY_PATH[BuildSettingInfo].value,
MOJO_PYTHON_LIBRARY = ctx.attr.MOJO_PYTHON_LIBRARY[BuildSettingInfo].value,
symbolizer = ctx.executable.symbolizer,
),
Expand All @@ -29,7 +29,7 @@ mojo_toolchain = rule(
doc = "The path to the mojo compiler.",
),
"MOJO_CC_PATH": attr.label(),
"MOJO_LIBRARY_PATH": attr.label(),
"LD_LIBRARY_PATH": attr.label(),
"MOJO_PYTHON_LIBRARY": attr.label(),
"symbolizer": attr.label(
doc = "The `llvm-symbolizer`.",
Expand Down

0 comments on commit a1dcb60

Please sign in to comment.