Skip to content
Open
5 changes: 5 additions & 0 deletions local-includes.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ include third_party/build/mtdeps/BUILD.mk
include examples/rubyapps/BUILD.mk

# Require bootstrap mtdeps for dependency generation.
# Exception: when MKDEPS is passed on the command line (as done by
# cosmo_configure.sh --bootstrap with the mkdeps stub), skip the check so the
# bootstrap build that produces build/bootstrap/mtdeps can actually run.
ifeq ($(wildcard build/bootstrap/mtdeps),)
ifneq ($(origin MKDEPS),command line)
$(error Missing build/bootstrap/mtdeps. Run third_party/ruby/cosmo_configure.sh --bootstrap)
endif
else
MKDEPS := build/bootstrap/mtdeps -P ruby_shims/
endif
Expand Down
2 changes: 2 additions & 0 deletions third_party/mexican_toaster/BUILD.mk
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ o/$(MODE)/third_party/mexican_toaster/mtsh.o: \
third_party/mexican_toaster/mtsh/util.inc \
third_party/mexican_toaster/mtsh/tokenize.inc \
third_party/mexican_toaster/mtsh/entry.inc
@$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -c $< -o $@

o/$(MODE)/third_party/mexican_toaster/mtsh.com.dbg: \
$$(THIRD_PARTY_MEXICAN_TOASTER_DEPS) \
Expand Down Expand Up @@ -100,6 +101,7 @@ o/$(MODE)/third_party/mexican_toaster/mtsh_embed.o: \
third_party/mexican_toaster/mtsh/util.inc \
third_party/mexican_toaster/mtsh/tokenize.inc \
third_party/mexican_toaster/mtsh/entry.inc
@$(COMPILE) -AOBJECTIFY.c $(OBJECTIFY.c) -c $< -o $@

o/$(MODE)/third_party/mexican_toaster/caboose.dbg: \
$$(THIRD_PARTY_MEXICAN_TOASTER_DEPS) \
Expand Down
24 changes: 24 additions & 0 deletions third_party/ruby-wip-4.0.0/bin/gem
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env ruby
#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
# See LICENSE.txt for permissions.
#++

require "rubygems"
require "rubygems/gem_runner"
require "rubygems/exceptions"

required_version = Gem::Requirement.new ">= 1.8.7"

unless required_version.satisfied_by? Gem.ruby_version
abort "Expected Ruby version #{required_version}, is #{Gem.ruby_version}"
end

args = ARGV.clone

begin
Gem::GemRunner.new.run args
rescue Gem::SystemExitException => e
exit e.exit_code
end
4 changes: 2 additions & 2 deletions third_party/ruby-wip-4.0.0/cosmo_configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ echo "cosmo_configure: MODE=${MODE} (using $RUBY_BIN)"
exit 1
fi
echo "cosmo_configure: building automate_mkdeps + mtdeps with stub mkdeps"
make -C "$ROOT" MKDEPS="$STUB" -j1 o//third_party/build/mtdeps/automate_mkdeps
make -C "$ROOT" MKDEPS="$STUB" -j1 o//third_party/build/mtdeps/mtdeps
make -C "$ROOT" MKDEPS="$STUB" -j"${BOOTSTRAP_JOBS:-$(nproc)}" o//third_party/build/mtdeps/automate_mkdeps
make -C "$ROOT" MKDEPS="$STUB" -j"${BOOTSTRAP_JOBS:-$(nproc)}" o//third_party/build/mtdeps/mtdeps
mkdir -p "$ROOT/build/bootstrap"
cp "$ROOT/o//third_party/build/mtdeps/automate_mkdeps" "$ROOT/build/bootstrap/automate_mkdeps"
cp "$ROOT/o//third_party/build/mtdeps/mtdeps" "$ROOT/build/bootstrap/mtdeps"
Expand Down
54 changes: 54 additions & 0 deletions third_party/ruby-wip-4.0.0/gen_ruby_shims.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
# Regenerate the ruby_shims/ directory required by mkdeps dependency scanning.
#
# ruby.deps.mk lists entries like ruby_shims/internal+array.h in
# THIRD_PARTY_RUBY_A_INCS. mkdeps (build/bootstrap/mtdeps -P ruby_shims/)
# needs those files to exist so it can read them during Stage 2 resolution
# (see docs/ai/cosmo_ruby/MKDEPS_AUTOMATION_SYSTEM.md). Historically they
# were produced by bin/create_shims.sh, which was never committed; this
# script rebuilds them deterministically from ruby.deps.mk instead.
#
# Mapping: strip "ruby_shims/", replace '+' with '/', then resolve against
# 1. repo root (entries like third_party+ruby+include+ruby.h)
# 2. third_party/ruby/ (entries like internal+array.h)
# Each shim is a one-line include of the resolved file so mkdeps picks up
# the real header's transitive dependencies. Unresolvable entries (e.g.
# generated files that don't exist yet) become empty shims, which merely
# weakens dependency tracking for those files.
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
DEPS_MK="$ROOT/third_party/ruby/ruby.deps.mk"
OUT="$ROOT/ruby_shims"

mkdir -p "$OUT"

missing=0
total=0
while IFS= read -r entry; do
total=$((total + 1))
name="${entry#ruby_shims/}"
real="${name//+//}"
shim="$OUT/$name"
resolved=""
for base in "" "third_party/ruby/" "third_party/ruby/include/"; do
if [ -f "$ROOT/$base$real" ]; then
resolved="$base$real"
break
fi
done
if [ -z "$resolved" ]; then
# Fall back to locating the header anywhere in the ruby tree
# (covers -I'd subdirs like enc/, enc/trans/, prism/, .ext includes).
resolved="$(cd "$ROOT" && find third_party/ruby/ -type f -path "*/$real" 2>/dev/null | sort | head -n1 || true)"
fi
if [ -n "$resolved" ]; then
printf '#include "%s"\n' "$resolved" > "$shim"
else
: > "$shim"
missing=$((missing + 1))
echo "gen_ruby_shims: no source found for $entry (created empty shim)" >&2
fi
done < <(grep -o 'ruby_shims/[^ \\]*' "$DEPS_MK" | sort -u)

echo "gen_ruby_shims: wrote $total shims to $OUT ($missing empty)"
2 changes: 1 addition & 1 deletion third_party/ruby-wip-4.0.0/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ RBIMPL_WARNING_POP()
// Not sure why effective even after popped.
#endif

#include "/home/groobiest/Code/jart/cosmopolitan/o/third_party/ruby/generated/parse.h"
#include "third_party/ruby/parse.h"

#define NO_LEX_CTXT (struct lex_context){0}

Expand Down
26 changes: 18 additions & 8 deletions third_party/ruby-wip-4.0.0/ruby.codegen.mk
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ THIRD_PARTY_RUBY_GENERATED += $(RUBY_RBCONFIG_GEN)
RUBY_RBCONFIG_PATCH := $(RUBY_PATCHDIR)/rbconfig.rb.diff

$(RUBY_RBCONFIG_PATCH): $(RUBY_RBCONFIG_GEN) $(RUBY_RBCONFIG_SOURCE) | $(RUBY_PATCHDIR)
@# TODO: Fix this recipe - cocmd doesn't handle complex && || chains with redirects properly
@# Original: cmp -s $(word 2,$^) $(word 1,$^) && rm -f $@ || diff -u $(word 2,$^) $(word 1,$^) > $@ || true
# TODO: Fix this recipe - cocmd doesn't handle complex && || chains with redirects properly
# Original: cmp -s $(word 2,$^) $(word 1,$^) && rm -f $@ || diff -u $(word 2,$^) $(word 1,$^) > $@ || true
@touch $@

THIRD_PARTY_RUBY_PATCHES += $(RUBY_RBCONFIG_PATCH)
Expand All @@ -123,7 +123,13 @@ THIRD_PARTY_RUBY_GENERATED += $(RUBY_MANIFEST)
################################################################################
# config.h - copy reference config.h to generated directory

$(RUBY_GENDIR)/config.h: docs/reference/_ext_config_ruby_orig_3_4_7.h $(RUBY_MANIFEST) | $(RUBY_GENDIR)
# The original recipe copied docs/reference/_ext_config_ruby_orig_3_4_7.h
# (the pristine config.h from the author's ruby-under-cosmocc configure run),
# but that file was never committed to the repository. Fall back to the
# committed cosmo config.h: the generated/config.h chain only feeds
# comparison/manifest artifacts (generated rbconfig.rb, enc.mk, exts.mk are
# "comparison only"), so the practical effect is empty reference diffs.
$(RUBY_GENDIR)/config.h: third_party/ruby/include/ruby/config.h $(RUBY_MANIFEST) | $(RUBY_GENDIR)
@cp $< $@
@$(RUBY_ENV) $(HOST_RUBY) --disable=gems $(RUBY_ADD_TO_MANIFEST) $(RUBY_MANIFEST) config.h third_party/ruby/include/ruby/config.h

Expand Down Expand Up @@ -236,7 +242,11 @@ THIRD_PARTY_RUBY_PATCHES += $(RUBY_ENCDB_PATCH)
RUBY_TRANSDB_GEN := $(RUBY_GENDIR)/transdb.h


$(RUBY_TRANSDB_GEN): $(RUBY_TOOLDIR)/generic_erb.rb $(RUBY_SRCDIR)/template/transdb.h.tmpl | $(RUBY_GENDIR)
# Order-only dependency on encdb.h: both recipes call ruby_prepare_encdir,
# which rm -rf's and recreates the shared $(RUBY_ENC_TMPDIR). Running them
# concurrently under make -jN makes one recipe delete enc sources while the
# other is still scanning them (ENC_REPLICATE "not defined yet" failures).
$(RUBY_TRANSDB_GEN): $(RUBY_TOOLDIR)/generic_erb.rb $(RUBY_SRCDIR)/template/transdb.h.tmpl | $(RUBY_GENDIR) $(RUBY_ENCDB_GEN)
$(call ruby_prepare_encdir)
@cd $(RUBY_GENDIR) && $(HOST_RUBY) --disable=gems $(abspath $(RUBY_TOOLDIR))/generic_erb.rb -c -o $(abspath $@) $(abspath $(RUBY_SRCDIR)/template/transdb.h.tmpl) $(abspath $(RUBY_TRANS_TMPDIR))
@$(RUBY_ENV) $(HOST_RUBY) --disable=gems $(RUBY_ADD_TO_MANIFEST) $(RUBY_MANIFEST) transdb.h third_party/ruby/enc/transdb.h
Expand Down Expand Up @@ -264,7 +274,7 @@ THIRD_PARTY_RUBY_GENERATED += $(RUBY_PROBES_GEN)
RUBY_PROBES_PATCH := $(RUBY_PATCHDIR)/probes.h.diff

$(RUBY_PROBES_PATCH): $(RUBY_PROBES_GEN) | $(RUBY_PATCHDIR)
@# probes.h is generated at build time in MRI; keep empty patch as sentinel
# probes.h is generated at build time in MRI; keep empty patch as sentinel
@touch $@

THIRD_PARTY_RUBY_PATCHES += $(RUBY_PROBES_PATCH)
Expand All @@ -289,7 +299,7 @@ THIRD_PARTY_RUBY_GENERATED += $(RUBY_ENCMK_GEN)
RUBY_ENCMK_PATCH := $(RUBY_PATCHDIR)/enc.mk.diff

$(RUBY_ENCMK_PATCH): $(RUBY_ENCMK_GEN) | $(RUBY_PATCHDIR)
@# enc.mk is generated at build time in MRI; keep empty patch as sentinel
# enc.mk is generated at build time in MRI; keep empty patch as sentinel
@touch $@

THIRD_PARTY_RUBY_PATCHES += $(RUBY_ENCMK_PATCH)
Expand All @@ -314,7 +324,7 @@ THIRD_PARTY_RUBY_GENERATED += $(RUBY_EXT_CONFIGURE_GEN)
RUBY_EXT_CONFIGURE_PATCH := $(RUBY_PATCHDIR)/ext-configure-ext.mk.diff

$(RUBY_EXT_CONFIGURE_PATCH): $(RUBY_EXT_CONFIGURE_GEN) | $(RUBY_PATCHDIR)
@# ext/configure-ext.mk is generated at build time in MRI; keep empty patch as sentinel
# ext/configure-ext.mk is generated at build time in MRI; keep empty patch as sentinel
@touch $@

THIRD_PARTY_RUBY_PATCHES += $(RUBY_EXT_CONFIGURE_PATCH)
Expand All @@ -337,7 +347,7 @@ THIRD_PARTY_RUBY_GENERATED += $(RUBY_EXTSMK_GEN)
RUBY_EXTSMK_PATCH := $(RUBY_PATCHDIR)/exts.mk.diff

$(RUBY_EXTSMK_PATCH): $(RUBY_EXTSMK_GEN) | $(RUBY_PATCHDIR)
@# exts.mk is generated at build time in MRI; keep empty patch as sentinel
# exts.mk is generated at build time in MRI; keep empty patch as sentinel
@touch $@

THIRD_PARTY_RUBY_PATCHES += $(RUBY_EXTSMK_PATCH)
Expand Down
2 changes: 1 addition & 1 deletion third_party/ruby-wip-4.0.0/yjit/BUILD.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ endif

ifeq ($(RUBY_YJIT_ENABLED),1)

CARGO := $(shell command -v cargo 2>/dev/null)
CARGO ?= $(shell command -v cargo 2>/dev/null)

# Track Rust source files for dependency detection
YJIT_RUST_SRCS := $(wildcard \
Expand Down
9 changes: 9 additions & 0 deletions tool/build/lib/BUILD.mk
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ TOOL_BUILD_LIB_BINS = \
$(TOOL_BUILD_LIB_COMS) \
$(TOOL_BUILD_LIB_COMS:%=%.dbg)

$(TOOL_BUILD_LIB_A): \
tool/build/lib/ \
$(TOOL_BUILD_LIB_A).pkg \
$(TOOL_BUILD_LIB_A_OBJS)

$(TOOL_BUILD_LIB_A).pkg: \
$(TOOL_BUILD_LIB_A_OBJS) \
$(foreach x,$(TOOL_BUILD_LIB_A_DIRECTDEPS),$($(x)_A).pkg)

ifeq ($(ARCH), x86_64)
o/$(MODE)/tool/build/lib/ssefloat.o: private \
TARGET_ARCH += \
Expand Down
Loading