From eb2a7d74132623b217922ea69a43dc5130febe5f Mon Sep 17 00:00:00 2001 From: Wildan M Date: Thu, 25 Dec 2025 11:02:11 +0700 Subject: [PATCH 1/8] Bootstrap GCC prefix using cookbook --- mk/config.mk | 7 +- mk/prefix.mk | 277 +++++------------- podman/redox-base-containerfile | 1 + recipes/core/relibc/recipe.toml | 8 +- recipes/dev/binutils-gdb/recipe.toml | 22 ++ recipes/dev/gcc13/recipe.toml | 52 +++- .../libs/other => dev}/libtool/recipe.toml | 4 + recipes/libs/libstdcxx-v3/recipe.toml | 12 + src/bin/repo.rs | 2 + src/bin/repo_builder.rs | 28 +- src/config.rs | 7 + src/cook/cook_build.rs | 26 +- src/cook/fs.rs | 25 +- src/cook/package.rs | 9 +- 14 files changed, 239 insertions(+), 241 deletions(-) create mode 100644 recipes/dev/binutils-gdb/recipe.toml rename recipes/{wip/libs/other => dev}/libtool/recipe.toml (82%) diff --git a/mk/config.mk b/mk/config.mk index 4a650dcd5..d6553a0a1 100644 --- a/mk/config.mk +++ b/mk/config.mk @@ -54,11 +54,13 @@ SCCACHE_BUILD?=$(shell [ -f /run/.containerenv ] && echo 1 || echo 0) CONTAINERFILE?=podman/redox-base-containerfile # Per host variables -export NPROC=nproc +NPROC=nproc +SED=sed ifneq ($(PODMAN_BUILD),1) FSTOOLS_IN_PODMAN=0 HOST_TARGET := $(shell env -u RUSTUP_TOOLCHAIN rustc -vV | grep host | cut -d: -f2 | tr -d " ") +HOST_GNU_TARGET := $(shell gcc -dumpmachine) # x86_64 linux hosts have all toolchains ifneq ($(HOST_TARGET),x86_64-unknown-linux-gnu) ifeq ($(ARCH),aarch64) @@ -101,7 +103,8 @@ endif UNAME := $(shell uname) ifeq ($(UNAME),Darwin) FUMOUNT=umount - export NPROC=sysctl -n hw.ncpu + NPROC=sysctl -n hw.ncpu + SED=gsed VB_AUDIO=coreaudio VBM=/Applications/VirtualBox.app/Contents/MacOS/VBoxManage else ifeq ($(UNAME),FreeBSD) diff --git a/mk/prefix.mk b/mk/prefix.mk index c9d085bdd..ebe52f5be 100644 --- a/mk/prefix.mk +++ b/mk/prefix.mk @@ -4,11 +4,13 @@ PREFIX=prefix/$(TARGET) PREFIX_INSTALL=$(PREFIX)/sysroot/ PREFIX_PATH=$(ROOT)/$(PREFIX_INSTALL)/bin -RELIBC_SOURCE=recipes/core/relibc/source +BINUTILS_TARGET=recipes/dev/binutils-gdb/target/$(HOST_TARGET)/$(TARGET) +LIBTOOL_TARGET=recipes/dev/libtool/target/$(HOST_TARGET) +GCC_TARGET=recipes/dev/gcc13/target/$(HOST_TARGET)/$(TARGET) +LIBSTDCXX_TARGET=recipes/libs/libstdcxx-v3/target/$(TARGET)/$(HOST_TARGET) +RELIBC_FREESTANDING_TARGET=recipes/core/relibc/target/$(TARGET)/$(HOST_TARGET) +RELIBC_TARGET=recipes/core/relibc/target/$(TARGET) -BINUTILS_BRANCH=redox-2.43.1 -GCC_BRANCH=redox-13.2.0 -LIBTOOL_VERSION=2.5.4 # official RISC-V support introduced in newer version UPSTREAM_RUSTC_VERSION=2025-11-15 @@ -16,64 +18,27 @@ export PREFIX_RUSTFLAGS=-L $(ROOT)/$(PREFIX_INSTALL)/$(TARGET)/lib export RUSTUP_TOOLCHAIN=$(ROOT)/$(PREFIX_INSTALL) export REDOXER_TOOLCHAIN=$(RUSTUP_TOOLCHAIN) -export CC= -export CXX= - -ifeq ($(TARGET),riscv64gc-unknown-redox) - GCC_ARCH?=--with-arch=rv64gc --with-abi=lp64d -else - GCC_ARCH?= -endif - -# TODO(andypython): Upstream libtool patches to remove the need to locally build libtool. -# Cannot be CI built, i.e. be a part of relibc-install.tar.gz, as the prefix has to be correctly -# set while building. Otherwise aclocal will not be able to find libtool's files. Furthermore, doing -# so would break non-podman builds (not sure if they are still supported though). prefix: $(PREFIX)/sysroot # Update relibc used for compiling and clean all statically linked recipes prefix_clean: | $(FSTOOLS_TAG) - rm -rf $(PREFIX)/relibc $(PREFIX)/sysroot $(REPO_TAG) + rm -rf $(PREFIX)/relibc-install $(PREFIX)/sysroot $(REPO_TAG) $(MAKE) c.base,base-initfs,extrautils,kernel,ion,pkgutils,redoxfs,relibc -PREFIX_STRIP=\ - mkdir -p bin libexec "$(GCC_TARGET)/bin" && \ - find bin libexec "$(GCC_TARGET)/bin" "$(GCC_TARGET)/lib" \ - -type f \ - -exec strip --strip-unneeded {} ';' \ - 2> /dev/null - -$(RELIBC_SOURCE): | $(FSTOOLS_TAG) -ifeq ($(PODMAN_BUILD),1) - $(PODMAN_RUN) make $@ -else - ./target/release/repo fetch relibc - touch $(RELIBC_SOURCE) -endif - -$(PREFIX)/relibc: | $(RELIBC_SOURCE) - mkdir -p "$(@D)" - rm -rf "$@.partial" "$@" - cp -r "$(RELIBC_SOURCE)" "$@.partial" - touch "$@.partial" - mv "$@.partial" "$@" - -$(PREFIX)/relibc-install: $(PREFIX)/relibc | $(PREFIX)/rust-install $(CONTAINER_TAG) +$(PREFIX)/relibc-install: $(PREFIX)/rust-install | $(CONTAINER_TAG) ifeq ($(PODMAN_BUILD),1) $(PODMAN_RUN) make $@ else + @echo "\033[1;36;49mBuilding relibc-install\033[0m" rm -rf "$@.partial" "$@" cp -r "$(PREFIX)/rust-install" "$@.partial" rm -rf "$@.partial/$(TARGET)/include/"* cp -r "$(PREFIX)/rust-install/$(GNU_TARGET)/include/c++" "$@.partial/$(GNU_TARGET)/include/c++" cp -r "$(PREFIX)/rust-install/lib/rustlib/$(HOST_TARGET)/lib/" "$@.partial/lib/rustlib/$(HOST_TARGET)/" - cd "$<" && \ export PATH="$(ROOT)/$@.partial/bin:$$PATH" && \ - export CARGO="env -u CARGO cargo" && \ - $(MAKE) clean && \ - $(MAKE) -j `$(NPROC)` all && \ - $(MAKE) -j `$(NPROC)` install DESTDIR="$(ROOT)/$@.partial/$(GNU_TARGET)" - cd "$@.partial" && $(PREFIX_STRIP) + export CARGO="env -u CARGO cargo" CI=1 && \ + ./target/release/repo cook relibc + cp -r "$(RELIBC_TARGET)/stage/usr/". "$@.partial/$(GNU_TARGET)" touch "$@.partial" mv "$@.partial" "$@" endif @@ -86,60 +51,30 @@ $(PREFIX)/relibc-install.tar.gz: $(PREFIX)/relibc-install --directory="$<" \ . -$(PREFIX)/libtool: | $(CONTAINER_TAG) +# TODO: move this behind PREFIX_BINARY=0 when compiled prefix has it +$(PREFIX)/libtool-install: | $(FSTOOLS_TAG) $(CONTAINER_TAG) ifeq ($(PODMAN_BUILD),1) $(PODMAN_RUN) make $@ else + @echo "\033[1;36;49mBuilding libtool-install\033[0m" rm -rf "$@.partial" "$@" mkdir -p "$@.partial" - - git clone \ - --recurse-submodules \ - --shallow-submodules \ - "https://gitlab.redox-os.org/redox-os/libtool/" \ - --branch "v$(LIBTOOL_VERSION)-redox" \ - --depth 2 \ - "$@.partial" - - touch "$@.partial" - echo $(LIBTOOL_VERSION) > $@.partial/.tarball-version - mv "$@.partial" "$@" -endif - -$(PREFIX)/libtool-build: $(PREFIX)/libtool $(PREFIX)/rust-install $(CONTAINER_TAG) -ifeq ($(PODMAN_BUILD),1) - $(PODMAN_RUN) make $@ -else - rm -rf "$@.partial" "$@" - mkdir -p "$@.partial" - PATH="$(ROOT)/$(PREFIX)/rust-install/bin:$$PATH" && \ - cd "$<" && \ - ./bootstrap \ - --skip-po \ - --force \ - --gnulib-srcdir=./gnulib - PATH="$(ROOT)/$(PREFIX)/rust-install/bin:$$PATH" && \ - cd "$@.partial" && \ - cp -r $(abspath $<)/. ./ && \ - "$(ROOT)/$ anyhow::Result<()> { fs::create_dir_all(repo_path)?; } + // Don't publish host packages + let target_packages = &config + .recipe_list + .iter() + .map(PackageName::new) + .filter(|pkg| pkg.as_ref().is_ok_and(|p| !p.is_host())) + .collect::, _>>()?; + + if target_packages.len() == 0 { + return Ok(()); + } + + // TODO: publish cross target builds? + if std::env::var("COOKBOOK_CROSS_TARGET").is_ok_and(|x| !x.is_empty()) { + return Ok(()); + } + // Runtime dependencies include both `[package.dependencies]` and dynamically // linked packages discovered by auto_deps. // // The following adds the package dependencies of the recipes to the repo as // well. - let (recipe_list, recipe_map) = Package::new_recursive_nonstop( - &config - .recipe_list - .iter() - .map(PackageName::new) - // Don't publish host packages - .filter(|pkg| pkg.as_ref().is_ok_and(|p| !p.is_host())) - .collect::, _>>()?, - WALK_DEPTH, - ); + let (recipe_list, recipe_map) = Package::new_recursive_nonstop(target_packages, WALK_DEPTH); if recipe_list.len() == 0 { // Fail-Safe diff --git a/src/config.rs b/src/config.rs index c8836c6d0..cdcc6bef6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -19,6 +19,8 @@ pub struct CookConfigOpt { /// whether to print verbose logs to certain commands /// build failure still be printed anyway pub verbose: Option, + /// whether to always clean the build directory + pub clean_build: Option, } #[derive(Debug, Default, Clone, Deserialize, PartialEq, Serialize)] @@ -29,6 +31,7 @@ pub struct CookConfig { pub logs: bool, pub nonstop: bool, pub verbose: bool, + pub clean_build: bool, } impl From for CookConfig { @@ -40,6 +43,7 @@ impl From for CookConfig { logs: value.logs.unwrap(), nonstop: value.nonstop.unwrap(), verbose: value.verbose.unwrap(), + clean_build: value.clean_build.unwrap(), } } } @@ -91,6 +95,9 @@ pub fn init_config() { if config.cook_opt.nonstop.is_none() { config.cook_opt.nonstop = Some(extract_env("COOKBOOK_NONSTOP", false)); } + if config.cook_opt.clean_build.is_none() { + config.cook_opt.clean_build = Some(extract_env("COOKBOOK_CLEAN_BUILD", false)); + } if config.mirrors.len() == 0 { // The GNU FTP mirror below is automatically inserted for convenience // You can choose other mirrors by setting it on cookbook.toml diff --git a/src/cook/cook_build.rs b/src/cook/cook_build.rs index 3b7b9255a..1b88de0aa 100644 --- a/src/cook/cook_build.rs +++ b/src/cook/cook_build.rs @@ -174,6 +174,7 @@ pub fn build( recipe: &Recipe, offline_mode: bool, check_source: bool, + clean_build: bool, logger: &PtyOut, ) -> Result<(Vec, BTreeSet), String> { let sysroot_dir = target_dir.join("sysroot"); @@ -276,9 +277,8 @@ pub fn build( create_dir_clean(&stage_dir_tmp)?; // Create build, if it does not exist - //TODO: flag for clean builds where build is wiped out - let build_dir = target_dir.join("build"); - if !build_dir.is_dir() { + let build_dir = get_build_dir(target_dir); + if clean_build || !build_dir.is_dir() { create_dir_clean(&build_dir)?; } @@ -428,15 +428,33 @@ pub fn remove_stage_dir(stage_dir: &PathBuf) -> Result<(), String> { } pub fn get_stage_dirs(features: &Vec, target_dir: &Path) -> Vec { + let mut target_dir = target_dir.to_path_buf(); + if let Some(cross_target) = std::env::var("COOKBOOK_CROSS_TARGET").ok() { + if cross_target != "" { + // TODO: automatically pass COOKBOOK_CROSS_GNU_TARGET? + target_dir = target_dir.join(cross_target) + } + } let mut v = Vec::new(); for f in features { v.push(target_dir.join(format!("stage.{}", f.name))); } // intentionally added last as it contains leftover files from package features - v.push(target_dir.join(format!("stage"))); + v.push(target_dir.join("stage")); v } +pub fn get_build_dir(target_dir: &Path) -> PathBuf { + let mut target_dir = target_dir.to_path_buf(); + if let Some(cross_target) = std::env::var("COOKBOOK_CROSS_TARGET").ok() { + if cross_target != "" { + // TODO: automatically pass COOKBOOK_CROSS_GNU_TARGET? + target_dir = target_dir.join(cross_target) + } + } + target_dir.join("build") +} + fn build_deps_dir( logger: &PtyOut, deps_dir: &PathBuf, diff --git a/src/cook/fs.rs b/src/cook/fs.rs index b32558bf1..a75c8bdab 100644 --- a/src/cook/fs.rs +++ b/src/cook/fs.rs @@ -33,7 +33,8 @@ pub fn create_dir_clean(dir: &Path) -> Result<(), String> { if dir.is_dir() { remove_all(dir)?; } - create_dir(dir) + fs::create_dir_all(dir) + .map_err(|err| format!("failed to create '{}': {}\n{:?}", dir.display(), err, err)) } pub fn create_target_dir(recipe_dir: &Path, target: &'static str) -> Result { @@ -292,9 +293,14 @@ pub fn get_git_head_rev(dir: &PathBuf) -> Result<(String, bool), String> { let head_str = fs::read_to_string(&git_head) .map_err(|e| format!("unable to read {path}: {e}", path = git_head.display()))?; if head_str.starts_with("ref: ") { - let git_ref = dir.join(".git").join(head_str["ref: ".len()..].trim_end()); - let ref_str = fs::read_to_string(&git_ref) - .map_err(|e| format!("unable to read {path}: {e}", path = git_ref.display()))?; + let entry = head_str["ref: ".len()..].trim_end(); + let git_ref = dir.join(".git").join(entry); + let ref_str = if git_ref.is_file() { + fs::read_to_string(&git_ref) + .map_err(|e| format!("unable to read {path}: {e}", path = git_ref.display()))? + } else { + get_git_ref_entry(dir, entry)? + }; Ok((ref_str.trim().to_string(), false)) } else { Ok((head_str.trim().to_string(), true)) @@ -306,12 +312,14 @@ pub fn get_git_tag_rev(dir: &PathBuf, tag: &str) -> Result { if tag.len() == 40 && tag.chars().all(|f| f.is_ascii_hexdigit()) { return Ok(tag.to_string()); } + get_git_ref_entry(dir, &format!("refs/tags/{tag}")) +} +pub fn get_git_ref_entry(dir: &PathBuf, entry: &str) -> Result { let git_refs = dir.join(".git/packed-refs"); let refs_str = fs::read_to_string(&git_refs) .map_err(|e| format!("unable to read {path}: {e}", path = git_refs.display()))?; - let expected_comment_part = format!("refs/tags/{tag}"); for line in refs_str.lines() { - if line.contains(&expected_comment_part) { + if line.contains(entry) { let sha = line .split_whitespace() .next() @@ -321,10 +329,7 @@ pub fn get_git_tag_rev(dir: &PathBuf, tag: &str) -> Result { } } - Err(format!( - "Could not find a rev tag for {}", - expected_comment_part - )) + Err(format!("Could not find a rev for {}", entry)) } /// get commit rev after fetch diff --git a/src/cook/package.rs b/src/cook/package.rs index 3a635377e..81aebdf99 100644 --- a/src/cook/package.rs +++ b/src/cook/package.rs @@ -194,7 +194,14 @@ pub fn package_stage_paths( package: Option<&OptionalPackageRecipe>, target_dir: &Path, ) -> (PathBuf, PathBuf, PathBuf) { - package_name_paths(package, target_dir, "stage") + let mut target_dir = target_dir.to_path_buf(); + if let Some(cross_target) = std::env::var("COOKBOOK_CROSS_TARGET").ok() { + if cross_target != "" { + // TODO: automatically pass COOKBOOK_CROSS_GNU_TARGET? + target_dir = target_dir.join(cross_target) + } + } + package_name_paths(package, &target_dir, "stage") } pub fn package_source_paths( From 0ad7cae812fcdf3745b615f7834a1ecc4275bd7e Mon Sep 17 00:00:00 2001 From: Wildan M Date: Thu, 25 Dec 2025 13:41:25 +0700 Subject: [PATCH 2/8] Further fixes for bootstrap --- mk/prefix.mk | 16 +++++++++------- recipes/core/relibc/recipe.toml | 4 ++-- recipes/libs/libstdcxx-v3/recipe.toml | 14 +++++++------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/mk/prefix.mk b/mk/prefix.mk index ebe52f5be..276634b61 100644 --- a/mk/prefix.mk +++ b/mk/prefix.mk @@ -72,7 +72,7 @@ ifeq ($(PODMAN_BUILD),1) else rm -rf "$@" cp -r "$(PREFIX)/relibc-install/" "$@" - cp -r "$(PREFIX)/libtool-install/". "$@.partial" + cp -r "$(PREFIX)/libtool-install/". "$@" # adapt path for libtoolize $(SED) -i 's|/usr/share|$(ROOT)/$@/share|g' "$@/bin/libtoolize" touch "$@" @@ -124,7 +124,7 @@ ifeq ($(PODMAN_BUILD),1) $(PODMAN_RUN) make $@ else @echo "\033[1;36;49mBuilding gcc-freestanding-install\033[0m" - rm -rf "$@.partial" "$@" $(PREFIX)/relibc-freestanding-install $(PREFIX)/sysroot + rm -rf "$@.partial" "$@" $(PREFIX)/relibc-freestanding-install $(PREFIX)/sysroot mkdir -p "$@.partial" $(PREFIX)/relibc-freestanding-install/$(TARGET)/include export CI=1 PATH="$(ROOT)/$(PREFIX)/binutils-install/bin:$$PATH" \ COOKBOOK_CLEAN_BUILD=true COOKBOOK_CROSS_TARGET=$(TARGET) COOKBOOK_CROSS_GNU_TARGET=$(GNU_TARGET) \ @@ -132,12 +132,13 @@ else ./target/release/repo cook host:gcc13 cp -r "$(GCC_TARGET)/stage/usr/". "$@.partial" cp -r "$(GCC_TARGET)/stage.cxx/usr/". "$@.partial" + cp -r "$(PREFIX)/binutils-install/". "$@.partial" rm -rf $(PREFIX)/relibc-freestanding-install touch "$@.partial" mv "$@.partial" "$@" endif -$(PREFIX)/relibc-freestanding-install: $(PREFIX)/gcc-freestanding-install $(PREFIX)/binutils-install | $(FSTOOLS_TAG) $(CONTAINER_TAG) +$(PREFIX)/relibc-freestanding-install: $(PREFIX)/gcc-freestanding-install | $(FSTOOLS_TAG) $(CONTAINER_TAG) ifeq ($(PODMAN_BUILD),1) $(PODMAN_RUN) make $@ else @@ -145,8 +146,8 @@ else rm -rf "$@.partial" "$@" mkdir -p "$@.partial/$(TARGET)" export CARGO="env -u CARGO -u RUSTUP_TOOLCHAIN cargo" && \ - export PATH="$(ROOT)/$(PREFIX)/gcc-freestanding-install/bin:$(ROOT)/$(PREFIX)/binutils-install/bin:$$PATH" && \ - export CC_$(subst -,_,$(TARGET))="$(GNU_TARGET)-gcc -isystem $(ROOT)/$@.partial/$(GNU_TARGET)/include" && \ + export PATH="$(ROOT)/$(PREFIX)/gcc-freestanding-install/bin:$$PATH" && \ + export CC_$(subst -,_,$(TARGET))="$(GNU_TARGET)-gcc -isystem $(ROOT)/$@.partial/$(GNU_TARGET)/include" LINKFLAGS="" && \ export CI=1 COOKBOOK_CLEAN_BUILD=true COOKBOOK_HOST_SYSROOT=/usr COOKBOOK_CROSS_TARGET=$(HOST_TARGET) && \ ./target/release/repo cook relibc cp -r "$(RELIBC_FREESTANDING_TARGET)/stage/usr/". "$@.partial/$(TARGET)" @@ -154,7 +155,7 @@ else mv "$@.partial" "$@" endif -$(PREFIX)/gcc-install: $(PREFIX)/relibc-freestanding-install $(PREFIX)/binutils-install $(PREFIX)/libtool-install | $(FSTOOLS_TAG) $(CONTAINER_TAG) +$(PREFIX)/gcc-install: $(PREFIX)/relibc-freestanding-install $(PREFIX)/libtool-install | $(FSTOOLS_TAG) $(CONTAINER_TAG) ifeq ($(PODMAN_BUILD),1) $(PODMAN_RUN) make $@ else @@ -167,8 +168,9 @@ else mkdir -p "$@.partial" "$@-build.partial" cp -r "$(PREFIX)/gcc-freestanding-install/". "$@.partial" cp -r "$(PREFIX)/relibc-freestanding-install/". "$@.partial" - cp -r "$(PREFIX)/binutils-install/". "$@.partial" cp -r "$(PREFIX)/libtool-install/". "$@.partial" + @#TODO: how to make this not conflict with libc? + rm -f "$@.partial/lib/gcc/$(GNU_TARGET)/13.2.0/include/limits.h" # libgcc export PATH="$(ROOT)/$@.partial/bin:$$PATH" && \ $(MAKE) -C "$(ROOT)/$(GCC_TARGET)/build" all-target-libgcc && \ diff --git a/recipes/core/relibc/recipe.toml b/recipes/core/relibc/recipe.toml index 938414b5d..046479417 100644 --- a/recipes/core/relibc/recipe.toml +++ b/recipes/core/relibc/recipe.toml @@ -1,5 +1,5 @@ -# [source] -# git = "https://gitlab.redox-os.org/redox-os/relibc.git" +[source] +git = "https://gitlab.redox-os.org/redox-os/relibc.git" [build] template = "custom" diff --git a/recipes/libs/libstdcxx-v3/recipe.toml b/recipes/libs/libstdcxx-v3/recipe.toml index d9b4a145f..892629216 100644 --- a/recipes/libs/libstdcxx-v3/recipe.toml +++ b/recipes/libs/libstdcxx-v3/recipe.toml @@ -3,26 +3,26 @@ same_as = "../../dev/gcc13" [build] template = "custom" -dependencies = [ - "libgmp", - "libmpfr", - "mpc", - "zlib" -] script = """ DYNAMIC_INIT # this results C++ missing nice stuff like mutex # our prefix workaround this by compiling twice -if [ ! -z "${COOKBOOK_CROSS_GNU_TARGET}" ]; then +if [[ -n "$COOKBOOK_CROSS_GNU_TARGET" ]]; then COOKBOOK_STAGE+="/usr" COOKBOOK_CONFIGURE_FLAGS=( --prefix="" --host="${GNU_TARGET}" --disable-hosted-libstdcxx + --with-cross-host="${COOKBOOK_CROSS_GNU_TARGET}" ) fi +COOKBOOK_CONFIGURE_FLAGS+=( + --enable-threads=posix + --enable-libstdcxx-threads +) + CPPINCLUDE="${COOKBOOK_HOST_SYSROOT}/$TARGET/include/c++/13.2.0" export CPPFLAGS+=" -I${CPPINCLUDE} -I${CPPINCLUDE}/$TARGET/bits" COOKBOOK_CONFIGURE="${COOKBOOK_SOURCE}/libstdc++-v3/configure" From 2fe4fdc2fb2a7c0d3f2c64bc0b22e3235aff7a8d Mon Sep 17 00:00:00 2001 From: Wildan M Date: Thu, 25 Dec 2025 16:21:19 +0700 Subject: [PATCH 3/8] Further fixes to make gcc13 compile --- mk/prefix.mk | 2 +- recipes/dev/gcc13/recipe.toml | 7 +++---- recipes/libs/libstdcxx-v3/recipe.toml | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/mk/prefix.mk b/mk/prefix.mk index 276634b61..92fbf5225 100644 --- a/mk/prefix.mk +++ b/mk/prefix.mk @@ -25,7 +25,7 @@ prefix_clean: | $(FSTOOLS_TAG) rm -rf $(PREFIX)/relibc-install $(PREFIX)/sysroot $(REPO_TAG) $(MAKE) c.base,base-initfs,extrautils,kernel,ion,pkgutils,redoxfs,relibc -$(PREFIX)/relibc-install: $(PREFIX)/rust-install | $(CONTAINER_TAG) +$(PREFIX)/relibc-install: $(PREFIX)/rust-install | $(FSTOOLS_TAG) $(CONTAINER_TAG) ifeq ($(PODMAN_BUILD),1) $(PODMAN_RUN) make $@ else diff --git a/recipes/dev/gcc13/recipe.toml b/recipes/dev/gcc13/recipe.toml index 305562d6b..19866f018 100644 --- a/recipes/dev/gcc13/recipe.toml +++ b/recipes/dev/gcc13/recipe.toml @@ -17,7 +17,7 @@ dependencies = [ "zlib" ] script = """ -DYNAMIC_INIT +DYNAMIC_STATIC_INIT CROSS_GNU_TARGET=${COOKBOOK_CROSS_GNU_TARGET:-$GNU_TARGET} if [ "${COOKBOOK_HOST_SYSROOT}" = "/usr" ]; then @@ -27,12 +27,12 @@ COOKBOOK_CONFIGURE_FLAGS=( --prefix="" --host="${GNU_TARGET}" --program-prefix="${CROSS_GNU_TARGET}-" + --with-native-system-header-dir="/include" --with-sysroot ) else COOKBOOK_CONFIGURE_FLAGS+=( - --with-sysroot=/usr - --prefix="/usr" + --with-sysroot=/ ) fi @@ -46,7 +46,6 @@ fi COOKBOOK_CONFIGURE_FLAGS+=( --target="${CROSS_GNU_TARGET}" --with-build-sysroot="${COOKBOOK_CROSS_SYSROOT:-$COOKBOOK_SYSROOT}" - --with-native-system-header-dir="/include" --with-linker-hash-style=gnu --enable-languages=c,c++,lto --enable-initfini-array diff --git a/recipes/libs/libstdcxx-v3/recipe.toml b/recipes/libs/libstdcxx-v3/recipe.toml index 892629216..9499cd8ef 100644 --- a/recipes/libs/libstdcxx-v3/recipe.toml +++ b/recipes/libs/libstdcxx-v3/recipe.toml @@ -4,7 +4,7 @@ same_as = "../../dev/gcc13" [build] template = "custom" script = """ -DYNAMIC_INIT +DYNAMIC_STATIC_INIT # this results C++ missing nice stuff like mutex # our prefix workaround this by compiling twice From 3049ad1e2216a29de147b72d0b195b6b779413d8 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Thu, 25 Dec 2025 16:36:26 +0700 Subject: [PATCH 4/8] Try fix CI --- recipes/dev/libtool/recipe.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/dev/libtool/recipe.toml b/recipes/dev/libtool/recipe.toml index b8d07ec4d..b62946be9 100644 --- a/recipes/dev/libtool/recipe.toml +++ b/recipes/dev/libtool/recipe.toml @@ -12,7 +12,7 @@ DYNAMIC_INIT # libtool saves absolute path to sysroot which contains nothing unset CFLAGS -rsync -av --delete "${COOKBOOK_SOURCE}/" ./ +cp -r "${COOKBOOK_SOURCE}"/. ./ ./bootstrap \ --skip-po \ --force \ From d034e6a381106053c0441aec490dd65c685ecc8e Mon Sep 17 00:00:00 2001 From: Wildan M Date: Fri, 26 Dec 2025 07:18:29 +0700 Subject: [PATCH 5/8] Fixes for other arch like RISC-V --- mk/prefix.mk | 30 ++++++++++++++------------- recipes/dev/gcc13/recipe.toml | 2 ++ recipes/libs/libstdcxx-v3/recipe.toml | 12 ----------- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/mk/prefix.mk b/mk/prefix.mk index 92fbf5225..686d3cccf 100644 --- a/mk/prefix.mk +++ b/mk/prefix.mk @@ -125,10 +125,10 @@ ifeq ($(PODMAN_BUILD),1) else @echo "\033[1;36;49mBuilding gcc-freestanding-install\033[0m" rm -rf "$@.partial" "$@" $(PREFIX)/relibc-freestanding-install $(PREFIX)/sysroot - mkdir -p "$@.partial" $(PREFIX)/relibc-freestanding-install/$(TARGET)/include + mkdir -p "$@.partial" $(PREFIX)/relibc-freestanding-install/$(GNU_TARGET)/include export CI=1 PATH="$(ROOT)/$(PREFIX)/binutils-install/bin:$$PATH" \ COOKBOOK_CLEAN_BUILD=true COOKBOOK_CROSS_TARGET=$(TARGET) COOKBOOK_CROSS_GNU_TARGET=$(GNU_TARGET) \ - COOKBOOK_HOST_SYSROOT=/usr COOKBOOK_CROSS_SYSROOT=$(ROOT)/$(PREFIX)/relibc-freestanding-install/$(TARGET) && \ + COOKBOOK_HOST_SYSROOT=/usr COOKBOOK_CROSS_SYSROOT=$(ROOT)/$(PREFIX)/relibc-freestanding-install/$(GNU_TARGET) && \ ./target/release/repo cook host:gcc13 cp -r "$(GCC_TARGET)/stage/usr/". "$@.partial" cp -r "$(GCC_TARGET)/stage.cxx/usr/". "$@.partial" @@ -144,13 +144,13 @@ ifeq ($(PODMAN_BUILD),1) else @echo "\033[1;36;49mBuilding relibc-freestanding-install\033[0m" rm -rf "$@.partial" "$@" - mkdir -p "$@.partial/$(TARGET)" + mkdir -p "$@.partial" export CARGO="env -u CARGO -u RUSTUP_TOOLCHAIN cargo" && \ export PATH="$(ROOT)/$(PREFIX)/gcc-freestanding-install/bin:$$PATH" && \ export CC_$(subst -,_,$(TARGET))="$(GNU_TARGET)-gcc -isystem $(ROOT)/$@.partial/$(GNU_TARGET)/include" LINKFLAGS="" && \ export CI=1 COOKBOOK_CLEAN_BUILD=true COOKBOOK_HOST_SYSROOT=/usr COOKBOOK_CROSS_TARGET=$(HOST_TARGET) && \ ./target/release/repo cook relibc - cp -r "$(RELIBC_FREESTANDING_TARGET)/stage/usr/". "$@.partial/$(TARGET)" + cp -r "$(RELIBC_FREESTANDING_TARGET)/stage/usr/". "$@.partial/$(GNU_TARGET)" touch "$@.partial" mv "$@.partial" "$@" endif @@ -171,25 +171,27 @@ else cp -r "$(PREFIX)/libtool-install/". "$@.partial" @#TODO: how to make this not conflict with libc? rm -f "$@.partial/lib/gcc/$(GNU_TARGET)/13.2.0/include/limits.h" -# libgcc +# libgcc and bare features of libstdcxx export PATH="$(ROOT)/$@.partial/bin:$$PATH" && \ - $(MAKE) -C "$(ROOT)/$(GCC_TARGET)/build" all-target-libgcc && \ - $(MAKE) -C "$(ROOT)/$(GCC_TARGET)/build" install-target-libgcc DESTDIR="$(ROOT)/$@-build.partial/usr" + $(MAKE) -C "$(ROOT)/$(GCC_TARGET)/build" all-target-libgcc all-target-libstdc++-v3 && \ + $(MAKE) -C "$(ROOT)/$(GCC_TARGET)/build" install-target-libgcc install-target-libstdc++-v3 DESTDIR="$(ROOT)/$@-build.partial/usr" cp -r "$@-build.partial/usr/". "$@.partial" -# libstdcxx, bare features - export PATH="$(ROOT)/$@.partial/bin:$$PATH" && \ - export CI=1 COOKBOOK_CLEAN_BUILD=true "COOKBOOK_HOST_SYSROOT=$(ROOT)/$@.partial" COOKBOOK_CROSS_TARGET=$(HOST_TARGET) COOKBOOK_CROSS_GNU_TARGET=$(HOST_GNU_TARGET) && \ - ./target/release/repo cook libstdcxx-v3 - cp -r "$(LIBSTDCXX_TARGET)/stage/usr/". "$@.partial" -# libstdcxx, full features + @#TODO: in riscv64gc libgcc_s.so is a GNU ld script + rm -f "$@.partial"/$(GNU_TARGET)/lib/libgcc_s.so + ln -s libgcc_s.so.1 "$@.partial"/$(GNU_TARGET)/lib/libgcc_s.so +# fully featured libstdcxx, not supported for targets only supporting static linking +ifneq ($(TARGET),riscv64gc-unknown-redox) +ifneq ($(TARGET),i586-unknown-redox) export PATH="$(ROOT)/$@.partial/bin:$$PATH" && \ export CI=1 COOKBOOK_CLEAN_BUILD=true "COOKBOOK_HOST_SYSROOT=$(ROOT)/$@.partial" COOKBOOK_CROSS_TARGET=$(HOST_TARGET) && \ rm -rf "$(LIBSTDCXX_TARGET)/stage" && ./target/release/repo cook libstdcxx-v3 cp -r "$(LIBSTDCXX_TARGET)/stage/usr/". "$@.partial/$(GNU_TARGET)" +endif +endif rm -rf "$@-build.partial" touch "$@.partial" mv "$@.partial" "$@" -# no longer needed, delete to save disk space +# no longer needed, delete build files to save disk space rm -rf $(BINUTILS_TARGET) $(LIBTOOL_TARGET) $(GCC_TARGET) $(LIBSTDCXX_TARGET) $(RELIBC_FREESTANDING_TARGET) endif diff --git a/recipes/dev/gcc13/recipe.toml b/recipes/dev/gcc13/recipe.toml index 19866f018..4a460b0ad 100644 --- a/recipes/dev/gcc13/recipe.toml +++ b/recipes/dev/gcc13/recipe.toml @@ -28,6 +28,7 @@ COOKBOOK_CONFIGURE_FLAGS=( --host="${GNU_TARGET}" --program-prefix="${CROSS_GNU_TARGET}-" --with-native-system-header-dir="/include" + --disable-hosted-libstdcxx --with-sysroot ) else @@ -55,6 +56,7 @@ COOKBOOK_CONFIGURE_FLAGS+=( --enable-host-shared --enable-threads=posix --enable-frame-pointer + --enable-libstdcxx-threads --with-bugurl="https://gitlab.redox-os.org/redox-os/gcc/-/issues" ) diff --git a/recipes/libs/libstdcxx-v3/recipe.toml b/recipes/libs/libstdcxx-v3/recipe.toml index 9499cd8ef..a0d76ef06 100644 --- a/recipes/libs/libstdcxx-v3/recipe.toml +++ b/recipes/libs/libstdcxx-v3/recipe.toml @@ -6,18 +6,6 @@ template = "custom" script = """ DYNAMIC_STATIC_INIT -# this results C++ missing nice stuff like mutex -# our prefix workaround this by compiling twice -if [[ -n "$COOKBOOK_CROSS_GNU_TARGET" ]]; then -COOKBOOK_STAGE+="/usr" -COOKBOOK_CONFIGURE_FLAGS=( - --prefix="" - --host="${GNU_TARGET}" - --disable-hosted-libstdcxx - --with-cross-host="${COOKBOOK_CROSS_GNU_TARGET}" -) -fi - COOKBOOK_CONFIGURE_FLAGS+=( --enable-threads=posix --enable-libstdcxx-threads From 85047bd2d59d582538cd1783b28811297e9cb844 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Sun, 28 Dec 2025 19:48:58 +0700 Subject: [PATCH 6/8] Add back libstdcx++ la files --- mk/prefix.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mk/prefix.mk b/mk/prefix.mk index 686d3cccf..fa7ead17d 100644 --- a/mk/prefix.mk +++ b/mk/prefix.mk @@ -179,6 +179,9 @@ else @#TODO: in riscv64gc libgcc_s.so is a GNU ld script rm -f "$@.partial"/$(GNU_TARGET)/lib/libgcc_s.so ln -s libgcc_s.so.1 "$@.partial"/$(GNU_TARGET)/lib/libgcc_s.so + @#TODO: generates wrong lib path for libtool + rm -f "$@.partial"/$(GNU_TARGET)/lib/libstdc++.la + rm -f "$@.partial"/$(GNU_TARGET)/lib/libsupc++.la # fully featured libstdcxx, not supported for targets only supporting static linking ifneq ($(TARGET),riscv64gc-unknown-redox) ifneq ($(TARGET),i586-unknown-redox) From bbca5b2386713f8af2d143d103dc1688597874cf Mon Sep 17 00:00:00 2001 From: Wildan M Date: Sun, 28 Dec 2025 19:50:06 +0700 Subject: [PATCH 7/8] Remove HOST_GNU_TARGET --- mk/config.mk | 1 - 1 file changed, 1 deletion(-) diff --git a/mk/config.mk b/mk/config.mk index d6553a0a1..d985c3964 100644 --- a/mk/config.mk +++ b/mk/config.mk @@ -60,7 +60,6 @@ SED=sed ifneq ($(PODMAN_BUILD),1) FSTOOLS_IN_PODMAN=0 HOST_TARGET := $(shell env -u RUSTUP_TOOLCHAIN rustc -vV | grep host | cut -d: -f2 | tr -d " ") -HOST_GNU_TARGET := $(shell gcc -dumpmachine) # x86_64 linux hosts have all toolchains ifneq ($(HOST_TARGET),x86_64-unknown-linux-gnu) ifeq ($(ARCH),aarch64) From c756677427c9b66c383a24a7f0af80ca36c9a091 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Wed, 31 Dec 2025 00:56:12 +0700 Subject: [PATCH 8/8] Flipped arg --- src/cook/cook_build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cook/cook_build.rs b/src/cook/cook_build.rs index 1b88de0aa..a7e537332 100644 --- a/src/cook/cook_build.rs +++ b/src/cook/cook_build.rs @@ -173,8 +173,8 @@ pub fn build( name: &PackageName, recipe: &Recipe, offline_mode: bool, - check_source: bool, clean_build: bool, + check_source: bool, logger: &PtyOut, ) -> Result<(Vec, BTreeSet), String> { let sysroot_dir = target_dir.join("sysroot");