Commit Graph

554 Commits (63383a8af8bf45b2de78967a2fe8773a5639d36b)

Author SHA1 Message Date
Andrew Kelley 5a4e8c779a
smarter detectNativeDynamicLinker logic
The current target's ABI cannot be relied on for this.
For example, we may build the zig compiler for target
riscv64-linux-musl and provide a tarball for users to
download. A user could then run that zig compiler on
riscv64-linux-gnu. This use case is well-defined and
supported by Zig. But that means that we must detect
the system ABI here rather than
relying on `std.Target.current`.
2020-02-17 19:26:32 -05:00
Andrew Kelley 8fe636dafd
fix ABI mismatch of ZigTarget in stage2 glue code 2020-02-17 16:49:30 -05:00
Andrew Kelley 4b91e4c91f fix dynamic linker detection on windows (where there isn't one) 2020-02-17 16:03:01 -05:00
Andrew Kelley e26f063b22 support the concept of a target not having a dynamic linker 2020-02-17 15:46:53 -05:00
Andrew Kelley 2f9c5c0644
self-host dynamic linker detection 2020-02-17 15:23:59 -05:00
Andrew Kelley c784c52819
fix backwards warning of `zig libc`
crt_dir is only not required for darwin
2020-02-17 01:15:43 -05:00
Andrew Kelley 44c14749a1
expand argv[0] when spawning system C compiler
Some C compilers, such as Clang, are known to rely on
argv[0] to find the path to their own executable,
without even bothering to resolve PATH. This results
in the message:

error: unable to execute command: Executable "" doesn't exist!

So we tell ChildProcess to expand argv[0] to the absolute path
to give them a helping hand.
2020-02-17 00:58:30 -05:00
Andrew Kelley 5c54d7bee7
add missing implementations of libc installation to detect msvc paths 2020-02-16 19:58:27 -05:00
Andrew Kelley 20f3b0efff rename libuserland to libstage2 2020-02-16 19:16:08 -05:00
Andrew Kelley 7eb0a3edce
remove libc dependency of zig0 building libstage2
Rather than `zig0 build ...` the build now does
`zig0 build-lib ...`, avoiding the requirement of linking the build
script, and thus avoiding the requirement of finding native libc,
for systems where libc is the system ABI.
2020-02-16 18:57:34 -05:00
Andrew Kelley 4b02a39aa9
self-hosted libc detection
* libc_installation.cpp is deleted.
   src-self-hosted/libc_installation.zig is now used for both stage1 and
   stage2 compilers.
 * (breaking) move `std.fs.File.access` to `std.fs.Dir.access`. The API
   now encourages use with an open directory handle.
 * Add `std.os.faccessat` and related functions.
 * Deprecate the "C" suffix naming convention for null-terminated
   parameters. "C" should be used when it is related to libc. However
   null-terminated parameters often have to do with the native system
   ABI rather than libc. "Z" suffix is the new convention. For example,
   `std.os.openC` is deprecated in favor of `std.os.openZ`.
 * Add `std.mem.dupeZ` for using an allocator to copy memory and add a
   null terminator.
 * Remove dead struct field `std.ChildProcess.llnode`.
 * Introduce `std.event.Batch`. This API allows expressing concurrency
   without forcing code to be async. It requires no Allocator and does
   not introduce any failure conditions. However it is not thread-safe.
 * There is now an ongoing experiment to transition away from
   `std.event.Group` in favor of `std.event.Batch`.
 * `std.os.execvpeC` calls `getenvZ` rather than `getenv`. This is
   slightly more efficient on most systems, and works around a
   limitation of `getenv` lack of integration with libc.
 * (breaking) `std.os.AccessError` gains `FileBusy`, `SymLinkLoop`, and
   `ReadOnlyFileSystem`. Previously these error codes were all reported
   as `PermissionDenied`.
 * Add `std.Target.isDragonFlyBSD`.
 * stage2: access to the windows_sdk functions is done with a manually
   maintained .zig binding file instead of `@cImport`.
 * Update src-self-hosted/libc_installation.zig with all the
   improvements that stage1 has seen to src/libc_installation.cpp until
   now. In addition, it now takes advantage of Batch so that evented I/O
   mode takes advantage of concurrency, but it still works in blocking
   I/O mode, which is how it is used in stage1.
2020-02-16 13:25:30 -05:00
Michael Dusan 8583038640
translate-c: change OutOfMemory → ASTUnitFailure
- return a better error when no diagnostics are available
2020-02-15 05:14:31 -05:00
Vexu 9206f8a8cd translate-c improve macro cast translation 2020-02-14 09:36:44 -05:00
Vexu ae5ba369e1 translate-c float fixes 2020-02-10 11:02:29 -05:00
Andrew Kelley 3fce8008cc
skip self-hosted for now as we work towards async I/O
1. behavior tests with --test-evented-io
 2. std lib tests with --test-evented-io
 3. fuzz test evented I/O a bit, make it robust
 4. make sure it works on all platforms (kqueue, Windows IOCP,
    epoll/other)
 5. restart efforts on self-hosted
2020-02-07 12:30:16 -05:00
Andrew Kelley 84323504ac
std.fmt.format: comptime output parameter 2020-02-05 16:52:18 -05:00
Andrew Kelley 40b1fecace
Merge pull request #4363 from Vexu/trans-std-c
Use std.c.tokenizer in translate-c
2020-02-05 14:29:39 -05:00
Vexu f196ddd251
translate c type names 2020-02-05 17:52:46 +02:00
Vexu 1f49460dcb
fix regressions in comments and string prefixes 2020-02-05 08:35:30 +02:00
Michaël Larouche 9b11e5e1f1 Add InstallRawStep to Zig build system that does a similar job to llvm-objcopy. To use it, do 'exe.installRaw("kernel.bin");' where exe is a LibExeObjStep
Part of #2826
2020-02-03 15:07:34 -05:00
Vexu 35c40f0a70
fix regressions 2020-02-02 10:49:51 +02:00
Vexu 3b23929be5
use std.c.tokenizer in translate-c 2020-02-02 01:40:46 +02:00
LemonBoy 3640c682a2 Run `zig fmt` 2020-02-01 11:32:53 +01:00
LemonBoy 176bc53858 translate-c: Fix translation of fn pointers
Closes #4332
2020-01-30 21:33:50 -05:00
LemonBoy c944865fc7 Generate compilable code for array inits
The compiler still doesn't like too much the newfangled anonymous arrays
so let's use the old-style declarations.

Closes #4181
2020-01-30 19:45:08 +01:00
Benjamin Feng b7a236d68e Convert a bunch of page_allocator to testing.allocator 2020-01-29 22:22:01 -06:00
LemonBoy 534014f84e translate-c: Handle fn protos wrapped in parenthesis
Closes #4289
2020-01-29 12:06:53 -05:00
Andrew Kelley 9dffc369f1
Merge remote-tracking branch 'origin/master' into layneson-cpus_and_features 2020-01-25 23:25:29 -05:00
Feix Weiglhofer a4a9330648 translate-c: Don't make const parameters mutable. (#4273)
* translate-c: Remove arg-prefix from const parameters.
* translate-c: Add unittest for const parameters.
2020-01-24 15:32:32 -05:00
LemonBoy a284be3f69 Fix unsafe cast in translate_c
Fixes #4250
2020-01-22 17:58:57 -05:00
Andrew Kelley 3227aec848
fix not respecting sub-arch feature 2020-01-22 17:35:57 -05:00
Andrew Kelley 48c7e6c48b
std.Target.CpuFeatures is now a struct with both CPU and feature set
Previously it was a tagged union which was one of:
 * baseline
 * a specific CPU
 * a set of features

Now, it's possible to have a CPU but also modify the CPU's feature set
on top of that. This is closer to what LLVM does.

This is more correct because Zig's notion of CPUs (and LLVM's) is not
exact CPU models. For example "skylake" is not one very specific model;
there are several different pieces of hardware that match "skylake" that
have different feature sets enabled.
2020-01-22 17:13:31 -05:00
Andrew Kelley cbe9a51518
don't trust llvm's GetHostCPUName
comment from this commit reproduced here:

I have observed the CPU name reported by LLVM being incorrect. On
the SourceHut build services, LLVM 9.0 reports the CPU as "athlon-xp",
which is a 32-bit CPU, even though the system is 64-bit and the reported
CPU features include, among other things, +64bit.
So the strategy taken here is that we observe both reported CPU, and the
reported CPU features. The features are trusted more; but if the features
match exactly the features of the reported CPU, then we trust the reported CPU.
2020-01-21 22:02:13 -05:00
Andrew Kelley 830e0ba2d2 enable native CPU feature for windows; disable failing tests
See #508. These can be re-enabled when we upgrade to LLVM 10.
2020-01-21 21:46:06 -05:00
Andrew Kelley 6e6ec3d71d put hack back in to disable windows native cpu features
See #508. This can be removed when we upgrade to LLVM 10.
2020-01-21 21:01:36 -05:00
Andrew Kelley 68b6867e76
lazily compute the full cpu features dependencies 2020-01-21 20:11:36 -05:00
Andrew Kelley 92559cd02c
hit a comptime limitation with computing dense sets 2020-01-21 19:40:44 -05:00
Andrew Kelley 91ecce3bc0
fix cache of cpu features 2020-01-21 12:14:43 -05:00
Andrew Kelley 1f7babbc80
properly forward baseline target cpu features to llvm 2020-01-21 03:01:20 -05:00
Andrew Kelley 0abaee79af
fix self-hosted compiler regression 2020-01-21 01:51:21 -05:00
Andrew Kelley 5974f95cb7
add cpus and cpu features to zig targets 2020-01-21 01:48:25 -05:00
Andrew Kelley 0c2dde2fda
add libc and glibcs to self-hosted zig targets 2020-01-21 01:31:27 -05:00
Andrew Kelley 39759b90fc
make zig targets show native cpu name and features 2020-01-21 01:22:37 -05:00
Andrew Kelley e640d01535
fixups to arch data, support any number of cpu features 2020-01-21 00:34:54 -05:00
Andrew Kelley f3dd9bbdac
improve `zig targets` 2020-01-20 13:40:25 -05:00
Andrew Kelley bf82929557
fix std.Target.Arch.parseCpuFeatureSet 2020-01-20 12:41:18 -05:00
Andrew Kelley 8f29d14073
stage1 is building. `zig targets` now self-hosted 2020-01-20 01:42:31 -05:00
Andrew Kelley 20af858601
some fixes 2020-01-19 21:06:41 -05:00
Andrew Kelley a313f15384
figure out zig0/stage1 and scanning for native CPU 2020-01-19 20:54:05 -05:00
Andrew Kelley a867b43366
progress towards merging
see BRANCH_TODO file
2020-01-19 20:54:04 -05:00