Skip to content

Commit

Permalink
dmd.mars: Add method to predefine FreeBSD_12 at compile-time.
Browse files Browse the repository at this point in the history
This allows to statically set which version of FreeBSD to compile for
using DFLAGS, choices are FreeBSD 10, 11 or 12. If unset, the default is
to use the same version as the host, or fallback to version 11 if
compiling on a different host, or using an old D compiler to build DMD.

To be decided is whether there should be a dynamic way of detecting the
FreeBSD OS version as well, such as by using getosreldate().
  • Loading branch information
ibuclaw committed Nov 19, 2020
1 parent 79413ab commit 9c8b709
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ task:
timeout_in: 60m
environment:
OS_NAME: freebsd
CI_DFLAGS: -version=TARGET_FREEBSD12
install_bash_script: pkg install -y bash
<< : *COMMON_STEPS_TEMPLATE

Expand All @@ -84,5 +85,6 @@ task:
environment:
OS_NAME: freebsd
HOST_DC: dmd-2.079.0
CI_DFLAGS: -version=TARGET_FREEBSD11
install_bash_script: pkg install -y bash
<< : *COMMON_STEPS_TEMPLATE
4 changes: 3 additions & 1 deletion ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ if [ -z ${FULL_BUILD+x} ] ; then echo "Variable 'FULL_BUILD' needs to be set.";
if [ -z ${MODEL+x} ] ; then echo "Variable 'MODEL' needs to be set."; exit 1; fi
# HOST_DC: dmd[-<version>]|ldc[-<version>]|gdmd-<version>
if [ -z ${HOST_DC+x} ] ; then echo "Variable 'HOST_DC' needs to be set."; exit 1; fi
# CI_DFLAGS: Optional flags to pass to the build
if [ -z ${CI_DFLAGS+x} ] ; then CI_DFLAGS=""; fi

CURL_USER_AGENT="DMD-CI $(curl --version | head -n 1)"
build_path=generated/$OS_NAME/release/$MODEL
Expand Down Expand Up @@ -50,7 +52,7 @@ clone() {
# build dmd, druntime, phobos
build() {
source ~/dlang/*/activate # activate host compiler, incl. setting `DMD`
make -j$N -C src -f posix.mak MODEL=$MODEL HOST_DMD=$DMD ENABLE_RELEASE=1 ENABLE_WARNINGS=1 all
make -j$N -C src -f posix.mak MODEL=$MODEL HOST_DMD=$DMD DFLAGS="$CI_DFLAGS" ENABLE_RELEASE=1 ENABLE_WARNINGS=1 all
make -j$N -C ../druntime -f posix.mak MODEL=$MODEL
make -j$N -C ../phobos -f posix.mak MODEL=$MODEL
deactivate # deactivate host compiler
Expand Down
10 changes: 4 additions & 6 deletions src/dmd/mars.d
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,6 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params)

setTarget(params);

// Predefined version identifiers
addDefaultVersionIdentifiers(params);

setDefaultLibrary();

// Initialization
Expand All @@ -388,6 +385,9 @@ private int tryMain(size_t argc, const(char)** argv, ref Param params)
import dmd.root.ctfloat : CTFloat;
CTFloat.initialize();

// Predefined version identifiers
addDefaultVersionIdentifiers(params);

if (params.verbose)
{
stdout.printPredefinedVersions();
Expand Down Expand Up @@ -1241,9 +1241,7 @@ void addDefaultVersionIdentifiers(const ref Param params)
{
VersionCondition.addPredefinedGlobalIdent("Posix");
VersionCondition.addPredefinedGlobalIdent("FreeBSD");
// FIXME: Need a way to statically and/or dynamically set the major FreeBSD version,
// to support FreeBSD 12.x and later releases both as a native and cross compiler.
VersionCondition.addPredefinedGlobalIdent("FreeBSD_11");
VersionCondition.addPredefinedGlobalIdent("FreeBSD_" ~ target.FreeBSDMajor);
VersionCondition.addPredefinedGlobalIdent("ELFv1");
VersionCondition.addPredefinedGlobalIdent("CppRuntime_Clang");
}
Expand Down
19 changes: 19 additions & 0 deletions src/dmd/target.d
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,25 @@ extern (C++) struct Target
|| params.isDragonFlyBSD
|| params.isSolaris;
}

/**
* Returns:
* FreeBSD major version string being targeted.
*/
extern (D) @property string FreeBSDMajor() scope const nothrow @nogc
in { assert(params.isFreeBSD); }
do
{
// FIXME: Need better a way to statically set the major FreeBSD version?
version (TARGET_FREEBSD12) return "12";
else version (TARGET_FREEBSD11) return "11";
else version (TARGET_FREEBSD10) return "10";
else version (FreeBSD_12) return "12";
else version (FreeBSD_11) return "11";
else version (FreeBSD_10) return "10";
// FIXME: Need a way to dynamically set the major FreeBSD version?
else /* default supported */ return "11";
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 9c8b709

Please sign in to comment.