pijul nest
guest [sign in]

Bootstrapped Rust

pmeunier
Aug 16, 2025, 3:19 PM
YEPZUQBDMT75FZUFBNGRJJEXERNI6QJ64MVX3G23XHLP4QADZOTQC

Dependencies

  • [2] LIMIMBOU Bootstrapping the Rust part
  • [3] LIUJQXB7 Allow merging two packages based on regular expressions of their name
  • [4] 6BIW5YDC Rust builder: compiling the crates
  • [5] R7J4254Z Reorganisation of the frontend
  • [6] LQBZJUGC Adding a basic Rust builder
  • [7] LTB4YNHF Rust compilation works!
  • [8] UWQB743K First working shell (with ocaml code)

Change contents

  • replacement in elpe/lib/rust/rust.ml at line 188
    [2.18932][2.18932:18985]()
    ~dependencies ~features ~opt_level ~is_top_level =
    [2.18932]
    [2.18985]
    ~dependencies ~features ~opt_level ~is_top_level ~extra_crate_dependencies =
  • edit in elpe/lib/rust/rust.ml at line 199
    [3.2503]
    [2.19201]
    method description =
    try package |> member "description" |> to_string with _ -> ""
  • edit in elpe/lib/rust/rust.ml at line 206
    [2.19333]
    [3.3284]
    method lib_name =
    try
    Some
    (List.find
    (fun x ->
    let kind = x |> member "kind" |> to_list |> filter_string in
    kind = [ "lib" ] || kind = [ "proc-macro" ])
    self#targets
    |> member "name" |> to_string)
    with Not_found -> None
  • edit in elpe/lib/rust/rust.ml at line 239
    [2.19756]
    [2.19756]
    export CC_ENABLE_DEBUG_OUTPUT=1
    export CC=$(command -v clang)
  • edit in elpe/lib/rust/rust.ml at line 243
    [2.19858]
    [2.19858]
    echo "sourcing env"
  • replacement in elpe/lib/rust/rust.ml at line 304
    [2.20494][2.20494:20523]()
    let dependencies_str =
    [2.20494]
    [2.20523]
    (* rustc wants a single (or few) `-L dependency=` flag, else it
    seems to ignore some of them. That's why we copy deps and
    transitive deps to target/deps. *)
    let dependencies_str, target_deps =
  • replacement in elpe/lib/rust/rust.ml at line 309
    [2.20546][2.20546:20891]()
    (fun acc (rename, name, h, is_proc_macro, b) ->
    acc ^ " --extern " ^ underscorize rename ^ "=" ^ List.hd b.destdir
    ^ "/lib/lib" ^ underscorize name ^ "-" ^ h
    ^
    if is_proc_macro then ".so"
    else if kind = "lib" then ".rmeta"
    else ".rlib")
    "" dependencies
    [2.20546]
    [2.20891]
    (fun (acc_extern, acc_ln) (rename, lib_name, h, is_proc_macro, b) ->
    let acc_extern =
    acc_extern ^ " --extern " ^ underscorize rename
    ^ "=target/deps/lib" ^ underscorize lib_name ^ "-" ^ h
    ^ if is_proc_macro then ".so" else ".rlib"
    in
    let acc_ln =
    acc_ln ^ "ln -sf " ^ List.hd b.destdir ^ "/lib/* target/deps\n"
    in
    (acc_extern, acc_ln))
    ("", "mkdir -p target/deps\n")
    dependencies
  • replacement in elpe/lib/rust/rust.ml at line 322
    [2.20900][2.20900:20930]()
    let dependencies_str =
    [2.20900]
    [2.20930]
    let target_deps =
  • replacement in elpe/lib/rust/rust.ml at line 324
    [2.20951][2.20951:21082]()
    (fun _ v acc -> acc ^ " -L dependency=" ^ List.hd v.destdir ^ "/lib")
    transitive_dependencies dependencies_str
    [2.20951]
    [3.4833]
    (fun _ v acc ->
    acc ^ "ln -sf " ^ List.hd v.destdir ^ "/lib/* target/deps\n")
    transitive_dependencies target_deps
  • edit in elpe/lib/rust/rust.ml at line 329
    [2.21143]
    [3.4842]
  • edit in elpe/lib/rust/rust.ml at line 331
    [3.4869]
    [3.4203]
    let local =
    match self#lib_name with
    | Some l ->
    "--extern " ^ underscorize l ^ "=$DESTDIR/lib/lib"
    ^ underscorize l ^ "-" ^ self#hash ^ ".rlib"
    | None -> ""
    in
  • edit in elpe/lib/rust/rust.ml at line 341
    [2.21178]
    [2.21178]
    set -xe
  • replacement in elpe/lib/rust/rust.ml at line 343
    [2.21201][2.21201:21489]()
    set -x
    rustc --crate-name %{under} %{edition} %{src_path} %{target} --crate-type bin -C linker=gcc $RUSTC_FLAGS %{features_args} -C metadata=%{hash} --out-dir %{out} %{dependencies_str} -L dependency=../lib --cap-lints allow
    { set +x; } 2>/dev/null
    [2.21201]
    [2.21489]
    mkdir -p target %{out} $DESTDIR
    touch target/rustc.opt
    RUSTC_FLAGS=$(cat target/rustc.opt)
    find $DESTDIR
    %{target_deps}
    rustc --crate-name %{under} %{edition} %{src_path} %{target} --crate-type bin --emit=link -C linker=gcc $RUSTC_FLAGS %{features_args} -C metadata=%{hash}-bin --out-dir %{out} %{dependencies_str} %{local} -L dependency=target/deps --cap-lints allow
  • edit in elpe/lib/rust/rust.ml at line 354
    [2.21541]
    [2.21541]
    set -xe
  • replacement in elpe/lib/rust/rust.ml at line 356
    [2.21564][2.21564:22049]()
    set -x
    rustc --crate-name %{under} %{edition} %{src_path} --crate-type %{kind} %{target} --emit=dep-info,metadata,link -C linker=gcc -C embed-bitcode=no -C debuginfo=2 $RUSTC_FLAGS %{if kind = "proc-macro" then " -C prefer-dynamic" else ""} %{features_args} -C metadata=%{hash} --out-dir %{out} -C extra-filename=-%{hash} %{dependencies_str} %{if kind = "proc-macro" then " --extern proc_macro" else ""} --cap-lints allow
    { set +x; } 2>/dev/null
    [2.21564]
    [2.22049]
    mkdir -p target %{out}
    touch target/rustc.opt
    RUSTC_FLAGS=$(cat target/rustc.opt)
    %{target_deps}
    rustc --crate-name %{under} %{edition} %{src_path} --crate-type %{kind} %{target} --emit=link -C linker=gcc -C embed-bitcode=no -C debuginfo=2 $RUSTC_FLAGS %{if kind = "proc-macro" then " -C prefer-dynamic" else ""} %{features_args} -C metadata=%{hash} --out-dir %{out} -C extra-filename=-%{hash} %{dependencies_str} %{if kind = "proc-macro" then " --extern proc_macro" else ""} -L dependency=target/deps --cap-lints allow
  • replacement in elpe/lib/rust/rust.ml at line 380
    [2.22573][2.22573:22613]()
    Hashtbl.add h d#name d;
    [2.22573]
    [2.22613]
    Hashtbl.add h d#hash d;
  • edit in elpe/lib/rust/rust.ml at line 414
    [2.23292]
    [2.23292]
    let x_lib_name = Option.get x#lib_name in
  • edit in elpe/lib/rust/rust.ml at line 426
    [2.23804]
    [2.23804]
  • replacement in elpe/lib/rust/rust.ml at line 448
    [2.24645][2.24645:24714]()
    r := (name, x_name, x_hash, is_proc_macro, b) :: !r;
    [2.24645]
    [2.24714]
    r := (name, x_lib_name, x_hash, is_proc_macro, b) :: !r;
  • edit in elpe/lib/rust/rust.ml at line 464
    [3.7284]
    [2.24989]
    method extra_deps =
    List.fold_left
    (fun acc dep ->
    let* acc = acc in
    let* extra = dep#extra_deps in
    Lwt.return (extra @ acc))
    (Lwt.return (extra_crate_dependencies self#name self#version))
    dependencies
  • edit in elpe/lib/rust/rust.ml at line 474
    [2.25016]
    [2.25016]
    let* extra = self#extra_deps in
  • edit in elpe/lib/rust/rust.ml at line 480
    [2.25125]
    [2.25125]
    ubuntu "clang";
    ubuntu "libc6-dev";
  • edit in elpe/lib/rust/rust.ml at line 484
    [2.25177]
    [2.25177]
    ubuntu "findutils";
  • replacement in elpe/lib/rust/rust.ml at line 487
    [2.25203][2.25203:25262]()
    @ extra_crate_dependencies self#name self#version)
    [2.25203]
    [3.7349]
    @ extra)
  • replacement in elpe/lib/rust/rust.ml at line 493
    [3.7481][2.25263:25336]()
    ref ("mkdir -p target/build-" ^ hash ^ "\nexport RUSTC=rustc\n")
    [3.7481]
    [3.7562]
    ref
    ("mkdir -p target/build-" ^ hash
    ^ "\nexport RUSTC=rustc\ntouch target/rustc.opt\n")
  • edit in elpe/lib/rust/rust.ml at line 503
    [3.7756]
    [3.7756]
    let links =
    try Some (package |> member "links" |> to_string)
    with Not_found | Yojson.Basic.Util.Type_error _ -> None
    in
  • edit in elpe/lib/rust/rust.ml at line 512
    [2.25455]
    [3.7793]
    let description =
    Str.global_replace
    (Str.regexp "\"\\|`\\|\\$\\|\\")
    "\\\\\\0" self#description
    in
  • replacement in elpe/lib/rust/rust.ml at line 521
    [2.25505][2.25505:25547]()
    {|export OUT_DIR=$DESTDIR/lib
    [2.25505]
    [2.25547]
    {|
    export OUT_DIR=$DESTDIR/lib
    export CC_ENABLE_DEBUG_OUTPUT=1
  • edit in elpe/lib/rust/rust.ml at line 526
    [2.25643]
    [2.25643]
    export CARGO_PKG_DESCRIPTION="%{description}"
  • replacement in elpe/lib/rust/rust.ml at line 530
    [2.25805][2.25805:25880]()
    export CARGO_PKG_VERSION_PATCH=%{Option.value v4 ~default:""}
    [2.25805]
    [2.25880]
    export CARGO_PKG_VERSION_PRE=%{Option.value v4 ~default:""}
    export CARGO_MANIFEST_DIR=$(pwd)/%{name}-%{version}
    export CARGO_MANIFEST_LINKS=%{Option.value links ~default: ""}
  • edit in elpe/lib/rust/rust.ml at line 576
    [2.27052]
    [2.27052]
    echo Running build script for %{name}-%{version}
  • replacement in elpe/lib/rust/rust.ml at line 604
    [2.27418][2.27418:27492]()
    d.transitive_dependencies d.dependencies "$OUT_DIR"
    [2.27418]
    [3.9776]
    d.transitive_dependencies d.dependencies "$DESTDIR/lib"
  • replacement in elpe/lib/rust/rust.ml at line 611
    [2.27633][2.27633:27740]()
    d.transitive_dependencies d.dependencies
    "$OUT_DIR/../bin"
    [2.27633]
    [2.27740]
    d.transitive_dependencies d.dependencies "$DESTDIR/bin"
  • replacement in elpe/lib/rust/rust.ml at line 655
    [2.28847][2.28847:28882]()
    ?(host = !Platform.host) src =
    [2.28847]
    [3.5346]
    ?(host = !Platform.host)
    ?(extra_crate_dependencies = extra_crate_dependencies) src =
  • replacement in elpe/lib/rust/rust.ml at line 705
    [3.7236][2.29085:29200]()
    let is_top_level = List.exists (fun w -> w = name) workspace_members in
    let cc = (cc :> derivation) in
    [3.7236]
    [3.7237]
    let is_top_level = List.exists (fun w -> w = id) workspace_members in
    let cc = (cc Clang :> derivation) in
  • replacement in elpe/lib/rust/rust.ml at line 710
    [2.29274][2.29274:29337]()
    ~dependencies ~features ~opt_level:"3" ~is_top_level
    [2.29274]
    [3.4792]
    ~extra_crate_dependencies ~dependencies ~features ~opt_level:"3"
    ~is_top_level
  • replacement in elpe/lib/rust/run_build_script.sh at line 2
    [2.29517][2.29517:29628]()
    eval $(echo $cargo | sed -ne 's/cargo:rustc-link-arg=\(.*\)/RUSTC_FLAGS="-C link_arg=\1 $RUSTC_FLAGS"/p')
    [2.29517]
    [2.29628]
    echo $cargo # | grep -v "^\(#\|cargo:\)"
    echo $cargo | sed -ne 's/cargo:rustc-link-arg=\(.*\)/-C link_arg=\1/p' >> target/rustc.opt
  • replacement in elpe/lib/rust/run_build_script.sh at line 5
    [2.29629][2.29629:29729]()
    eval $(echo $cargo | sed -ne 's/cargo:rustc-link-lib=\(.*\)/RUSTC_FLAGS="-l\1 $RUSTC_FLAGS"/p')
    [2.29629]
    [2.29729]
    echo $cargo | sed -ne 's/cargo:rustc-link-lib=\(.*\)/-l \1/p' >> target/rustc.opt
  • replacement in elpe/lib/rust/run_build_script.sh at line 7
    [2.29730][2.29730:29833]()
    eval $(echo $cargo | sed -ne 's/cargo:rustc-link-search=\(.*\)/RUSTC_FLAGS="-L\1 $RUSTC_FLAGS"/p')
    [2.29730]
    [2.29833]
    echo $cargo | sed -ne 's/cargo:rustc-link-search=\(.*\)/-L \1/p' >> target/rustc.opt
  • replacement in elpe/lib/rust/run_build_script.sh at line 9
    [2.29834][2.29834:29933]()
    eval $(echo $cargo | sed -ne "s/cargo:rustc-cfg=\(.*\)/RUSTC_FLAGS='--cfg \1 $RUSTC_FLAGS'/p")
    [2.29834]
    [2.29933]
    echo $cargo | sed -ne 's/cargo:rustc-cfg=\(.*\)/--cfg \1/p' >> target/rustc.opt
  • replacement in elpe/lib/rust/run_build_script.sh at line 11
    [2.29934][2.29934:30029]()
    eval $(echo $cargo | sed -ne 's/cargo:rustc-flags=\(.*\)/RUSTC_FLAGS="\1 $RUSTC_FLAGS"/p')
    [2.29934]
    [2.30029]
    echo $cargo | sed -ne 's/cargo:rustc-flags=\(.*\)/\1/p' >> target/rustc.opt
  • replacement in elpe/lib/dune at line 7
    [2.36392][2.36392:36439]()
    (preprocessor_deps (file run_build_script.sh))
    [2.36392]
    [2.36439]
    (preprocessor_deps (file rust/run_build_script.sh))
  • replacement in elpe/lib/derivation.ml at line 76
    [3.16526][3.16526:16587]()
    let link_extra = [ ("libstd-rust-.*-dev", "libstd-rust.*") ]
    [3.16526]
    [2.38260]
    let link_extra =
    [ ("libstd-rust-.*-dev", "libstd-rust.*"); ("clang", "clang-.*") ]
  • replacement in elpe/lib/derivation.ml at line 150
    [3.10575][3.10575:10856](),[3.10856][2.40576:40623](),[2.40623][3.10894:11695](),[3.10894][3.10894:11695]()
    let c =
    match !backend_conn with
    | None -> failwith "no conn"
    | Some c -> c
    in
    let* index =
    Lwt_list.map_p
    (fun repository ->
    let arch =
    match platform.arch with
    | Amd64 -> Elpegrpc.Elpe.Arch.Amd64
    | Aarch64 -> Elpegrpc.Elpe.Arch.Aarch64
    in
    let* res = ubuntu_release c ~release ~arch ~repository in
    let res, _ = Result.get_ok res in
    match res with
    | `Ok r -> Lwt.return r.destdir
    | `Error e -> raise (DerivationError e)
    | _ -> assert false)
    [ "main"; "universe" ]
    in
    let index = List.concat index in
    let* res = ubuntu_package c ~index ~name in
    let r = Result.get_ok res in
    let x = { destdir = r.destdir; paths = r.paths } in
    cached_build := Some x;
    Lwt.return x)
    [3.10575]
    [3.4112]
    match !cached_build with
    | Some x -> Lwt.return x
    | None ->
    let c =
    match !backend_conn with
    | None -> failwith "no conn"
    | Some c -> c
    in
    let* index =
    Lwt_list.map_p
    (fun repository ->
    let arch =
    match platform.arch with
    | Amd64 -> Elpegrpc.Elpe.Arch.Amd64
    | Aarch64 -> Elpegrpc.Elpe.Arch.Aarch64
    in
    let* res =
    ubuntu_release c ~release ~arch ~repository
    in
    let res, _ = Result.get_ok res in
    match res with
    | `Ok r -> Lwt.return r.destdir
    | `Error e -> raise (DerivationError e)
    | _ -> assert false)
    [ "main"; "universe" ]
    in
    let index = List.concat index in
    let* res = ubuntu_package c ~index ~name in
    let r = Result.get_ok res in
    let x = { destdir = r.destdir; paths = r.paths } in
    cached_build := Some x;
    Lwt.return x)
  • replacement in elpe/lib/derivation.ml at line 429
    [2.41008][2.41008:41017]()
    let cc =
    [2.41008]
    [2.41017]
    type cc = Gcc | Clang
    let cc x =
    let x = match x with Gcc -> "gcc" | Clang -> "clang" in
  • replacement in elpe/lib/derivation.ml at line 436
    [2.41083][2.41083:41158]()
    method! build_inputs = Lwt.return [ ubuntu "coreutils"; ubuntu "gcc" ]
    [2.41083]
    [2.41158]
    method! build_inputs = Lwt.return [ ubuntu "coreutils"; ubuntu x ]
  • replacement in elpe/lib/derivation.ml at line 440
    [2.41226][2.41226:41310]()
    let* gcc = (ubuntu "gcc")#build in
    List.iter self#add_path gcc.destdir;
    [2.41226]
    [2.41310]
    let* cc = (ubuntu x)#build in
    List.iter self#add_path cc.destdir;
  • replacement in elpe/lib/derivation.ml at line 443
    [2.41327][2.41327:41439]()
    ("mkdir -p $DESTDIR/usr/bin; ln -s " ^ List.hd gcc.destdir
    ^ "/usr/bin/gcc $DESTDIR/usr/bin/cc")
    [2.41327]
    [2.41439]
    ("mkdir -p $DESTDIR/usr/bin; ln -s " ^ List.hd cc.destdir ^ "/usr/bin/"
    ^ x ^ " $DESTDIR/usr/bin/cc")