Commit Graph

893 Commits (3aab6012c471522e2d1cd5a456f56cb9a7addeb6)

Author SHA1 Message Date
Andrew Kelley 22e7ca5613 ir: analysis of fn instruction 2020-04-21 16:06:15 -04:00
Andrew Kelley 9a2ea5ca42 ir: comptime coerceArrayPtrToSlice 2020-04-21 13:50:04 -04:00
Andrew Kelley fb63ba2577 ir: type coercion skeleton 2020-04-21 13:24:25 -04:00
Andrew Kelley 8e0bcaca9b ir: analyze str instruction 2020-04-21 01:20:01 -04:00
Andrew Kelley 4c7507cceb ir: semantic analysis skeleton 2020-04-21 00:56:30 -04:00
Andrew Kelley cc1c2bd568 simplify ZIR spec; separate parsing/rendering from analysis 2020-04-20 19:21:03 -04:00
Andrew Kelley af4ccf34c1 ir: render keyword parameters 2020-04-19 23:59:00 -04:00
Andrew Kelley f7786d0ca8 ir: render function body 2020-04-19 23:39:34 -04:00
Andrew Kelley e74c5a7c24 ir: nice rendering of string literal constants 2020-04-19 20:44:18 -04:00
Andrew Kelley ded6e0326d ir: rendering skeleton 2020-04-19 20:04:11 -04:00
Andrew Kelley 1f3eeb5443 ir: parse type noreturn 2020-04-19 19:31:50 -04:00
Andrew Kelley 104ae419e4 ir: parse export instruction 2020-04-19 19:31:50 -04:00
Andrew Kelley f020999ca3 ir: parse asm instructions 2020-04-19 19:31:50 -04:00
Andrew Kelley 82e294cf09 ir: parse deref instruction 2020-04-19 19:31:50 -04:00
Andrew Kelley 730dd887e4 ir: parse string literals as parameters 2020-04-19 19:31:50 -04:00
Andrew Kelley bd37c8d8ed ir: parse ptrtoint 2020-04-19 19:31:50 -04:00
Andrew Kelley 49e2f3ca36 ir: more foolproof way to organize instruction parsing 2020-04-19 19:31:50 -04:00
Andrew Kelley 4cb203db92 ir: parsing integer literals 2020-04-19 19:31:50 -04:00
Andrew Kelley 7127c07f68 ir: parse types 2020-04-19 19:31:50 -04:00
Andrew Kelley 59154a1c51 ir: parse fn body 2020-04-19 19:31:50 -04:00
Andrew Kelley 018daa028e rework types and values data layout 2020-04-19 19:31:50 -04:00
Andrew Kelley f92ccf365b generic ir parsing framework 2020-04-19 19:31:50 -04:00
Andrew Kelley bd4280decf beginnings of zig ir parser 2020-04-19 19:31:50 -04:00
joachimschmidt557 3fd38429e4 Enable formatting in std.big.Int.format 2020-04-15 12:51:43 -04:00
Vexu ca3bf6e6ad
translate-c cleanup and zig fmt 2020-04-15 15:15:32 +03:00
Vexu a016fb8c62
translate-c: correct invalid shortcut 2020-04-15 15:14:10 +03:00
Lachlan Easton 0122f2cff6 Translate C: Redo Add comment containing c source location for failed decls. 2020-04-14 22:13:43 +10:00
xackus dbc00e2424 ArrayList: remove old (before span) API 2020-04-11 20:40:34 -04:00
Andrew Kelley 3c34c313cf revert Translate C: Add comment containing c source location for failed decls
This reverts 0db108101a.

Unfortunately this caused a regression. Closes #5007.
2020-04-11 17:56:48 -04:00
emekoi de08d283da fix compilation under mingw 2020-04-11 15:18:54 -05:00
Andrew Kelley a6e288d5fe
Merge pull request #4711 from leroycep/feature-file-locks
Add lock option to File.OpenFlags and File.CreateFlags
2020-04-10 15:00:45 -04:00
Auguste Rame df14578c9d
Merge branch 'master' into nameless-fields 2020-04-10 11:49:50 -04:00
Lachlan Easton d7902707bc
Translate C: Allow casting literal ints to pointers 2020-04-08 14:11:01 -04:00
Vexu 7b5fb79b5b
Translate C: Put an alignCast in c style pointer casts to allow opaque types to cast properly in C macros
Translate C: add test case for aligning opaque types in pointer casts
2020-04-08 14:11:01 -04:00
SuperAuguste 882aa86843 more fixes 2020-04-07 15:08:46 -04:00
Vexu adaf7ad672
Merge pull request #4684 from LakeByTheWoods/comment_failed_decls
Translate C: Add comment containing c source location for failed decls
2020-04-07 21:47:32 +03:00
SuperAuguste f21ac0220a msvc fix 2020-04-07 14:39:24 -04:00
SuperAuguste 9298d38cee remove debug statement 2020-04-07 13:33:01 -04:00
SuperAuguste 94841d0292 Nameless struct field consistency 2020-04-07 13:26:17 -04:00
LeRoyce Pearson 798207ec80 Merge branch 'master' into feature-file-locks 2020-04-06 21:51:57 -06:00
Andrew Kelley e4eb817f79
libc_installation.zig: don't special-case based on C ABI
Whether the C ABI is mingw-w64 or msvc, detection of native libc paths
should be the same. In the future we may want to allow passing a C ABI
parameter to detectNativeCPaths() but for now we have the same behavior
regardless.
2020-04-06 13:33:32 -04:00
Vexu c5ced0d74a
Merge pull request #4939 from SuperAuguste/master
translate-c: Properly translate C multicharacter literals
2020-04-06 10:31:17 +03:00
SuperAuguste 6106cf4419 fixes 2020-04-05 19:06:43 -04:00
Vexu 6ef15fc8d0
Merge pull request #4901 from phase/feature/translate-c-remassign
translate-c: RemAssign and DivAssign
2020-04-05 21:05:18 +03:00
Jadon Fowler ae376e0758 translate-c: remove unneeded semicolon
Signed-off-by: Jadon Fowler <j@jadon.io>
2020-04-05 10:44:42 -04:00
SuperAuguste 027e2a1673 fix multichar literals in translate_c 2020-04-04 17:56:25 -04:00
xackus cd20e0cc67 rename mem.separate to mem.split 2020-04-04 17:37:51 -04:00
Andrew Kelley e5d479b06e detect an endless loop when trying to detect native libc installation
closes #4810
2020-04-04 15:03:22 -04:00
Andrew Kelley 52db13738b
zig cc looks for native include directories unless -nostdinc
closes #4938
2020-04-04 14:58:24 -04:00
Jadon Fowler 391ee996a5 translate-c: account for signedness when translating div & mod
Signed-off-by: Jadon Fowler <j@jadon.io>
2020-04-04 02:16:30 -04:00
Andrew Kelley e89c42655c
Merge pull request #4868 from xackus/new-arraylist-api
new ArrayList API
2020-04-03 22:31:15 -04:00
LeRoyce Pearson 733f1c25bd Fix compile errors in stage2 2020-04-02 23:39:25 -06:00
LeRoyce Pearson f757f0ea59 Merge branch 'master' into feature-file-locks 2020-04-02 21:47:41 -06:00
LeRoyce Pearson 35c462caf0 Merge branch 'master' into feature-file-locks 2020-04-02 21:46:48 -06:00
Andrew Kelley f8cc6a1917
zig cc: fix ambiguity with -MT
In an MSVC context, `-MT` means
"Use static run-time"
and it is a flag with no parameter.

On POSIX it means
"Specify name of main file output in depfile"
and it is "joined or separate".

The former was interfering with the latter. Now, the MT flag is required
to be specified with a `/` to disambiguate: `/MT`.
2020-04-02 21:15:36 -04:00
Andrew Kelley c4b3c84b3f
zig cc: support -F and -framework 2020-04-02 15:59:48 -04:00
Andrew Kelley e4edc6d118
zig cc: respect -MF -MV -MD options
Zig disables its caching and forwards these args when any are provided.

see #4784
2020-04-02 15:47:27 -04:00
xackus 7a28c644aa new ArrayList API: fix everything else 2020-04-02 16:12:08 +02:00
Andrew Kelley 4848b28ec8
zig cc: detect -mcpu, -march, -mtune
However these are all treated like zig's -mcpu parameter.

See #4784
2020-04-01 18:06:04 -04:00
Rejean Loyer 2b6dfdd3d4 zig cc: add support for -L linker arguments 2020-04-01 17:21:11 -04:00
Andrew Kelley 783f73c7e3
zig cc properly handles -S flag and .ll, .bc extensions 2020-04-01 16:01:06 -04:00
Andrew Kelley c211b8f91d
fix regressions from previous commit 2020-04-01 15:02:31 -04:00
Jadon Fowler a255b0f842 translate-c: translate DivAssign & RemAssign
Closes #4790

Signed-off-by: Jadon Fowler <j@jadon.io>
2020-04-01 14:23:26 -04:00
Andrew Kelley 2e806682f4
(breaking) std.Buffer => std.ArrayListSentineled(u8, 0)
This new name (and the fact that it is a function returning a type) will
make it more clear which use cases are better suited for ArrayList and
which are better suited for ArrayListSentineled.

Also for consistency with ArrayList,
 * `append` => `appendSlice`
 * `appendByte` => `append`

Thanks daurnimator for pointing out the confusion of std.Buffer.
2020-04-01 13:30:07 -04:00
Andrew Kelley 553f0e0546
fixups and revert a few things 2020-04-01 11:56:39 -04:00
daurnimator 7eb938c909
Use length field as passed in stage2 libc_installation instead of relying on zero termination 2020-04-01 10:36:38 -04:00
daurnimator e535057364
std: use std.ArrayList(u8).OutStream instead of std.Buffer.OutStream 2020-04-01 10:36:38 -04:00
daurnimator 3fb030e78a
std: use std.ArrayList(u8) instead of std.Buffer in src-self-hosted/translate_c.zig 2020-04-01 10:36:38 -04:00
daurnimator 3cf302a71d
Tidy up some mem.spanZ use-sites now that null is accepted 2020-04-01 01:50:34 +11:00
Andrew Kelley 839d85e440 fixes to 32-bit handling, to support 32-bit arm 2020-03-31 10:10:31 -04:00
Andrew Kelley cfedd3aca2
revert detection of rtti and exceptions
This caused link errors in c++ code because it was not correct to pass
these flags to child codegens. And that was the only reason to detect
these flags. Otherwise we can safely rely on non-explicitly-detected
flag forwarding.
2020-03-30 17:42:30 -04:00
Andrew Kelley 9e7ae06249
std lib API deprecations for the upcoming 0.6.0 release
See #3811
2020-03-30 14:23:22 -04:00
Layne Gustafson 2a05ca1c94 Conv macro string concat to ++ 2020-03-28 20:40:13 -04:00
LeRoyce Pearson 457f557c37
Merge branch 'master' into feature-file-locks 2020-03-28 17:24:19 -06:00
Ryan Liptak cc7c670851 Sync clang_options_data.zig with update_clang_options
Some of the recent c++ related options were added to update_clang_options but didn't make it into clang_options_data.zig
2020-03-28 00:39:33 -07:00
Ryan Liptak 874b4618ca zig cc: Add support for -z
This is only the first step; it makes zig cc recognize -z and append it to the linker args, but the linker arg parsing doesn't support -z yet so it will just give the warning 'unsupported linker arg: -z'
2020-03-28 00:35:54 -07:00
Ryan Liptak b0b29b8a2f zig cc: Add support for -Xlinker, --for-linker, --for-linker= 2020-03-27 23:32:01 -07:00
Andrew Kelley 107b5196f6
Merge pull request #4827 from ziglang/zig-cpp
support compiling and linking c++ code
2020-03-27 22:35:13 -04:00
Andrew Kelley a258741084
initial support of response files
See #4833

It doesn't support comments or quotes yet.
2020-03-27 22:24:40 -04:00
Michael Dusan 33819ecfbc windows: don't hard-code forward-slash paths
`zig targets` -> unable to list targets: BadPathName
2020-03-27 21:28:52 -04:00
LeRoyce Pearson c7f4e68464
Merge branch 'master' into feature-file-locks 2020-03-27 11:32:33 -06:00
Andrew Kelley f407109070
zig c++: get it working with musl and mingw-w64 2020-03-27 12:38:52 -04:00
Andrew Kelley db17c0d88c
ability to compile c++ hello world with `zig c++`
closes #4786
2020-03-26 22:48:37 -04:00
Andrew Kelley fae6cf0961
improved handling of native system directories
* `-isystem` instead of `-I` for system include directories
   fixes a problem with native system directories interfering with zig's
   bundled libc.
 * separate Stage2Target.is_native into Stage2Target.is_native_os and
   Stage2Target.is_native_cpu.
2020-03-25 20:34:15 -04:00
Michael Dusan dd66fbb96a
Merge pull request #4811 from mikdusan/fix4634
self-hosted: use fs.selfExePathAlloc
2020-03-25 19:49:52 -04:00
Andrew Kelley e3fec6cce9
zig cc: add detection for `-###`
it turns on --verbose-cc and --verbose-link
2020-03-25 19:32:12 -04:00
Michael Dusan d554070de1
self-hosted: use fs.selfExePathAlloc
- add fs.selfExePathAlloc
- use fs.selfExePathAlloc instead of fs.selfExeDirPathAlloc
- remove redundant code from fs.selfExeDirPath

closes #4634
2020-03-25 18:40:28 -04:00
Andrew Kelley 6cbe589b51
zig cc: support -T linker script option 2020-03-25 12:05:48 -04:00
Andrew Kelley 93c7fa105f
Merge remote-tracking branch 'origin/llvm10'
LLVM 10 was released today
2020-03-24 09:57:09 -04:00
LeRoyce Pearson 113b217593 Merge branch 'master' into feature-file-locks 2020-03-23 21:39:16 -06:00
Andrew Kelley 13d04f9963
Merge pull request #4741 from momumi/master
allow `_` separators in number literals (stage 1)
2020-03-23 00:54:54 -04:00
Andrew Kelley 94f7c56001
riscv: add -mrelax arg for C to work around upstream issue
See #4485
2020-03-22 21:47:19 -04:00
Andrew Kelley e5e5196d8e
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-22 20:48:21 -04:00
momumi 2d18178c27 minor fixes and more tests for _ separators
* Make the tokenizer spit out an Invalid token on the first invalid
  character found in the number literal.
* More parsing and tokenizer tests for number literals
* fix invalid switch statement in ir.zig
2020-03-23 09:21:34 +10:00
Andrew Kelley 23c263776c
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-22 15:09:29 -04:00
momumi 8de45e5143 update parsing of int literals in self-hosted
* update std.math.big.Int.setString() to ignore underscores and make it
  case insensitive
* fix issue in ir.zig with leading zeroes in integer literals
2020-03-22 13:59:14 +10:00
Andrew Kelley 2b65dc1032
zig cc: detect optimization and debug flags 2020-03-21 22:30:46 -04:00
Andrew Kelley 4b0ddb817b
zig cc: better support for the preprocessor option (-E) 2020-03-21 20:32:48 -04:00
Michael Dusan 28ad78cb7f
rename "passthrough" → "driver_punt"
- punt when `-E` is supplied
- punt when `-S` is supplied
2020-03-21 16:53:59 -04:00
Andrew Kelley 0eee98edc1
zig cc improvements
* The generated options data file is sorted now in a way that
   makes sure longer prefixes are first. This prevents collisions
   with some parameters.
 * Add support for `-fPIC`, `-fno-PIC`, `-nostdlib`, `-shared`,
   `-rdynamic`, `-Wl,-soname`, `-Wl,-rpath`
 * Better support for `-o`.
 * Disable generating h files
 * Shared library support.
 * Better positional argument support.
2020-03-21 15:40:49 -04:00
Andrew Kelley a4eaeee720
ability to use `zig cc` as a drop-in C compiler
The basics are working
2020-03-21 15:39:39 -04:00
Andrew Kelley 7438d0fc31
glibc: include ld symbols and proper soname for ld 2020-03-20 14:39:05 -04:00
Andrew Kelley 53b5aa812b
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-19 22:19:24 -04:00
Andrew Kelley 8ea0a00f40
improve std lib code for the new semantics 2020-03-19 09:53:54 -04:00
Andrew Kelley 0707be8de8
fixes in semantic analysis needed to support this feature 2020-03-19 09:53:54 -04:00
Andrew Kelley 46ffc798b6
fix swapped logic for Windows
Remove `std.fs.deleteTree`. Callers instead should use
`std.fs.cwd().deleteTree`.

Add `std.fs.deleteTreeAbsolute` for when the caller has an absolute
path.
2020-03-18 16:42:47 -04:00
Andrew Kelley 27affde592
(breaking) clarify openDir API
* remove deprecated `std.fs.Dir` APIs
 * `std.fs.Dir.openDir` now takes a options struct with bool fields for
   `access_sub_paths` and `iterate`. It's now much more clear how
   opening directories works.
 * fixed the std lib and various zig code calling the wrong openDir
   function.
 * the runtime safety check for dir flags is removed in favor of the
   cheaper option of putting a comment on the same line as handling
   EBADF / ACCESS_DENIED, since that will show up in stack traces.
2020-03-18 16:10:57 -04:00
Andrew Kelley dbde5df568
clean up some self-hosted bitrot + don't assume libstdc++
closes #4682

The self-hosted compiler is still bit rotted and still not compiling
successfully yet. I have a more serious rework of the code in a
different branch.
2020-03-17 23:03:45 -04:00
Andrew Kelley 656ba530d8
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-13 15:17:53 -04:00
Andrew Kelley 4905102901
fix all the TODOs from the pull request
* `std.Buffer.print` is removed; use `buffer.outStream().print`
 * `std.fmt.count` returns a `u64`
 * `std.Fifo.print` is removed; use `fifo.outStream().print`
 * `std.fmt.bufPrint` error is renamed from `BufferTooSmall`
   to `NoSpaceLeft` to match `std.os.write`.
 * `std.io.FixedBufferStream.getWritten` returns mutable buffer
   if the buffer is mutable.
2020-03-13 12:02:58 -04:00
Andrew Kelley 2dd920ee39
Merge branch 'format-stream' of https://github.com/fengb/zig into fengb-format-stream 2020-03-13 11:31:11 -04:00
Andrew Kelley aa49f972d6
Merge pull request #4720 from Vexu/translate-c
Translate-c treat C bools as ints
2020-03-12 14:00:07 -04:00
daurnimator 8a22c50c08 Remove unused static_crt_dir field from libc config 2020-03-12 12:27:45 -04:00
Benjamin Feng 4aae55b4cc Replace fmt with new fmtstream 2020-03-12 10:41:09 -05:00
Benjamin Feng ed7f30e1cd Migrate last vestiges of fmt 2020-03-12 10:41:09 -05:00
Benjamin Feng 0059d9ee3e Convert fmt.bufPrint / fmt.allocPrint 2020-03-12 10:41:09 -05:00
Benjamin Feng 4023ed56d4 Convert translate-c to fmtstream 2020-03-12 10:41:09 -05:00
Vexu 02c491e42a
translate-c fix order of tokens 2020-03-12 17:14:01 +02:00
Vexu dda711ba0d
translate-c treat c bools as ints 2020-03-12 14:40:47 +02:00
Andrew Kelley f58705b4a6
fix `zig targets` not reporting native info 2020-03-12 00:33:06 -04:00
Michael Dusan bfebc11d06
fix zig-cache to treat cpu-features as raw-bytes
- add Stage2Target.cache_hash_len
- add cache_mem(ch, ptr, len)
- update call sites to use { ptr, len }
2020-03-11 19:33:12 -04:00
Michael Dusan e0fe0f7f1e
parse CPU features when --target is null
- fixes case where features are not parsed when `-target` is null
- `zig builtin -mcpu native+bogus` should return error/list of valid features
2020-03-11 19:33:10 -04:00
Andrew Kelley d882a30587
fix stage2 lib on windows 2020-03-10 20:51:30 -04:00
Andrew Kelley b6fbd524f1
(breaking) improve and simplify fixed buffer streams API 2020-03-10 16:31:04 -04:00
Andrew Kelley ba0e3be5cf
(breaking) rework stream abstractions
The main goal here is to make the function pointers comptime, so that we
don't have to do the crazy stuff with async function frames.

Since InStream, OutStream, and SeekableStream are already generic
across error sets, it's not really worse to make them generic across the
vtable as well.

See #764 for the open issue acknowledging that using generics for these
abstractions is a design flaw.

See #130 for the efforts to make these abstractions non-generic.

This commit also changes the OutStream API so that `write` returns
number of bytes written, and `writeAll` is the one that loops until the
whole buffer is written.
2020-03-10 15:32:32 -04:00
Vexu cb4c488cbd
translate-c support struct field alignment 2020-03-10 15:57:57 +02:00
Vexu 4cace8f7c3
properly mangle shadowed primitive types 2020-03-10 15:52:54 +02:00
Vexu baec74645d
translate-c add daurnimator's pointer check to macro cast 2020-03-10 15:52:03 +02:00
Lachlan Easton 0db108101a Translate C: Add comment containing c source location for failed decls 2020-03-09 18:10:41 +11:00
Vexu 692a974c3e
translate-c reject structs with VLAs 2020-03-08 12:11:37 +02:00
Vexu 5aa993cd61
translate-c fix nested loops without blocks. 2020-03-08 11:26:53 +02:00
Andrew Kelley 9e60c89601
Revert "Translate C: Group generated casts"
This reverts commit 895672b3f9.
2020-03-08 03:53:06 -04:00
Andrew Kelley 8b80cb3072
Revert "translate-c remove redundant grouping, fix nested loops without blocks."
This reverts commit abe7305e16.
2020-03-08 03:52:52 -04:00
Andrew Kelley 96c07674fc
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-07 12:18:41 -05:00
Vexu abe7305e16 translate-c remove redundant grouping, fix nested loops without blocks. 2020-03-07 12:14:44 -05:00
Lachlan Easton 895672b3f9 Translate C: Group generated casts
Translate C: Put an alignCast in c style pointer casts to allow opaque types to cast properly in C macros

Translate C: add test case for aligning opaque types in pointer casts

Translate C: Fix @typeId -> @typeInfo

Add test case to run_translated_c for casting from pointer to opaque type
2020-03-07 03:26:42 -05:00
Andrew Kelley 49817c6add
cleanup CPU model & feature detection
Add std.Target.Cpu.Model.generic which is even more empty than baseline.
CPU model and feature detection uses this rather than baseline.

Rename cpu_detected to cpu_detection_unimplemented and flip the logic.
It can be relied on by stage2.zig to decide whether the LLVM workaround
is needed without also checking the CrossTarget.

Move the CPU detection to after the OS detection, and use the detected
OS for the CPU detection. This is relevant because operating systems
sometimes emulate certain CPU features, so knowing the OS and version is
relevant for determining CPU features.

Prepare for #4592 by passing the CPU arch to the detection code, instead
of having it rely on Target.current.

The CPU model & feature detection logic is modified. Before:

 * Detect actual features
 * Use as hint when detecting CPU model
 * Populate dependencies of CPU model features
 * Merge that into the actual features set

After:

 * Detect actual features
 * Use as hint when detecting CPU model
 * Add known CPU model features to actual features
 * Detect actual features again, overriding known CPU model features
 * Populate dependencies
2020-03-06 19:47:03 -05:00
alichay f199182567
Cleaned up CPU detection and fixed incorrect detection bits. 2020-03-06 18:52:09 -05:00
alichay e24f29bbad
Added self-hosted x86 CPU detection. 2020-03-06 18:52:09 -05:00
daurnimator 1cbf352cfb
Remove unused std.Buffer imports 2020-03-06 18:49:13 -05:00
Vexu 83d27f71ef translate-c more macro ops 2020-03-06 17:34:37 -05:00
Vexu eaccfffe56 translate-c: default initialize non-extern variables to undefined 2020-03-06 00:06:45 -05:00
Vexu ad27041de9 translate-c demote struct to opaque if unable to translate type 2020-03-05 10:55:32 -05:00
Vexu e063854563
translate-c correct assumption about macros 2020-03-05 12:23:32 +02:00
Vexu 8088bdc6d5
translate-c macro comma operator 2020-03-05 11:22:50 +02:00
Andrew Kelley 3178807657
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-04 15:35:46 -05:00
Andrew Kelley 447a89cd4d
update self-hosted `zig targets` to print correct glibc availability 2020-03-04 01:05:42 -05:00
daurnimator 1ca5f06762
Update callers of fs.makePath 2020-03-03 13:25:43 -05:00
Andrew Kelley d1cb16aace
Merge remote-tracking branch 'origin/master' into llvm10 2020-03-03 09:44:13 -05:00
Andrew Kelley ef3d761da5
breaking: std.mem.len no longer takes a type argument
also update fmt code to use std.mem.span.
2020-03-01 13:21:39 -05:00
daurnimator 0b0de22fd1
std: format contents of sentinel terminated many pointers
std: add std.meta.Sentinel to get sentinel of a type
2020-03-01 13:04:29 -05:00
Andrew Kelley 4591236ae1
CrossTarget.cpu_model: communicate intent precisely 2020-02-28 18:31:46 -05:00
Andrew Kelley aa13f339d4
fix handling of CrossTarget.cpu_model 2020-02-28 18:09:33 -05:00
Andrew Kelley 8691d3c50d
improve std.zig.system.NativeTargetInfo.detect
It now takes a std.zig.CrossTarget parameter, and only resolves
native things, leaving explicitly overridden things alone.
2020-02-28 17:23:16 -05:00
Andrew Kelley 500dde32d5
dynamic_linker becomes a field of std.zig.CrossTarget 2020-02-28 14:51:56 -05:00
Andrew Kelley ef24f2dd93
remove special darwin os version min handling
now it is integrated with zig's target OS range.
2020-02-28 14:51:56 -05:00
Andrew Kelley fd006c1c74
std.zig.system.NativeTargetInfo.detect: almost no Allocator 2020-02-28 14:51:55 -05:00
Andrew Kelley 60f2f3457d
getStandardDynamicLinkerPath renamed and no allocator
* `std.Target.getStandardDynamicLinkerPath` =>
   `std.Target.standardDynamicLinkerPath`
 * it now takes a pointer to fixed size array rather than an allocator
 * `std.zig.system.NativeTargetInfo.detect` now supports reading
   PT_INTERP from /usr/bin/env
2020-02-28 14:51:55 -05:00
Andrew Kelley f89a1844bf
don't error out for targets with unknown standard dynamic linker path 2020-02-28 14:51:55 -05:00
Andrew Kelley 2387f48d5c
fix incorrect builtin import code for windows 2020-02-28 14:51:54 -05:00
Andrew Kelley 622b5b62c2
fix not setting the dynamic linker path when cross compiling 2020-02-28 14:51:54 -05:00
Andrew Kelley 0912484c4f
improve the "external executor" detection logic 2020-02-28 14:51:54 -05:00
Andrew Kelley cf233bad58
fix target parsing 2020-02-28 14:51:54 -05:00
Andrew Kelley dbe4d72bcf
separate std.Target and std.zig.CrossTarget
Zig now supports a more fine-grained sense of what is native and what is
not. Some examples:

This is now allowed:
-target native

Different OS but native CPU, default Windows C ABI:
-target native-windows
This could be useful for example when running in Wine.

Different CPU but native OS, native C ABI.
-target x86_64-native -mcpu=skylake

Different C ABI but otherwise native target:
-target native-native-musl
-target native-native-gnu

Lots of breaking changes to related std lib APIs.
Calls to getOs() will need to be changed to getOsTag().
Calls to getArch() will need to be changed to getCpuArch().

Usage of Target.Cross and Target.Native need to be updated to use
CrossTarget API.

`std.build.Builder.standardTargetOptions` is changed to accept its
parameters as a struct with default values. It now has the ability to
specify a whitelist of targets allowed, as well as the default target.
Rather than two different ways of collecting the target, it's now always
a string that is validated, and prints helpful diagnostics for invalid
targets. This feature should now be actually useful, and contributions
welcome to further improve the user experience.

`std.build.LibExeObjStep.setTheTarget` is removed.
`std.build.LibExeObjStep.setTarget` is updated to take a CrossTarget
parameter.

`std.build.LibExeObjStep.setTargetGLibC` is removed. glibc versions are
handled in the CrossTarget API and can be specified with the `-target`
triple.

`std.builtin.Version` gains a `format` method.
2020-02-28 14:51:54 -05:00
Andrew Kelley 87b9e744dd
update std lib to new Target API 2020-02-28 14:51:54 -05:00
Andrew Kelley 4616af0ca4
introduce operating system version ranges as part of the target
* re-introduce `std.build.Target` which is distinct from `std.Target`.
   `std.build.Target` wraps `std.Target` so that it can be annotated as
   "the native target" or an explicitly specified target.
 * `std.Target.Os` is moved to `std.Target.Os.Tag`. The former is now a
   struct which has the tag as well as version range information.
 * `std.elf` gains some more ELF header constants.
 * `std.Target.parse` gains the ability to parse operating system
   version ranges as well as glibc version.
 * Added `std.Target.isGnuLibC()`.
 * self-hosted dynamic linker detection and glibc version detection.
   This also adds the improved logic using `/usr/bin/env` rather than
   invoking the system C compiler to find the dynamic linker when zig
   is statically linked. Related: #2084
   Note: this `/usr/bin/env` code is work-in-progress.
 * `-target-glibc` CLI option is removed in favor of the new `-target`
   syntax. Example: `-target x86_64-linux-gnu.2.27`

closes #1907
2020-02-28 14:51:53 -05:00
Vexu 22432b15e3
add test for `@intToEnum` 2020-02-26 11:19:40 -05:00
Andrew Kelley f33bf48af7
Merge remote-tracking branch 'origin/master' into llvm10 2020-02-25 16:30:40 -05:00
Vexu 538d9a5dd8
remove uses of `@ArgType` and `@IntType` 2020-02-24 23:39:03 +02:00
Vexu 45da72c5b6
remove usages of `@typeId`, `@memberCount`, `@memberName` and `@memberType` 2020-02-24 23:09:01 +02:00
Andrew Kelley 0cd89e9176
std.os.execvpeZ_expandArg0: fix not restoring argv[0]
This function expands argv[0] into the absolute path resolved with PATH
environment variable before making the execve syscall. However, in case
the execve fails, e.g. with ENOENT, it did not restore argv to how it
was before it was passed in. This resulted in the caller performing an
invalid free.

This commit also adds verbose debug info when native system C compiler
detection fails. See #4521.
2020-02-22 13:56:02 -05:00
Andrew Kelley 71573584cd
std.Target.parse gives parsing diagnostics 2020-02-21 13:34:55 -05:00
Andrew Kelley 61c67a9833
remove sub-arch from stage1 2020-02-21 11:47:34 -05:00
Andrew Kelley 7b8b4d200c
fix not initializing some ZigTarget fields 2020-02-21 01:54:00 -05:00
Andrew Kelley 2de7d0b10c
fix zig build, ABI ABI, and update tests to new Target layout 2020-02-20 18:50:20 -05:00
Andrew Kelley 0f016b368d
support -mcpu=baseline, both in stage1 and stage2
See e381a42de9 for more details.
This is set up so that if we wish to make "baseline" depend on the
OS in the future, it is possible to do that.
2020-02-20 18:31:17 -05:00
Andrew Kelley 84f1893c18
remove the concept of "sub-architecture"
in favor of CPU features. Also rearrange the `std.Target`
data structure.

 * note: `@import("builtin")` was already deprecated in favor of
   `@import("std").builtin`.
 * `std.builtin.arch` is now deprecated in favor of
   `std.builtin.cpu.arch`.
 * `std.Target.CpuFeatures.Cpu` is now `std.Target.Cpu.Model`.
 * `std.Target.CpuFeatures` is now `std.Target.Cpu`.
 * `std.Target` no longer has an `arch` field. Instead it has a
   `cpu` field, which has `arch`, `model`, and `features`.
 * `std.Target` no longer has a `cpu_features` field.
 * `std.Target.Arch` is moved to `std.Target.Cpu.Arch` and
   it is an enum instead of a tagged union.
 * `std.Target.parseOs` is moved to `std.Target.Os.parse`.
 * `std.Target.parseAbi` is moved to `std.Target.Abi.parse`.
 * `std.Target.parseArchSub` is only for arch now and moved
    to `std.Target.Cpu.Arch.parse`.
 * `std.Target.parse` is improved to accept CPU name and features.
 * `std.Target.Arch.getBaselineCpuFeatures` is moved to
   `std.Target.Cpu.baseline`.
 * `std.Target.allCpus` is renamed to `std.Target.allCpuModels`.
 * `std.Target.defaultAbi` is moved to `std.Target.Abi.default`.
 * Significant cleanup of aarch64 and arm CPU features, resulting in
   the needed bit count for cpu feature set going from 174 to 138.
 * Add `std.Target.Cpu.Feature.Set.addFeatureSet` for merging
   feature sets together.

`-target-feature` and `-target-cpu` are removed in favor of
`-mcpu`, to conform to established conventions, and it gains
additional power to support cpu features. The syntax is:
-mcpu=name+on1+on2-off1-off2

closes #4261
2020-02-19 21:30:36 -05:00
Andrew Kelley c664692bdd
make the CLI support depending on system headers and libraries
(include and lib search paths)

The detection of native system paths is self-hosted.

closes #2041
2020-02-19 01:24:34 -05:00
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
Andrew Kelley a8b36fbe34
Merge remote-tracking branch 'origin/master' into llvm10 2020-02-14 10:27:44 -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 cdc5070f21
Merge remote-tracking branch 'origin/master' into llvm10 2020-02-10 00:26:33 -05:00
Andrew Kelley 9e5b248991
remove workarounds for Windows native CPU features
bug fixed in LLVM 10

closes #508
2020-02-07 12:41:46 -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